This article is a draft

This is not a complete article: This is a draft, a work in progress that is intended to be published into an article, which may or may not be ready for inclusion in the main wiki. It should not necessarily be considered factual or authoritative.




"R is a system for statistical computation and graphics. It consists of a language plus a run-time environment with graphics, a debugger, access to certain system functions, and the ability to run programs stored in script files."

Even though R was not developed for high performance computing (HPC), its popularity with scientists from a variety of disciplines, including engineering, mathematics, statistics, bioinformatics, etc. makes it an essential tool on HPC installations dedicated to academic research. Features such as C extensions, byte-compiled code and parallelisation allow for reasonable performance in single-node jobs. Thanks to R’s modular nature, users can customize the R functions available to them by installing packages from the Comprehensive R Archive Network (CRAN) into their home directories.

The R interpreter

You need to begin by loading an R module; there will typically be several versions available which you can see using the command

 
[name@server ~]$ module avail R

You can load a particular R module using a command like

 
[name@server ~]$ module load R/3.3.2

and with R now loaded in your environment, you can start the R interpreter, and type R code inside that environment:

 
[name@server ~]$ R

To execute R scripts, use the Rscript front-end with the file containing the R commands as an argument:

 
[name@server ~]$ Rscript computation.R

This front-end will automatically pass scripting-appropriate options --slave and --no-restore to the R interpreter. These also imply the --no-save option, preventing the creation of useless workspace files on exit.

Installing R packages

To install packages from CRAN, you can use the install.packages facility inside the R interpreter. For example, to install the sp package that provides classes and methods for spatial data, use the following command on a login node:

 
[name@server ~]$ R
[...]
> install.packages("sp")

When asked, select an appropriate mirror for download. Ideally, it will be geographically close to the cluster you're working on.

Some packages require defining the environment variable TMPDIR before installing.

To install a package that you downloaded (i.e. not from CRAN), you can install it the following way. Assuming the package is named archive_package.tgz, run the following command in a shell:

 
[name@server ~]$ R CMD INSTALL archive_package.tgz