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

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

It works! However, when I start R I get a couple of errors:

ignacio@ignacio-XPS-8930:~/Documents/snaps/R$ rstats.R 

R version 3.1.3 (2015-03-09) -- "Smooth Sidewalk"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_COLLATE failed, using "C" 
3: Setting LC_TIME failed, using "C" 
4: Setting LC_MESSAGES failed, using "C" 
5: Setting LC_MONETARY failed, using "C" 
6: Setting LC_PAPER failed, using "C" 
7: Setting LC_MEASUREMENT failed, using "C" 

According to this stackoverflow answer, I should run defaults write org.R-project.R force.LANG en_US.UTF-8 to fix this error. How would I do that inside the snap?

I tried adding the following to the environment as suggested in [this post]:

    environment:
      LC_ALL: en_US.UTF-8
      LANG: en_US.UTF-8

Alas, that did not solve the problem. Any suggestions?

Hello Ignacio How far did you get on this in the end?

Not far at all. All my attempts and challenges are described in this thread. Are you going to give it a try?