Running R on CREATE¶
Using modules, R/4.3 is the current default version on CREATE HPC.
Tip
To avoid memory limitations on the login nodes, request an interactive session to complete your installation process. R and its' dependencies can require more memory than what is allocated as default. Please see the documentation on how to request more resources when using CREATE HPC.
How to use R via Modules¶
You can use the R modules within CREATE to run the R interactively within the terminal and install R packages:
1 2 3 |
|
When installing a package not every software dependency would be loaded with the default R module.
If you are installing a package like the lme4
package. Your installation may run into this missing dependency issue and give a warning like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
A lot of software is already installed on CREATE and is available through modules. module avail
will help with finding these dependencies.
For the lme4
example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
If you ever get an error similar to the cmake
not found make sure:
If you have searched using module avail
and you still cannot find the dependency within the modules then raise a software request to support@er.kcl.ac.uk.
Using pkg-config¶
To install certain R packages on the HPC you will need to set some additional environment variables.
You can do this using pkg-config, which is available through module: pkgconf/1.9.5-gcc-13.2.0
.
For example, the following instructions can be used to install devtools
:
1 2 3 4 5 6 7 |
|
Setting a new package-library location¶
By default, R will set your home directory as the library path for all new package installs. To avoid using too much of the storage space available in your home directory, which may result quota limits being reached, you can create and set a new library location on your own personal scratch directory, as shown here:
1 |
|
Now using R to install the packages interactively:
1 2 3 4 |
|
Make sure the new library path is included in your R scripts or interactive sessions:
Example batch script:
1 2 3 4 5 6 7 8 |
|
With an example R script (library-test.R
) using the new library location:
1 2 3 4 5 6 |
|
Using Singularity to set up R¶
Singularity is a containerisation tool, similar to Docker, which can be used to run R on CREATE HPC. The following command can be used to download the lastest version of R available from Docker Hub:
1 |
|
Tags can also be used for downloading more specific versions: docker://r-base:3.6.1
.
The Rocker Project is also a great source for containerised R environments, enabling both reproducible builds and complete dependency solutions:
1 |
|
This should create a Singularity image file called: r-ver_4.3.0.sif
.
The next example downloads R 4.2.2 with all the requirements for tidyverse and more.
1 |
|
Interactive R containers¶
Use the following commands to run a interactive containerised R version:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Running containerised RScripts¶
Singularity containers can also be used to run your required Rscripts.
Example Rscript called test.R
:
1 2 3 |
|
Which can be executed with your container and through sbatch:
1 2 3 4 5 |
|
Binding container paths for R¶
By default, within the context of your containerised R application, unlike other immediate /scratch
paths on the HPC, your host home directory (/users/k1234567/R/...
) is an accessible mounted path in your R container.
Therefore, all packages you install in your container will be written to your home directory - the default library location - so to avoid using too much of your home directory storage, you can specify and bind a different HPC location for your containerised R to install to:
1 2 |
|
The above binds your host scratch path: /scratch/users/k1234567/software
to a new example container path: /my-libraries
, where any changes that occur on /my-libraries
in your container will correspond to /scratch/users/k1234567/software
, however, within the context of your container, only /my-libraries
is accessible, and the path /scratch/users/k1234567/software
does not exist.
Whilst in the same container shell session as above, you can use .libPaths()
to set the alternative library location for your containerised R package installations:
1 2 3 4 |
|
It is also possible to specifiy and bind multiple paths for your container, where the following example container path /my-data
will correspond to your HPC host path /scratch/users/k1234567/data
in addition to the above /my-libraries
example:
1 2 3 4 5 |
|
Such container paths should also be used in your Rscripts.
Containerised R with Jupyter¶
Instructions on how to launch Jupyter with R through Singularity is available in our documentation here.
Setting up R with Anaconda¶
You can also use the Anaconda package manager to use R.
To set up the conda environment in a non standard conda package cache location, and save space in the user directory, run these commands:
1 2 |
|
Note that if not specified r-base will load the latest version of R, in this case it, is R 4.3.1.
This will load the Anaconda environment with some of the more popular R packages.
Make sure to include the r-
when installing, updating or removing the R packages e.g. conda install r-tidyverse
.
Anaconda does not have every single package in the CRAN repository but r-base
and r-essential
will load with
many of the popular packages that R users need.