Description
R is a free software environment for statistical computing and graphics.
Usage
module load 2023 module load R/4.3.2-gfbf-2023a
Installed packages
R module is installed with more than 700 packages. We are not listing them all here. However, you can always see them by calling the following command:
module load 2023 module show R/4.3.2-gfbf-2023a
If you believe a common R package is missing, please contact the helpdesk and we will install it for you.
Installing R packages
If you want to install your own specific packages, follow the guidelines described below. This is a recipe to install R packages from CRAN (http://cran.r-project.org/). As an example we demonstrate how to install the package far
.
Many packages are already installed (see above), so try that first:
module load 2023 module load R/4.3.2-gfbf-2023a R > require(far) Loading required package: far Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘far’
So, package far
is not installed. To install it:
module load 2023 module load R/4.3.2-gfbf-2023a
locate the package on the CRAN website and download it to Snellius
wget http://cran.r-project.org/src/contrib/far_0.6-5.tar.gz
Tell the R program when to look for user installed packages
mkdir $HOME/rpackages export R_LIBS=$HOME/rpackages:$R_LIBS
And install it
R CMD INSTALL -l $HOME/rpackages far_0.6-5.tar.gz
That is nearly all. The package is installed now in the directory 'rpackages' in your home directory. We advise to install all your R packages in this directory. Note that you'll also need to set the R_LIBS
environment variable in your batch jobs.
NOTE: sometimes a package depends on another package. During installation, you will get a message like:
ERROR: dependencies 'yyyyyy' are not available for package 'xxxxxx'
In this case, install package 'yyyyyy' first.
Command line parameters in R
It is possible to call an R program on the command line with arguments for the R program.
Example:
file: test.r argv = commandArgs(trailingOnly=TRUE) cat("Number of arguments: ",length(argv),"\n") cat("Argument number 2: ",argv[2],"\n")
call this script with the example command line arguments:
Rscript --no-save --slave test.r one two 123 # or R --no-save --slave --args one two 123 < test.r # or R CMD BATCH --no-save --slave '--args one two 123' test.r outputfile
- --no-save : do not save the workspace
- --slave : run as quiet as possible (no welcome screen etc.)
The output:
Number of arguments: 3 Argument number 2: two
Notes:
- 1st example: output goes to standard output
- 2nd example: the arguments for the R script are directly after the --args flag. The output goes to standard output.
- 3rd example: the output goes to the file 'outputfile'. If the name of the output file is ommitted, the output goes to 'test.r.Rout'.
NOTE: the arguments are available as strings. You can convert to number as follows:
#convert third argument to number: x = as.numeric(argv[3])