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

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:

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

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.5.1 (with additional CRAN packages) R-bundle-CRAN/2025.10-foss-2025a
4.5.1 R/4.5.1-gfbf-2025a
4.4.2 (with additional CRAN packages) R-bundle-CRAN/2024.11-foss-2024a
4.4.2 R/4.4.2-gfbf-2024a
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

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

By default, 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.

However, on the HPCC, we have overridden this default behavior so that package installations can run on all common node types (NVIDIA Grace nodes are the only exception). As a side effect, code installed from packages may not be as optimized and therefore may run slightly slower.

(Advanced) Optimizing package installation

We recommend that you do not optimize packages to a particular node type so that you are able to benefit from running your R code anywhere on the HPCC. However, if you would like to override the generic behavior above to optimize your packages to a specific type of node, you can unset the R_MAKEVARS_SITE environment variable responsible for this option after you load the respective R module. Note that this can only be accomplished on the command line, but only needs to be done once when the package is installed.

module purge
module load R
unset R_MAKEVARS_SITE
R
# inside R
> install.packages('example')

You do not need to run unset R_MAKEVARS_SITE the next time you use the packages, but you will need to adapt your workflow to avoid "illegal instruction" errors. See the tips in the section below to avoid these errors.

How to fix "Illegal instruction error"

If you have installed a package that was customized to one type of node (e.g., you followed the optimization instructions above or installed a package before the global generic installation setting was enacted on June 30, 2026) that package may not be usable on other types of nodes. This manifests as an "illegal instruction" error. If you get this error, you can either reinstall your library so that all packages are generic or ensure that you always choose 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-amd20 corresponds to amd20 nodes)
In a SLURM job Add a constraint like #SBATCH --constraint=amd20
In OnDemand Choose the Node type in the Advanced Options menu

If you aren't sure which node type to use, choose amd20. There are the largest number of nodes, and is the most compatible with other nodes.

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

Reinstalling a library

You may wish to reinstall an entire library of packages (e.g., to replace node-optimized packages with generic ones).

To do so, start R and save your installed packages to a file:

packages <- installed.packages()[,"Package"]
save(packages, file = "Rpackages")
q()

Then backup your previous library to avoid conflicts. Usually, your packages are stored in subdirectories of ~/R/x86_64-pc-linux-gnu-library labeled by the version of R they were installed with, but if you would like to double check, you can run R and look at the first entry of

.libPaths()

Move this library to a backup location so you can go back to it if necessary by running this command from the command line.

mv ~/R/x86_64-pc-linux-gnu-library ~/R/x86_64-pc-linux-gnu-library.backup

Finally, start R and reinstall the packages listed in your Rpackages file that are not already installed.

load("Rpackages")
new_packages <- setdiff(packages, installed.packages()[,"Package"])
for(p in new_packages)
install.packages(p)

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:

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:

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.