R
Guidance last updated: 20 October 2026
R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R.
Warning
The CPU & GPU nodes have different CPU architectures (Intel & AMD respectively). R packages containing compiled code may fail when used on a different CPU architecture. Install these packages for the architecture on which they will run, using separate personal libraries as described under Installing additional packages.
Interactive Usage
After connecting to Stanage (see Establishing a SSH connection), start an interactive session:
salloc
You can then load a specific version of R using:
module load R/4.5.2-gfbf-2025b
module load R/4.5.2-gfbf-2025b
R can then be run with:
$ R
Serial (one CPU) Batch usage
Here, we assume that you wish to run the program my_code.r on the system.
With batch usage it is recommended to load a specific version of R,
for example module load R/4.5.2-gfbf-2025b,
to ensure the expected output is achieved.
First, write an example batch submission script named my_job.slurm:
#!/bin/bash
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=4000 # Request 4GB of memory
#SBATCH --mail-user=username@sheffield.ac.uk # Replace with your email address
module load R/4.5.2-gfbf-2025b # Recommended to load a specific version of R
export OPENBLAS_NUM_THREADS=1
export OMP_NUM_THREADS=1
R CMD BATCH my_code.r my_code.r.${SLURM_JOB_ID}.out
Note that R must be called with both the CMD and BATCH options
which tell it to run an R program,
in this case my_code.r.
If you do not do this, R will attempt to open an interactive prompt.
The final argument, my_code.r.${SLURM_JOB_ID}.out, tells R to send output to a file with this name.
Since my_code.r.${SLURM_JOB_ID}.out will always be unique, this ensures that all of your output files are unique.
Without this argument R sends all output to a file called my_code.r.Rout.
Ensuring that my_code.r and my_job.slurm are both in your current working directory,
submit your job to the batch system
sbatch my_job.slurm
Replace my_job.slurm with the name of your submission script.
Warning
By default, R will save variables in the workspace in the current directory
(in a file called .RData)
when a script exits and reload them when it starts from the same directory.
To disable this, add the --no-save and --no-restore options to your command
e.g. R CMD BATCH --no-save --no-restore my_code.r my_code.r.${SLURM_JOB_ID}.out.
Graphical output
By default, graphical output from batch jobs is sent to a file called Rplots.pdf.
Installing additional packages
The module includes a selection of additional R packages, but not all packages
available on CRAN. Use installed.packages() in R to check which packages are
available before installing additional packages.
If you use both Intel and AMD nodes, you can keep compiled packages separate
by setting R_LIBS_USER
after loading the R module and before starting R on the allocated compute node:
export R_LIBS_USER="$HOME/R/$EBVERSIONR-$(awk '/^vendor_id/ {print $3; exit}' /proc/cpuinfo)-library"
mkdir -p "$R_LIBS_USER"
R
If you choose this setup, use these commands before running R in both interactive sessions and batch scripts. The library directory must exist when R starts. Install packages separately on each CPU architecture on which you will use them.
Without a custom setting, R uses its default personal library under ~/R/.
When installing your first package, accept the prompt to create this library.
Keep compiled packages separate if you switch CPU architectures.
From an interactive R session, install a package into your personal library with:
install.packages("dplyr", repos = "https://cloud.r-project.org")
Once the chosen package has been installed,
additional packages can be installed either in the same way,
or by creating a .R script.
An example script might look like:
install.packages("dplyr", repos = "https://cloud.r-project.org")
Call this using source().
For example if your script is called packages.R and is stored in your home folder,
source this from an interactive R session with:
source("~/packages.R")
Once the personal library has been created, this installs the package there without prompting for a CRAN mirror.
To check your packages are up to date, and update them if necessary, run the following line from an R interactive session
update.packages(lib.loc = Sys.getenv("R_LIBS_USER"))
R sets R_LIBS_USER to its default personal library path if you have not set
it yourself. If you use a custom setting, use it consistently when installing,
updating and using packages.
Warning
Notice that the personal package library path includes the version of R: if after installing some packages you switch to using a different major or minor version of R then you will need to install those packages for this new version.
R Packages that require external libraries
Some R packages require external libraries to be installed before you can install and use them
(e.g. hdf5r).
Since there are so many, we only install those libraries that have been explicitly requested by users of the system. Some associated R packages may need to be installed in your personal package library.
To load external libraries you should search for a module which matches the build chain of the R version you are using to avoid load conflicts e.g. for R 4.5.2, gfbf-2025b.
Available external libraries include UDUNITS, GEOS, GDAL, PROJ, HDF5 and NLopt. Consult your R package’s installation requirements to choose the libraries it needs.
To request the installation of dependencies for R packages that depend on non-R libraries
please contact research-it@sheffield.ac.uk.
Using the Rmath library in C Programs
The standalone Rmath library provides some of R’s numerical functions for C programs.
It is not included in R/4.5.2-gfbf-2025b. Contact research-it@sheffield.ac.uk if you require it.
For details about the available functions, see Writing R extensions.
Installation notes
This section is primarily for administrators of the system.
The latest version of R was installed manually.