Skip to main content

R on the clusters

R is provided via the new software environment

Interactive mode

To load R:

module load gcc r
# Then you can use R interactively
> ...

Batch mode

While using R in batch mode, you have to use Rscript to launch your script. Here is an example of sbatch script,


#SBATCH --time 00-00:20:00
#SBATCH --nodes 1
#SBATCH --ntasks 1
#SBATCH --cpus-per-task 1
#SBATCH --mem 4G

module load gcc r

Rscript my_r_script.R

Then, just submit the job to Slurm:


Package installation

A number of core packages are installed centrally - you can see what is available by using the library() function. Given the number of packages and multiple versions available other packages should be installed by the user. 

Installing R packages is pretty straightforward thanks to install.packages() function. However, be careful since it might fill your home directory very quickly. For big packages with large amount of dependencies, like adegenet for instance, you will probably reach the quota before the end of the installation. Here is a solution to mitigate that problem:

rm -rf $HOME/R
  • Create a new library in your scratch directory (obviously modify the path according to your situation):
mkdir -p /scratch/wally/FAC/FBM/DEE/my_py/default/jdoe/R
cd $HOME
ln -s /scratch/wally/FAC/FBM/DEE/my_py/default/jdoe/R
  • Install your R packages


Warning for Axiom and Wally!!!

When working on Axiom and Wally clusters please be aware that the frontend nodes might have a more recent CPU architecture than that of the compute nodes. This leads to problems when installing R packages that involve compiling code as anything compiled on a newer machine will not work on an older one.

You should install your R packages on a node in the debug partition since these nodes have the oldest CPU architecture of the whole infrastructure (which is a way to ensure that it will work everywhere).

You can reserve a node interactively for up to one hour to perform your installation as follows:

Sinteractive -p debug -c 4 -m 16G -t 1:00:00

Once connected you can launch R as usual and perform the installation.


Warning for Jura!!!

Please refer to the page dedicated to offline installation on Jura.


Setting up an alternate personal library

If you want to set up an alternate location where to install R packages, you can proceed as follows:

mkdir -p ~/R/my_personal_lib2

# If you already have a ~/.Renviron file, make a backup
cp -iv ~/.Renviron ~/.Renviron_backup                  

echo 'R_LIBS_USER=~/R/my_personal_lib2' > ~/.Renviron

Then relaunch R. Packages will then be installed under ~/R/my_personal_lib2.