Skip to content

Getting started with R

This page provides a quick explanation of using R on the system. For more details, see our R for HPCC workshop materials.

Accessing R and RStudio

R is available on the HPCC by default which means you can run it on the command line by using the command

1
R

To avoid any issues resulting from a user-customized .Renviron or .Rprofile file, you can also start R by using R --vanilla.

You can also use R via the RStudio Server interface through OnDemand. See our OnDemand documentation for more details.

Versions and bundles

The HPCC provides many versions of R, but we highly recommend using bundles which include extra R packages. Note that bundles are not loaded by default. There are two bundle flavors that include many common packages from the following sources: CRAN and Bioconductor.

You can see all available bundles with the above two links or by running:

1
module spider R-bundle

Our current recommendation is to use R-bundle-CRAN/2023.12-foss-2023a. To access this bundle from the command line, run

1
2
module purge
module load R-bundle-CRAN/2023.12-foss-2023a

To access this bundle in RStudio Server, choose the R version "4.3.2 (with additional CRAN packages, RECOMMENDED)".

Module names versus OnDemand versions

The modules on the command line associated with the R versions available through OnDemand are as follows:

OnDemand name module name
4.3.2 (with additional CRAN packages, RECOMMENDED) R-bundle-CRAN/2023.12-foss-2023a
4.4.1 (with additional CRAN packages) R-bundle-CRAN/2024.06-foss-2023b
4.3.2 (with additional CRAN packages, RECOMMENDED) R-bundle-CRAN/2023.12-foss-2023a
4.4.1 (with additional CRAN packages) R-bundle-CRAN/2024.06-foss-2023b
4.4.1 R/4.4.1-gfbf-2023b
4.3.3 R/4.3.3-gfbf-2023b
4.3.2 (with Bioconductor packages) R-bundle-Bioconductor/3.18-foss-2023a-R-4.3.2
4.3.2 R/4.3.2-gfbf-2023a
4.2.2 (with Bioconductor packages) R-bundle-Bioconductor/3.16-foss-2022b-R-4.2.2
4.2.2 (with additional CRAN packages) R/4.2.2-foss-2022b

Installing packages

Use the install.packages command to install packages in R. By default, these packages will be installed into your home directory in ~/R/x86_64-pc-linux-gnu-library/4.X where X is the minor version number of the version of R you are using (e.g., 3 for R version 4.3.2).

If you use a different minor version of R, you will need to reinstall all packages you need into the new location.

Managing different node types (how to fix "Illegal instruction error")

The HPCC has many different types of nodes you can run your code on. See a listing here.

When R installs a package, it customizes it to the type of node you installed it on. It is not guaranteed that you can then run this package on other node types.

Therefore, when using R, we recommend always choosing the same node type (whether you are using a development node, a SLURM job, or OnDemand). To select a node type use the following steps:

Method Instructions
On a development node Choose the development node with the same name as the nodetype (e.g., dev-intel16 corresponds to intel16 nodes)
In a SLURM job Add a constraint like #SBATCH --constraint=intel16
In OnDemand Choose the Node type in the Advanced Options menu

If you aren't sure which node type to use, choose intel16. There are the largest number of nodes, and it is the oldest which lowers the chance of compatibility issues.

For more on this topic, see our page on Architecture Specific Compilation.

Common issues

Installing the Matrix or MASS Packages

The default versions of the R packages Matrix and MASS (which are dependencies for many other packages including ggplot2) are incompatible with versions of R earlier than 4.4.0. Installations that require these packages will fail with a message like:

1
2
3
4
5
6
7
8
Warning message:
package ‘Matrix’ is not available for this version of R
‘Matrix’ version 1.7-3 is in the repositories but depends on R (>= 4.4)
‘Matrix’ version 1.7-3 is in the repositories but depends on R (>= 4.6)

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

We recommend using the R-bundle-CRAN module instead of R (discussed above) which includes pre-installed versions of these packages.

If you need to install these packages yourself using install.packages, You will need to use the direct URL of a version that is compatible with your version of R. As shown in the Matrix NEWS file and MASS changelog, versions 1.6-5 and 7.3-60.0.1 respectively will work with some earlier versions of R.

To install them, use install.packages with the link to the corresponding tar.gz source files in the Matrix and MASS archives with the options repos=NULL and type="source:

1
2
install.packages("https://cran.r-project.org/src/contrib/Archive/Matrix/Matrix_1.6-5.tar.gz", repos=NULL, type="source")
install.packages("https://cran.r-project.org/src/contrib/Archive/MASS/MASS_7.3-60.0.1.tar.gz", repos=NULL, type="source")

Note that you may need to install some additional dependencies using standard install.packages commands prior to these source installations, but R will show show you which ones are necessary if the above commands fail.