Skip to content

Using R via Spack on the HPC

Samuel Jenness edited this page Sep 27, 2022 · 4 revisions

We use the package manager Spack to ensure that we have the same versions of R used across and within our projects. Several versions of R are already available on the HPC via modules, but these versions may be outdated or compiled in a way that is inconsistent with what you have on your local computer. To get started with using R on the HPC, you will need to set up Spack on the HPC one time and then load R with it each time.

First Time Setup

You start by loading Spack by running the following:

. /projects/epimodel/spack/share/spack/setup-env.sh

This such a commonly run line, I suggest making an alias for it.

alias lspack='. /projects/epimodel/spack/share/spack/setup-env.sh'

After Spack loads the first time, copy over a compiler file you will need to load R. This will copy a .yaml file over to a subdirectory in your home directory.

cp /projects/epimodel/shared/compilers.yaml ~/.spack/linux/

Once complete, you can see all of the versions of R available through Spack.

spack find r

Pick the version that matches what you have on your local computer. If that version is not available, let Sam know and he will build it for you on the HPC (if available). Generally , it is fine to use a different minor version of R, but not fine to use a different major version of R, where the versioning is in this format: 4.major.minor.

To load a specific version of R, you then use:

substituting the specific version number as needed.

You can test that this version runs by then typing:

R

which should bring up the standard R starting prompts:

[sjennes@clogin01 sjenness]$ R

R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Do not do anything further in R at this point, as you should not run any computational work on the login nodes on the HPC. You quit R with q().

To avoid getting asked whether to save your R data each time you quit R, I recommend setting up this alias that loads R up with those options turned off:

alias R='R --no-save --no-restore'

Loading R Every Time

Every time you use R (not on the login nodes!), you will first need to load Spack and then load the version of R you want to use. You can find the available versions of R via Spack that we have already built with:

lspack; spack find r

Using Git/Github directly on the command line after loading the R module above can occasionally create problems. Therefore, we recommend that you also load the Spack version of git at the same time you load the Spack version of R.

lspack
spack load [email protected]
spack load [email protected] # substitute R version as needed

Also, it is helpful to load R but avoid auto-saving and restoring global data each time you start/quit R. You can do that with:

R --no-save --no-restore

Putting it all together, try creating new aliases that automates this sequence:

alias lR='lspack; spack load [email protected]; spack load [email protected]; R --no-save --no-restore'

This will load Spack, load Git, load R, and start R all by typing just lR.