Repository navigation
Using R via Spack on the HPC
Who this is for: anyone who will run R on the HPC. Before you start: finish Setting Up Your HPC Environment and read HPC Rules, Storage, and Getting Help. This page only loads R; you start R on a compute node in the next page.
We use the package manager Spack to give everyone in the lab the same builds of R.
The official RSPH guide loads R with module load R. We do not use the module R. As of 10/12/26, module load R loads R 4.2.2 by default, and the module versions are built and updated by RSPH IT on their own schedule. Our projects need an R version that matches the one recorded in each project's renv lockfile, built the same way for everyone in the lab, so we keep our own R builds with Spack in /projects/epimodel/spack.
Do not mix the two: if you have loaded a module, run module purge before loading R with Spack. If you install conda for other work, turn off its automatic activation in ~/.bashrc, because conda's own compilers and libraries can break R package installs.
Spack is installed in our group folder. Load it into your current shell with:
. /projects/epimodel/spack/share/spack/setup-env.shYou will type this often, so add the lspack alias from Setting Up Your HPC Environment.
Spack commands take about a second. If you used Spack on the cluster before October 2026, you may have a private copy of Spack's package recipes in ~/.spack/package_repos/ (about 1.2 GB of your home quota). The lab now shares one copy, so you can delete yours with rm -rf ~/.spack/package_repos.
List the versions we have built:
spack find rAs of October 2026:
-
r@4.6.1is the newest version. The tutorials on these pages use it, and it is the one to use for work outside a project. -
r@4.5.1matches projects whoserenv.lockrecords R 4.5, which includes projects created from the current EpiModelHIV-Template. For project work, use the version your project'sR/hpc_configs.Rloads; the project workflows do this for you. - Older versions are kept only for old projects. Some of them (
r@4.1.2,r@4.2.0, andr@4.2.2) carry old copies of EpiModel and its dependencies in their own library, which R will use silently if your project does not install its own.
R versions are numbered major.minor.patch: in 4.6.1, 4 is the major version, 6 the minor version, and 1 the patch. Use the same major and minor version on the HPC as on your own computer and in your project's renv.lock; the patch number can differ. Packages installed under one minor version (4.5) must be reinstalled for another (4.6). If you need a version that is not listed, ask in #coding-help on the lab Slack.
spack unload -a
spack load r@4.6.1spack unload -a clears anything loaded earlier in the same shell, so you never have two versions of R loaded at once. Always include the version: spack load r on its own fails with r matches multiple packages.
To check that it worked, without starting R:
spack find --loaded
which RDo not start R on the login node, even to test it. The login node is only for logging in, moving files, git, and submitting jobs. All R work, including installing packages, runs on a compute node: interactively with srun (next page) or in a batch job with sbatch.
You do not need to load git from Spack; the system git works normally after R is loaded.
With these in your ~/.bashrc, typing lr loads Spack and R in one step (it does not start R):
alias lspack='. /projects/epimodel/spack/share/spack/setup-env.sh'
alias lr='lspack; spack unload -a; spack load r@4.6.1'
alias R='R --no-save --no-restore'The R alias starts R without asking whether to save or restore the workspace. Aliases work in your own shells, including srun sessions, but not inside batch scripts, so .sbatch files spell out the full commands.
EpiModel Research Lab wiki. Something out of date or unclear? Post in #coding-help on the lab Slack, or fix it yourself: see Contributing to This Wiki.
0. Start here
1. Your computer
2. Learn EpiModel
3. First project
4. Model code
5. HPC
- Access and login
- Environment setup
- Rules, storage, and help
- Files
- Git
- R via Spack
- srun
- sbatch
- Monitoring jobs
- Project workflows
- Checkpoints
6. Calibrate and analyze
7. Publish
8. Admin