Introduction#
R is a system for statistical computation and graphics. It consists of a language plus a runtime environment with graphics, a debugger, access to certain system functions, and the ability to run programs stored in script files.
Available R versions#
Multiple versions of R are available. Use module spider r
to find out the different versions of R:
[~@ ~]$ module spider r
r/4.4.1+aocl-4.2.0
r/4.4.1+mkl-2019.5
r/4.4.1+mkl-2024.1
r/4.5.0+mkl-2024.1
At the time of updating this page, the version r/4.5.0+mkl-2024.1 is available and can be loaded using:
module load arch/avx512 gcc/13.2.0 r/4.5.0+mkl-2024.1
The R interpreter can be launched by invoking the command R afyer loading the module:
[~@yak ~]$ module load arch/avx512 gcc/13.2.0 r/4.5.0+mkl-2024.1
[~@yak ~]$ R
R version 4.5.0 (2025-04-11) -- "How About a Twenty-Six"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu
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.
[Previously saved workspace restored]
>
To run R code my-program.R interactively, use:
[~@yak ~]$ module load arch/avx512 gcc/13.2.0 r/4.5.0+mkl-2024.1
[~@yak ~]$ Rscript my-program.R
The following shows an example of scripts to run R code on Grex using a batch job:
#!/bin/bash
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=4000M
#SBATCH --time=8:00:00
#SBATCH --job-name=R-Test
# Load the modules:
module load arch/avx512 gcc/13.2.0 r/4.5.0+mkl-2024.1
echo "Starting run at: `date`"
Rscript my-program.R
echo "Program finished with exit code $? at: `date`"
Installing packages#
As mentioned above, the base modules have already some packages. However, users may have to install additional packages depending on what their program uses. Here is a quick example of installing a package called tidyverse unsing the R module r/4.5.0+mkl-2024.1.
[~@yak ~]$ module load arch/avx512 gcc/13.2.0 r/4.5.0+mkl-2024.1
[~@yak ~]$ R
[~@yak ~]$ > Sys.setenv("DISPLAY"=":0.0")
[~@yak ~]$ > install.packages("tidyverse")
For the first installation, there are two warning messages that ask questions about the personal library where R packages will be installed:
Warning in install.packages("tidyverse") :
'lib = "/home/software/alma8/sb/opt/arch-avx512-gcc-13.2.0/r/4.5.0+mkl-2024.1/lib64/R/library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) yes
Would you like to create a personal library
‘/home/kerrache/R/x86_64-pc-linux-gnu-library/4.5’
to install packages into? (yes/No/cancel) yes
The message refers to a path where the base module is installed. As a user, you do not have write access to this directory. Therefore, the answers to the above questions should be yes and the packages will be installed under a directory /home/$USER/R under your account where you have read and write access. You can add all your packages as described above and they will be stored under the directory /home/$USER/R. Please keep this directory as it is if you want to keep your packages. If deleted, you will have to re-install again your packages.
In the example of installing the package tidyverse, no additional library or module was required. However, on many cases, the installation of R packages requires additional modules. The list is, but not limited to, gsl, netcdf, hdf5, udunits, geos, proj, gdal, tbb, … etc. Usually, the error message gives a hint to the misssing library. The dependencies used to install any R package are also required to be loaded when running the job. As an example, to install the package rjags, one need to load jags module in addition to R:
[~@yak ~]$ module load arch/avx512 gcc/13.2.0 r/4.5.0+mkl-2024.1
[~@yak ~]$ module load jags
[~@yak ~]$ R
[~@yak ~]$ > Sys.setenv("DISPLAY"=":0.0")
[~@yak ~]$ > install.packages("rjags")