Illinois

Main navigation

University of Illinois shared computing cluster

R on the Campus Cluster

  1. Introduction
  2. Versions
  3. Adding R to Your Environment
  4. Installing Add-on Packages (in user specified locations)
  5. Viewing installed R packages

Introduction

R is a programming language and software environment for statistical computing and graphics. R and its libraries implement a wide variety of statistical and graphical techniques, including linear and non-linear modelling, classical statistical tests, time-series analysis, classification, clustering, and others. R is easily extensible through functions and extensions, and the R community is noted for its active contributions in terms of packages. R is also an interpreted language in which users typically access it through a command-line interpreter.

R and R packages are available via the "Comprehensive R Archive Network" (CRAN), a collection of sites which carry identical material, consisting of the R distribution(s), the contributed extensions, documentation for R, and binaries.

Versions

The table below list the versions of R installed on the Campus Cluster.

Version
R 3.4.2
R 3.3.3
R 3.2.5
R 3.2.2
R 3.1.2
R 3.1.0

Adding R to your environment

Each R installation on the Campus Cluster has a module that you can use to load a specific version of R into your user environment. You can see the available versions of R by typing module avail R on the command line. The latest version of R available on the Campus Cluster can be loaded into your environment by typing module load R. To load a specific version you will need to load the corresponding module. See the section Managing Your Environment in the User Guide for more information about modules.

Installing Add-on Packages (in user specified locations)

Any R add-on package not available in the system installation (see here for information on viewing the list) can be installed from the CRAN in a user specified location that you have write access to with just a few easy steps.

Generally when installing any software there are a few things to consider

Installation Command Syntax

R package installations for the most part are straight forward. Minimally, all that is needed is the name of the package that is to be installed, but installation location and the repository can also be specified.

Command ("Package Name", "Location", "Repository") Behavior
install.packages('package_name', '/path/to/r_libraries', 'Repository URL') Installs the package downloaded from the specified repository in the specified location
Command ("Local Filename", "Location", "Repository") Behavior
install.packages('package_name.tar.gz', '/path/to/r_libraries', repos = NULL) Installs the local package(file) in the specified location specifying no repository(NULL)

When the installation location and the repository URL are not specified, R packages are installed in a default location and the R installation process prompts to choose from a list of repositories.

R packages downloaded manually from the CRAN can be installed by specifying the local filename and omitting the repository URL (specifying NULL).

Using Rscript

To run R commands without starting an R session the command Rscript can be used (as we show in the examples on this page). As a scripting front end for R, Rscript enables the use of R via shell scripts and scripting applications.

Installation Steps

Below are steps with examples of the actual commands that can be run on the Campus Cluster. In these steps ~/Rlibs is used for the location to install user specific add-on packages (The tilde "~" means the users' home directory -- i.e. $HOME).

Note: It is assumed that these steps are being run under the default BASH shell. When using a different shell the syntax for that shell should be used where appropriate.

Step Description Command
1 Create a directory for your R packages mkdir ~/Rlibs
2 Load the R modulefile module load R/3.2.2
3 Set the R library environment variable (R_LIBS) to include your R package directory export R_LIBS=~/Rlibs
4 Use the install.packages function to install your R package. Rscript -e "install.packages('RCurl', '~/Rlibs', 'http://ftp.ussg.iu.edu/CRAN')"

If the environment variable R_LIBS is not set and a directory is not specified with the install.packages command, the R package will be installed under

by default. (This R subdirectory structure is created automatically.)

The R_LIBS environment variable will need to be set every time when logging in to the Campus Cluster if the user's R package location is to be visible to an R session. The following:

  if [ -n $R_LIBS ]; then
      export R_LIBS=~/Rlibs:$R_LIBS
  else
      export R_LIBS=~/Rlibs
  fi

can be added to a user's ~/.bashrc file to remove the need to set the R_LIBS environment variable with every login session to the Campus Cluster.

Warnings and error messages

R packages that are not available in the current CRAN (Comprehensive R Archive Network) or if the name of the package is misspelled, tend to generate a message similar to the following:

Searching the CRAN site for your desired R package may provide links to archived versions that are not available in the current CRAN. In this case the specific archived R package can be downloaded and installed from the local file using the same command but omitting the repository URL (specifying NULL).

Some R packages have dependencies and require them to be installed first and will generate an error message similar to the following:

Installing the required R package first then the desired R package resolves this issue.

Viewing installed R packages

The library() command can be used to view all user and system installed R packages (user installed packages are only visible to R when the $R_LIBS environment variable is set).