Installing R packages

1. R availability

When you need to install a specific R package you DO NOT have to install R. We provide a few versions of R that can be accessed via modules. The base installs already have a lot of added packages. To find out what R is available:

[user@login-x:~]$ module avail R
---------------------- /opt/rcic/Modules/modulefiles/LANGUAGES ---------------------------
R/3.6.2 R/4.0.2 R/4.0.4 R/4.1.2

You can choose either R version, however it is advisable to stop using earlier release 3 and move to a later release of version 4. Steps below explain the basic steps specific to the cluster.

For additional info on installing R packages via different methods please see R documentation Installing R packages.

2. Install R packages

R has thousands of specific packages and it is not possible for us to maintain them all. For this reason users can easily add their desired packages to the base installs using local user area. The local installation of R packages will go to the $HOME/R and is automatically available to the user.

  1. Get an interactive node

    Always claim an interactive node because R builds involve compilation and downloads that can use a lot of CPU time and memory.

    [user@login-x:~]$ srun -c 2 -p free --pty /bin/bash -i
  2. Load desired module

    For building in your user area, first you need to load R module:

    [user@login-x:~]$ module load R/4.1.2

    Check that R is available to you, the output of the below command should be similar to:

    [user@login-x:~]$ which R
  3. Start R

    [user@login-x:~]$ R

    Check if your package is already installed:

    > packageVersion('farver')
    [1] ‘2.1.0’

    In case the package is not installed there will be an error:

    > packageVersion('farverB')
    Error in packageVersion("farverB") : there is no package called ‘farverB’
  4. Install your software package

    Below we provide a common example of installation from CRAN.

    > install.packages("ggfun")
    Warning in install.packages("ggfun") :
      'lib = "/opt/apps/R/4.1.2/lib64/R/library"' is not writable
    Would you like to use a personal library instead? (yes/No/cancel) yes (1)
    Would you like to create a personal library
    to install packages into? (yes/No/cancel) yes (2)
    --- Please select a CRAN mirror for use in this session ---
    Secure CRAN mirrors
     1: 0-Cloud [https]
     2: Australia (Canberra) [https]
     ... more lines deleted here
     71: USA (IA) [https]
    72: USA (KS) [https]
    73: USA (MI) [https]
    74: USA (OH) [https]
    75: USA (OR) [https]
    76: USA (TN) [https]
    77: USA (TX 1) [https]
    78: Uruguay [https]
    79: (other mirrors)
    Selection: 72 (3)
    trying URL ''
    Content type 'application/x-gzip' length 148598 bytes (145 KB)
    downloaded 145 KB
    * installing source package ‘ggfun’ ...
    ** package ‘ggfun’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    ** installing help indices
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded from temporary location
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
    * DONE (ggfun)
    The downloaded source packages are in
1 This warning is normal as users cant write in the system area. Response confirms to use a local library in the user area.
2 This confirms a creation of personal library. This is done once. Future installs will use this existing location.
3 There are many CRAN mirrors where R packages are available. Please select the US mirror.