[Help request] I want to create a snap for R (the statistical software)

I made that change but that did not solve the problem. Thanks for the help and the patience!

indeed, the prefix change will only fix a future runtime issue you will run into :wink:

the linker error in the build log seems to be caused by a missing build-package entry … looking at the r-base build dependencies of the .deb package there seem to be a bunch more packages you might want to add

$ apt-cache showsrc r-base|grep Build-Depends
Build-Depends: gcc (>= 4:4.1.0), g++ (>= 4:4.1.0), gfortran (>= 4:4.1.0), libblas-dev, liblapack-dev (>= 3.1.1), tcl8.6-dev, tk8.6-dev, bison, groff-base, libncurses5-dev, libreadline-dev, debhelper (>= 7.2.3), texinfo (>= 4.1-2), libbz2-dev, liblzma-dev, libpcre3-dev, libcurl4-openssl-dev | libcurl4-dev, xdg-utils, zlib1g-dev, libpng-dev, libjpeg-dev, libx11-dev, libxt-dev, x11proto-core-dev, libpango1.0-dev, libcairo2-dev, libtiff5-dev, xvfb, xauth, xfonts-base, texlive-base, texlive-latex-base, texlive-generic-recommended, texlive-fonts-recommended, texlive-fonts-extra, texlive-extra-utils, texlive-latex-recommended, texlive-latex-extra, default-jdk [!arm !hppa !kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], mpack, bash-completion, gcc-4.9 [mips]

I modified my yaml to include all the dependencies listed:

name: rstats 
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: R is a language and environment for statistical computing and graphics
description: |
  R is ‘GNU S’, a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. Please consult the R project homepage for further information.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

apps:
  R:
    command: R
    plugs:
      - network
      - network-bind
      - home

parts:
  r:
    # See 'snapcraft plugins'
    plugin: autotools
    source: https://cran.rstudio.com/src/base/R-3/R-3.5.2.tar.gz
    override-build: |
       ./configure --enable-R-shlib --with-blas --with-lapack
       make
       make install
       R -e "install.packages('tidyverse', repos = 'http://cran.us.r-project.org')"
    build-packages:
      - gcc 
      - g++ 
      - gfortran
      - libblas-dev
      - liblapack-dev 
      - tcl-dev
      - tk-dev
      - bison
      - groff-base
      - libncurses5-dev
      - libreadline-dev
      - debhelper 
      - texinfo
      - libbz2-dev
      - liblzma-dev
      - libpcre3-dev
      - libcurl4-openssl-dev 
      - xdg-utils
      - zlib1g-dev
      - libpng-dev
      - libjpeg-dev
      - libx11-dev
      - libxt-dev
      - x11proto-core-dev
      - libpango1.0-dev
      - libcairo2-dev
      - libtiff5-dev
      - xvfb
      - xauth
      - xfonts-base
      - texlive-base
      - texlive-latex-base
      - texlive-generic-recommended
      - texlive-fonts-recommended
      - texlive-fonts-extra
      - texlive-extra-utils
      - texlive-latex-recommended
      - texlive-latex-extra
      - default-jdk 
      - mpack
      - bash-completion

Alas, the error did not go away. Any other ideas or suggestions?

there seems to be a mailing list thread at:

https://stat.ethz.ch/pipermail/r-sig-debian/2018-June/002890.html

particulary:

https://stat.ethz.ch/pipermail/r-sig-debian/2018-June/002892.html

perhaps that helps ?

I saw that thread. I think they are saying just install the .deb instead of trying to compile. Which is a good solution unless you are trying to learn how to do this stuff. Why I don’t get is why was I able to compile it in a clean install of Ubuntu server (inside a VM) but not with the snap.

well, the particular mail i linked to talks about libicu versions being out of sync … 16.04 only has libicu55, the code seems to expect a higher version … 18.04 has icu60 so you might need to build a base: core18 snap instead …

1 Like

Thanks! This helped me understand the problem and make some progress :-). Changing the base to base: core18 did not solve the problem. However, I thought that for now, I could use a much older version of R just to see if I could get things running with that. This time things went much further. Alas, I got a whole new error that I think has to do with my yaml instead of R dependencies

This is the new yaml:

name: rstats 
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: R is a language and environment for statistical computing and graphics
description: |
  R is ‘GNU S’, a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. Please consult the R project homepage for further information.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
base: core18

apps:
  R:
    command: R
    plugs:
      - network
      - network-bind
      - home

parts:
  r:
    # See 'snapcraft plugins'
    plugin: autotools
    source: https://cran.rstudio.com/src/base/R-3/R-3.1.3.tar.gz
    override-build: |
       ./configure --enable-R-shlib --with-blas --with-lapack --with-cairo
       make
       make install
       R -e "install.packages('tidyverse', repos = 'http://cran.us.r-project.org')"
    build-packages:
      - gcc 
      - g++ 
      - gfortran
      - libblas-dev
      - liblapack-dev 
      - tcl-dev
      - tk-dev
      - bison
      - groff-base
      - libncurses5-dev
      - libreadline-dev
      - debhelper 
      - texinfo
      - libbz2-dev
      - liblzma-dev
      - libpcre3-dev
      - libcurl4-openssl-dev 
      - xdg-utils
      - zlib1g-dev
      - libpng-dev
      - libjpeg-dev
      - libx11-dev
      - libxt-dev
      - x11proto-core-dev
      - libpango1.0-dev
      - libcairo2-dev
      - libtiff5-dev
      - xvfb
      - xauth
      - xfonts-base
      - texlive-base
      - texlive-latex-base
      - texlive-generic-recommended
      - texlive-fonts-recommended
      - texlive-fonts-extra
      - texlive-extra-utils
      - texlive-latex-recommended
      - texlive-latex-extra
      - default-jdk 
      - mpack
      - bash-completion
      - libicu-dev

I think the error is telling me that my snap is trying to write to ‘/usr/local/lib/R’: and it cannot do that because snaps are not supposed to do that. Am I right? If so, what should I do different in my snap?

Please offload the actual building commands(configure, make install) to snapcraftctl build, the autotools plugin pretty much does all the necessary changes for you (like setting DESTDIR make variable so the files will properly installed to the SNAPCRAFT_PART_INSTALL directory).

Check out the output of snapcraft help autotools for supported keys for the build customizations.

Thanks @Lin-Buo-Ren. I’m very very new to all this. Could you show me how to modify my yaml to do what you suggest? I think what you are suggesting is to remove the following:

override-build: |
       ./configure --enable-R-shlib --with-blas --with-lapack --with-cairo
       make
       make install

However, i don’t get how would I pass the options --enable-R-shlib --with-blas --with-lapack --with-cairo and how I would run the last line that is using the R to install some packages that I want to have in my snap. Thanks again!

snapcraft help autotools

    - configflags:
      (list of strings)
      configure flags to pass to the build such as those shown by running
      './configure --help'

So remove the entire override-build and just put all the configure flags inside a set of configflags. e.g. https://github.com/snapcrafters/corebird/blob/1fb119a98b6f6741503d9ac50de5737b416634cb/snap/snapcraft.yaml#L131

1 Like

Thanks @popey ! I made some more progress :slight_smile:

name: rstats 
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: R is a language and environment for statistical computing and graphics
description: |
  R is ‘GNU S’, a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. Please consult the R project homepage for further information.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
base: core18

apps:
  R:
    command: R
    plugs:
      - network
      - network-bind
      - home

parts:
  r:
    # See 'snapcraft plugins'
    plugin: autotools
    source: https://cran.rstudio.com/src/base/R-3/R-3.1.3.tar.gz
    configflags:
      - --enable-R-shlib
      - --with-blas
      - --with-lapack
      - --with-cairo
    build-packages:
      - gcc 
      - g++ 
      - gfortran
      - libblas-dev
      - liblapack-dev 
      - tcl-dev
      - tk-dev
      - bison
      - groff-base
      - libncurses5-dev
      - libreadline-dev
      - debhelper 
      - texinfo
      - libbz2-dev
      - liblzma-dev
      - libpcre3-dev
      - libcurl4-openssl-dev 
      - xdg-utils
      - zlib1g-dev
      - libpng-dev
      - libjpeg-dev
      - libx11-dev
      - libxt-dev
      - x11proto-core-dev
      - libpango1.0-dev
      - libcairo2-dev
      - libtiff5-dev
      - xvfb
      - xauth
      - xfonts-base
      - texlive-base
      - texlive-latex-base
      - texlive-generic-recommended
      - texlive-fonts-recommended
      - texlive-fonts-extra
      - texlive-extra-utils
      - texlive-latex-recommended
      - texlive-latex-extra
      - default-jdk 
      - mpack
      - bash-completion
      - libicu-dev
Snapping 'rstats' -                                                                   
Snapped rstats_0.1_amd64.snap

Alas, when I tried to run the program it did not work

ignacio@ignacio-XPS-8930:~/Documents/snaps/R$ rstats.R 
/snap/rstats/x1/bin/R: line 236: /lib/R/etc/ldpaths: No such file or directory
ERROR: R_HOME ('/lib/R') not found

Additionally when I tried the following to my yaml i was not able to get it to compile:

    override-build: |
           R -e "install.packages('tidyverse', repos = 'http://cran.us.r-project.org')"
ignacio@ignacio-XPS-8930:~/Documents/snaps/R$ snapcraft
Pulling r 
Downloading 'R-3.1.3.tar.gz'[==================================================================] 100%
Building r 
/bin/sh: 27: R: not found
Failed to run 'override-build': Exit code was 127.

It’s failing because you’re launching /snap/rstats/x1/bin/R which is a shell script. Let’s look at the first few lines…

#!/bin/bash
# Shell wrapper for R executable.

R_HOME_DIR=/lib/R
if test "${R_HOME_DIR}" = "/lib/R"; then
   case "linux-gnu" in
   linux*)
     run_arch=`uname -m`
     case "$run_arch" in 

That R_HOME_DIR is the problem. You may either want to bypass this script, setting up environment variables in the apps section that would otherwise be set by that script and then launching R as per the script, or you could patch that script and set R_HOME_DIR to something else, perhaps $SNAP/lib/R.

Could you show me how to do this? What should the environment variables be set to? I tried this:

apps:
  R:
    command: R
    environment:
      R_HOME_DIR: $SNAP/lib/R
    plugs:
      - network
      - network-bind
      - home

Alas, it did not work:

ignacio@ignacio-XPS-8930:~/Documents/snaps/R$ rstats.R 
/snap/rstats/x1/bin/R: line 236: /lib/R/etc/ldpaths: No such file or directory
ERROR: R_HOME ('/lib/R') not found

You can’t set the variable in the snapcraft.yaml alone as it will then get overridden by the entry in the script. My point was to bypass the script, understand what it’s doing and re-implement those settings (if possible) in the yaml as an environment section, then bypass the script, calling whatever the script calls, inside the snap, not calling the script directly.

That makes sense. If i understand the script correctly, i want to call $SNAP/lib/R/bin/R Is this correct? I also look at the export inside the script to try to figure out which are the variables that i have to set. This is what my yaml looks like now:

name: rstats 
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: R is a language and environment for statistical computing and graphics
description: |
  R is ‘GNU S’, a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. Please consult the R project homepage for further information.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
base: core18

apps:
  R:
    command: $SNAP/lib/R/bin/R
    environment:
      R_HOME: $SNAP/lib/R
      R_SHARE_DIR: $SNAP/lib/R/share
      R_INCLUDE_DIR: $SNAP/lib/R/include
      R_DOC_DIR: $SNAP/lib/R/doc
    plugs:
      - network
      - network-bind
      - home

parts:
  r:
    # See 'snapcraft plugins'
    plugin: autotools
    source: https://cran.rstudio.com/src/base/R-3/R-3.1.3.tar.gz
    configflags:
      - --enable-R-shlib
      - --with-blas
      - --with-lapack
      - --with-cairo
    build-packages:
      - gcc 
      - g++ 
      - gfortran
      - libblas-dev
      - liblapack-dev 
      - tcl-dev
      - tk-dev
      - bison
      - groff-base
      - libncurses5-dev
      - libreadline-dev
      - debhelper 
      - texinfo
      - libbz2-dev
      - liblzma-dev
      - libpcre3-dev
      - libcurl4-openssl-dev 
      - xdg-utils
      - zlib1g-dev
      - libpng-dev
      - libjpeg-dev
      - libx11-dev
      - libxt-dev
      - x11proto-core-dev
      - libpango1.0-dev
      - libcairo2-dev
      - libtiff5-dev
      - xvfb
      - xauth
      - xfonts-base
      - texlive-base
      - texlive-latex-base
      - texlive-generic-recommended
      - texlive-fonts-recommended
      - texlive-fonts-extra
      - texlive-extra-utils
      - texlive-latex-recommended
      - texlive-latex-extra
      - default-jdk 
      - mpack
      - bash-completion
      - libicu-dev

When I tried to compile it I got the following error:

usr/lib/x86_64-linux-gnu/libxcb.so.1
Sorry, Snapcraft ran into an error when trying to running through its
lifecycle that generated a trace that has been put in '/tmp/tmpt9nznfz8/trace.txt'.
"Submitting this error to the Snapcraft developers is not possible through the CLI
without Raven installed.
If you wish to report this issue, please copy the contents of the previous traceback
and submit manually at https://launchpad.net/snapcraft/+filebug.

What am I doing wrong this time?

Omit the leading $SNAP/ from the command: line. Just have command: lib/R/bin/R (assuming that’s where the R binary is inside the snap).

1 Like

I think my mistake now is in how I declare the environmental variables.

ignacio@ignacio-XPS-8930:~/Documents/snaps/R$ rstats.R 
WARNING: ignoring environment value of R_HOME
/snap/rstats/x1/lib/R/bin/R: line 236: /lib/R/etc/ldpaths: No such file or directory
ERROR: R_HOME ('/lib/R') not found

This is how the yaml looks like right now:

name: rstats 
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: R is a language and environment for statistical computing and graphics
description: |
  R is ‘GNU S’, a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. Please consult the R project homepage for further information.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
base: core18

apps:
  R:
    command: $SNAP/lib/R/bin/R
    environment:
      R_HOME: $SNAP/lib/R
      R_SHARE_DIR: $SNAP/lib/R/share
      R_INCLUDE_DIR: $SNAP/lib/R/include
      R_DOC_DIR: $SNAP/lib/R/doc
    plugs:
      - network
      - network-bind
      - home

parts:
  r:
    # See 'snapcraft plugins'
    plugin: autotools
    source: https://cran.rstudio.com/src/base/R-3/R-3.1.3.tar.gz
    configflags:
      - --enable-R-shlib
      - --with-blas
      - --with-lapack
      - --with-cairo
    build-packages:
      - gcc 
      - g++ 
      - gfortran
      - libblas-dev
      - liblapack-dev 
      - tcl-dev
      - tk-dev
      - bison
      - groff-base
      - libncurses5-dev
      - libreadline-dev
      - debhelper 
      - texinfo
      - libbz2-dev
      - liblzma-dev
      - libpcre3-dev
      - libcurl4-openssl-dev 
      - xdg-utils
      - zlib1g-dev
      - libpng-dev
      - libjpeg-dev
      - libx11-dev
      - libxt-dev
      - x11proto-core-dev
      - libpango1.0-dev
      - libcairo2-dev
      - libtiff5-dev
      - xvfb
      - xauth
      - xfonts-base
      - texlive-base
      - texlive-latex-base
      - texlive-generic-recommended
      - texlive-fonts-recommended
      - texlive-fonts-extra
      - texlive-extra-utils
      - texlive-latex-recommended
      - texlive-latex-extra
      - default-jdk 
      - mpack
      - bash-completion
      - libicu-dev

Any thoughts?

The file you’re pointing to in command: is just another copy of the shell script, and not the R binary. I ran snapcraft --debug and had a look in parts/r/install and under lib/R/bin/exec is the actual R binary. So you likely want:

command: lib/R/bin/exec/R

Thanks @popey. I’m getting a brand new error now, which I guess is good progress:

ignacio@ignacio-XPS-8930:~/Documents/snaps/R$ rstats.R 
/snap/rstats/x1/lib/R/bin/exec/R: error while loading shared libraries: libR.so: cannot open shared object file: No such file or directory

If I understand this correctly, I’m messing up the environmental variable for the libraries because I do have that file in /snap/rstats/x1/lib/R/lib

This is my yaml:

name: rstats 
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: R is a language and environment for statistical computing and graphics
description: |
  R is ‘GNU S’, a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. Please consult the R project homepage for further information.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
base: core18

apps:
  R:
    command: lib/R/bin/exec/R
    environment:
      R_HOME: $SNAP/lib/R
      R_SHARE_DIR: $SNAP/lib/R/share
      R_INCLUDE_DIR: $SNAP/lib/R/include
      R_DOC_DIR: $SNAP/lib/R/doc
    plugs:
      - network
      - network-bind
      - home

parts:
  r:
    # See 'snapcraft plugins'
    plugin: autotools
    source: https://cran.rstudio.com/src/base/R-3/R-3.1.3.tar.gz
    configflags:
      - --enable-R-shlib
      - --with-blas
      - --with-lapack
      - --with-cairo
    build-packages:
      - gcc 
      - g++ 
      - gfortran
      - libblas-dev
      - liblapack-dev 
      - tcl-dev
      - tk-dev
      - bison
      - groff-base
      - libncurses5-dev
      - libreadline-dev
      - debhelper 
      - texinfo
      - libbz2-dev
      - liblzma-dev
      - libpcre3-dev
      - libcurl4-openssl-dev 
      - xdg-utils
      - zlib1g-dev
      - libpng-dev
      - libjpeg-dev
      - libx11-dev
      - libxt-dev
      - x11proto-core-dev
      - libpango1.0-dev
      - libcairo2-dev
      - libtiff5-dev
      - xvfb
      - xauth
      - xfonts-base
      - texlive-base
      - texlive-latex-base
      - texlive-generic-recommended
      - texlive-fonts-recommended
      - texlive-fonts-extra
      - texlive-extra-utils
      - texlive-latex-recommended
      - texlive-latex-extra
      - default-jdk 
      - mpack
      - bash-completion
      - libicu-dev

Should I be setting R_HOME: $SNAP/lib/R to something different?

You will probably need to set LD_LIBRARY_PATH in the environment section so R can find libR.so because it’s in a funky location.

LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/lib/R/lib

1 Like