R
At the HPC R can be used in the command line with batch scripts submitted via slurm or via a web GUI, RStudio, through Open Ondemand.
Modules
One version of R is installed for every year. These are accessible through environment modules. Thus in order to access a specific version of R one must first load the year module, followed by the available R version for that year.
Additionally, extension bundle modules for R are also present.These modules contain a list of the installed extensions in their module files and are thus searcheable
Searching for extensions
In order to search for a particular extension, use the module key command
module key [extensionName]
For instance, when searching for the terra extension,
module load 2023 module key terra
The following output is then printed
----------------------------------------------------------------------------------------------------------- The following modules match your search criteria: "terra" ----------------------------------------------------------------------------------------------------------- R-bundle-CRAN: R-bundle-CRAN/2023.12-foss-2023a Bundle of R packages from CRAN -----------------------------------------------------------------------------------------------------------
This indicated that the terra extension is contained in the R-bundle-CRAN/2023.12-foss-2023a module. This bundle loads the corresponding R version for that year and adds extensions to it.
Installing your own R extensions
Submitting Slurm jobs
Slurm job script use bash as an interpreter (note the #!/bin/bash on the first line), so it cannot execute R code. Its job is to allocate resources in the cluster, load modules and execute any other bash command you need in your job.
Thus in order to launch an R job via slurm, one needs to have two scripts: an R script and a slurm (bash) script.
Here is an example of a very simple R script that will list all installed extensions.
#!/usr/bin/env Rscript installed.packages()[,1]
Let's call this script list_ext.r and let's place in ~/myRScripts. Note that the first line is used to point to the R interpreter, Rscript. In order to access it, the R (or R-bundle) module must have been loaded beforehand. This is done in the sbatch script.
Important: Make sure that the R script, in this example list_ext.r, is executable.
#!/bin/bash #SBATCH --comment="List R extensions" #SBATCH --time=0-0:10:00 # 10 minutes #SBATCH --mem=1G #SBATCH --ntasks=1 #SBATCH --output=output_%j.txt #SBATCH --error=error_output_%j.txt #SBATCH --job-name= module load 2023 module load R-bundle-CRAN/2023.12-foss-2023a #execute the R-script ~/myRScripts/list_ext.r
Since this is just an illustrative job, we have only allocated 1 GB of RAM and a single CPU.
- RStudio in Open OnDemand