R is a software environment for statistical computing and graphics.

Category:  Bioinformatics/Statistics

Availability: Open access for all academic users



Usage Notes

To show the software versions:  module avail R

Loading the module will set the path and any necessary variables:  module load R/version

Rmpi, an interface to MPI (Message-Passing Interface), is available with versions of R 2.11.1 and greater.  Sample SLURM scripts and examples are in the /util/academic/R directory - subdirectories: Rmpi-example, Rmpi-simple, and Rmpi-julia.


R manuals can be found here



Additional Information

Numerous add-on packages for R have been installed in many of the CCR R installations; however, they may vary by version. A complete list for a given version may be viewed using the following command, after loading your preferred R version using the 'module load' command:


cat $R_DIR/PkgList.txt



To install an R package in user (or projects) space:


Nearly 20,000 packages are available for R.  If you want to use a package for R that is not already installed, you can install your own packages by either downloading the package and installing it or pointing to the R package library and installing directly from there.  The two options are shown below.  To see the full list of R packages available, please visit the R project page: 

 https://cran.r-project.org/


Option 1: Download and install R packages in your home or project directory


Download the R package you want to install.  In this example, we demonstrate the 'readr' package:

 wget https://cran.r-project.org/src/contrib/readr_2.0.2.tar.gz


Create your R library directory in your home or project directory, if you don't have one already.  For example:

mkdir /user/[username]/rlibs

or

mkdir /projects/[academic/industry]/[groupname]/[username]/rlibs


Then point to that directory when installing the R library you want to use:

R CMD INSTALL -l /user/[username]/rlibs package


For our example, to install the readr package we got with the wget command:

R CMD INSTALL -l /user/[username]/rlibs readr_2.0.2.tar.gz


Option 2: Install directly from the R Project repository from within R:


Load your preferred version of R and launch R:

module load R/version

R


Then install the package by specifying the package name, R project repository, and your R library location in your home or project directory


install.packages("package_name", repos = "http://cran.r-project.org", lib = "/user/[username]/rlibs")


For our example, to install the readr package:

install.packages("readr", repos = "http://cran.r-project.org", lib = "/user/[username]/rlibs")



To load an R package from user (or projects) space:


module load R

R
library(package, lib.loc="/user/[username]/rlibs/")


For our example, this would be:

library(readr, lib.loc="/user/username]/rlibs/")



Installing R packages from within the R Studio GUI:

Whether using CCR's R Studio app on OnDemand or launching it from the command line, users can install R packages into their home or project directories.  Launch R Studio and navigate to the Tools menu and click on 'Install Packages'


Make sure the installation directory is specifying either your home directory or a subdirectory within your group's shared project directory and check the "Install dependencies" option:



In this example, we've installed ggplot2 which completes the installation but does give an error that not all features are available in this version of R:




Common Installation Error


ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'


If you are trying to install a R library and see this error, it is trying to create a temporary directory to use during the installation and isn't able to.  To resolve this, create a temporary directory in your home or project directory and, after starting R, set the variable before attempting the installation:

dir.create("/user/username/tmp/")

Sys.setenv(TMPDIR="/user/username/tmp/")

install.packages(“XML”)


The directory will be used during installation and the temporary files removed when the install is complete.