Springe direkt zu Inhalt

R

Introduction

 R is a programming language and a software environment for statistical calculations and graphics.

Local Packages

Many packages are installed automatically with R.  However, if a package is missing, you can install it locally in your home directory. 

Warning: In general installing a package within a batch job will not work.  There the installation should be performed just once directly on the login node.

To do this you first need to start the desired version of R

module load R/4.1.0-foss-2021a
R

In R you then need to run install.packages, e.g.:

install.packages('ergm')

The first time you do this you will be asked to select a server from which the package should be downloaded. In general you should choose a server in Germany.

Job scripts

A simple example script which can be sent to the resource manger could looks as follows:

#!/bin/bash

#SBATCH --job-name=my_R_job
#SBATCH --ntasks=1                             
#SBATCH --mem-per-cpu=4096
#SBATCH --time=1-12:00:00
#SBATCH --qos=standard

module load R/3.5.1-foss-2018b

cd /scratch/${USER}/r-jobs

Rscript script.r arg1 arg2

Parallel jobs can be started with the R package Rmpi. In this case, the number of tasks must be given via the resource manager parameter --ntasks. In contrast, the number process to start which is passed to mpirun with the option -np must be set to 1:

#!/bin/bash

#SBATCH --job-name=my_R_job
#SBATCH --ntasks=8                             
#SBATCH --mem-per-cpu=4096
#SBATCH --time=1-12:00:00
#SBATCH --qos=standard

module load R/3.5.1-foss-2018b

cd /scratch/${USER}/r-jobs/

mpirun -n 1  Rscript rmpi_job.r ${SLURM_NTASKS} arg1 arg2