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:
[~@yak ~]$ 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
r/4.5.0+openblas-0.3.28To see how to load a particular version, run the command module spider r/<version>.
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.1The 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 see the packages installed, use the command installed.packages()
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 R 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")The command Sys.setenv("DISPLAY"=":0.0") is not required but it helps for not opening the GUI interface that might be slow over ssh.
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/$USER/R/x86_64-pc-linux-gnu-library/4.5’
to install packages into? (yes/No/cancel) yesThe 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 all your packages. It is recommended to keep track on the installation process (like list of modules and packages) in case you need to reproduce the installation another time.
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")Packages from CRAN mirrors#
After loading r module and all the required dependencies, the installation of R package from CRAN is invoked by the command install.packages(“name of the package”) like in the following example for installing rjags. This package requires an additional external module called jags:
[~@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")It is possible to bundle more than one package in the same command line using:
install.packages(c("packae1", "package2", "package3"))Packages from GitHub repositories#
There are R packages hosted on GitHub and their installation require to first install devtools
or remotes
. First, one need to add the package devtools or remotes if not installed already and make them available in the R prompt before using them to install other packages.
Here is an example used to install stampr
with devtools:
[~@yak ~]$ module load arch/avx512 gcc/13.2.0 r/4.5.0+mkl-2024.1 gdal
[~@yak ~]$ R
[~@yak ~]$ > Sys.setenv("DISPLAY"=":0.0")
[~@yak ~]$ > install.packages("devtools")
[~@yak ~]$ > library("devtools")
[~@yak ~]$ > devtools::install_github("jedalong/stampr") Similar procedure could be used to install a package with ```remotes`:
[~@yak ~]$ module load arch/avx512 gcc/13.2.0 r/4.5.0+mkl-2024.1 gdal geos
[~@yak ~]$ R
[~@yak ~]$ > Sys.setenv("DISPLAY"=":0.0")
[~@yak ~]$ > install.packages("remotes")
[~@yak ~]$ > library("remotes")
[~@yak ~]$ > remotes::install_github("jedalong/stampr")Bioconductor packages#
The following example shows how to install the packages “edgeR”, “qvalue”, “GenomicAlignments”, “GenomicFeatures” using BiocManager :
[~@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 ~]$ > if (!require("BiocManager", quietly = TRUE))
[~@yak ~]$ + install.packages("BiocManager")
[~@yak ~]$ > BiocManager::install(c("edgeR", "qvalue", "GenomicAlignments", "GenomicFeatures"))