R

R is the name of both a programming language and a tool for statistics and stochastic simulations.

On the cluster, R version 3.6.3 is installed.

An introduction to R can be found here.

On this page you can find instruction on calling R, running scripts on the cluster and installing packages.

Calling R

For calling the interactive R environment, the corresponding module needs to be loaded:

module load R

Afterwards, it suffices to enter

R

Note that it is a capital R. Here are some short example commands in the R environment:

# This is a comment.
> 
> 2 # Output an  integer
[1] 2
> 2+3 # Simple addition
[1] 5
> log(2) # natural logarithm
[1] 0.6931472
> 
> x <- "Hello World!" # Saves a string in a variable
> x
[1] "Hello World!"

Individual commands or scripts (see below) can be run with the command Rscript:

$ Rscript -e "log(2)"

The commands need to be enclosed in either single or double quotes.

Scripts

As usual, R calls can also be put into a shell script instead of entering the manually in the console:

#!/bin/bash
Rscript -e "'Hello World!'"
Rscript -e "'1+1='"
Rscript -e 1+1

This will produce the following output:

[1] "Hello World!"
[1] "1+1="
[1] 2

With the scheduler SLURM, such a script can also be run on multiple nodes:

$ sbatch -N 2 my_Rscript.sh 
[1] "Hello World!"
[1] "Hello World!"
[1] "1+1="
[1] "1+1="
[1] 2
[1] 2

In this example, two nodes are used. You can learn more about jobs here

Packages

R has a system for installing packages. The available packages are listed on the CRAN homepage.

You can install R packages on the OMNI cluster yourself. By default, the packages are installed into your home directory (in a subdirectory also named R). They are then available to you. If a large number of users needs the same packages (e.g. an entire chair), we can also install packages in a central location for you. In this case please contact hpc-support@uni-siegen.de.

In order to install a package:

  1. Open the R console on the cluster with R

  2. In the R console, enter:

    install.packages("Packagename")

    The package name needs to be in quotes.

  3. Select an installation mirror. This choice does not matter much, except that closer mirrors might be faster than ones that are further away (e.g. outside Europe). If you are connected via an SSH connection with X window support, R might open a window here.

  4. Note the output. It may happen that R needs to compile external code (e.g. C code), in that case errors may occur. If a package installation fails, contact the HPC support or join us in our consultation hour.

Aktualisiert um 18:18 am 8. February 2021 von Gerd Pokorra