How to install additional R packages for your use on teton

Many R packages have been built for us and are available when we load R with the module system. For example, the module r/4.0.5-py27 makes available about 514 packages, including tidyverse, rstan, etc.

But you are likely to encounter instances where you want packages for yourself, ASAP, and that you don’t have a sense how likely others would be to use them. If so, this guide will give instructions for ways to do this.

Otherwise, for packages that are likely helpful for many users, see these considerations and ask ARCC to install these as part of the R module.

Packages that you want to share with others in your project space

On teton, do the following steps. At the UNIX command prompt, where you will need to substitute your project name for MYPROJECTNAME:

mkdir -p /project/MYPROJECTNAME/share/Rlibs/r4.0/ module load swset/2018.05 gcc/7.3.0 r/4.0.5-py27 R

Then, as below, within R and at its prompt, first prepend the new directory for R packages to the libPaths variable. This directory will be your primary directory and the system-wide, administrator controlled directory will be secondary. Then install a package (here the wesanderson color palette and load the library.

.libPaths("/project/MYPROJECTNAME/share/Rlibs/r4.0/") install.packages("wesanderson") library(wesanderson)

In future sessions, you or another member of your research project group will be able to start an R session and simply do the following to use this package (after substituting your project name for MYPROJECTNAME).

.libPaths("/project/MYPROJECTNAME/share/Rlibs/r4.0/") library(wesanderson)

Packages that only need to be accessible to you

If R packages can reside in your personal workspace (home directory), you can do the following.

Load R.

In R, install the package you want. It will be installed in ~/R/x86_64-pc-linux-gnu-library/4.0 by default.

Problems encountered and solutions offered

  1. I got the following errors trying to add those packages in Teton. When I don't add “repos='<http://cran.us.r-project.org'“> it requests to select a CRAN mirror and it crashs later. If anyone can help me, Id appreciate it.

>install.packages("ncdf4", repos='http://cran.us.r-project.org')
Installing package into '/pfs/tc1/project/modelscape/users/cbarbosa/share/Rlibs/r4.0'
(as 'lib' is unspecified)
trying URL 'http://cran.us.r-project.org/src/contrib/ncdf4_1.19.tar.gz'
Content type 'application/x-gzip' length 126381 bytes (123 KB)

downloaded 123 KB

Error, nc-config not found or not executable. This is a script that comes with the
netcdf library, version 4.1-beta2 or later, and must be present for configuration
to succeed.

If you installed the netcdf library (and nc-config) in a standard location, nc-config
should be found automatically. Otherwise, you can specify the full path and name of
the nc-config script by passing the --with-nc-config=/full/path/nc-config argument
flag to the configure script. For example:

./configure --with-nc-config=/sw/dist/netcdf4/bin/nc-config

Special note for R users:

To pass the configure flag to R, use something like this:

R CMD INSTALL --configure-args="--with-nc-config=/home/joe/bin/nc-config" ncdf4

where you should replace /home/joe/bin etc. with the location where you have
installed the nc-config script that came with the netcdf 4 distribution.

ERROR: configuration failed for package 'ncdf4'

  • removing '/pfs/tc1/project/modelscape/users/cbarbosa/share/Rlibs/r4.0/ncdf4'

The downloaded source packages are in
'/tmp/Rtmpd0ip2F/downloaded_packages'
Warning message:
In install.packages("ncdf4", repos = "http://cran.us.r-project.org") :
installation of package 'ncdf4' had non-zero exit status

>install.packages("sf", repos='http://cran.us.r-project.org')
Installing package into '/pfs/tc1/project/modelscape/users/cbarbosa/share/Rlibs/r4.0'
(as 'lib' is unspecified)
also installing the dependency 's2'

trying URL 'http://cran.us.r-project.org/src/contrib/s2_1.1.0.tar.gz'
Content type 'application/x-gzip' length 2283183 bytes (2.2 MB)

downloaded 2.2 MB

trying URL 'http://cran.us.r-project.org/src/contrib/sf_1.0-8.tar.gz'
Content type 'application/x-gzip' length 3472914 bytes (3.3 MB)

downloaded 3.3 MB

ERROR: failed to lock directory '/pfs/tc1/project/modelscape/users/cbarbosa/share/Rlibs/r4.0' for modifying
Try removing '/pfs/tc1/project/modelscape/users/cbarbosa/share/Rlibs/r4.0/00LOCK-s2'
ERROR: dependency 's2' is not available for package 'sf'

  • removing '/pfs/tc1/project/modelscape/users/cbarbosa/share/Rlibs/r4.0/sf'

The downloaded source packages are in
'/tmp/Rtmpd0ip2F/downloaded_packages'
Warning messages:
1: In install.packages("sf", repos = "http://cran.us.r-project.org") :
installation of package 's2' had non-zero exit status
2: In install.packages("sf", repos = "http://cran.us.r-project.org") :
installation of package 'sf' had non-zero exit status