Programming Language R
| Affiliation | OMNI Cluster |
| Billing |
Free of charge |
|
Documentation |
An introduction to R can be found here. |
| Pre-installed on the cluster |
R 3.6.3 |
Calling R
For calling the interactive R environment, the corresponding module needs to be loaded:
module load RAfterwards, it suffices to enter
RNote that it is a capital R. Here are some short example commands in the R environment:
# This is a comment
>
> 2 # Enter a natural number
[1] 2
> 2+3 # Perform a simple addition
[1] 5
> log(2) # natural logarithm
[1] 0.6931472
>
> x <- "Hello World!" # Speichert einen String
> 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+1This will produce the following output:
[1] "Hello World!"
[1] "1+1="
[1] 2Using the scheduler SLURM you can also run such a script on several nodes:
$ srun -N 2 R/Rscript.sh
[1] "Hello World!"
[1] "Hello World!"
[1] "1+1="
[1] "1+1="
[1] 2
[1] 2Two nodes are used in this example. You can find out more about jobs here.
Packages
R has a system for installing packages. The available packages can be found on the CRAN website website.
You can install R packages yourself on the OMNI cluster. The packages are installed by default in your home directory (in a subfolder that is also called R ). They are then available to you. If a larger number of users need the same packages (e.g. an entire department), it may be worthwhile for us to install packages centrally. In this case, please contact us.
Please carry out the following steps if you wish to install a package:
- Open the R console on the cluster with
R - Enter the following in the R console (the package name must be in quotation marks)
install.packages("package name")- Select the installation mirror. This has little effect, except that closer mirrors are usually faster than those further away (e.g. outside Europe). If you are using the SSH connection with X support R may open a window here.
- Pay attention to the output. External code (e.g. C code) may have to be compiled during package installation. In this case, errors may occur. If a package installation fails, please contact the support-team or come to the weekly office hours.