==== R ==== * Home page: [[https://www.r-project.org|The R Project for Statistical Computing]] * Licenza: GPL Several versions of R are available: ^ R ^ | 3.4.4 | | 3.5.2 | | 3.5.3 | | 3.6.3 | | 4.0.5 | | 4.1.2 | Compilation details: ^ R ^ Compiler ^ BLAS ^ | 3.4.4 | GNU 5.4.0 | OpenBLAS 0.2.20 | | 3.5.2 | GNU 5.4.0 | OpenBLAS 0.2.20 | | 3.5.3 | GNU 5.4.0 | OpenBLAS 0.2.20 | | 3.6.3 | GNU 5.4.0 | OpenBLAS 0.2.20 | | 4.0.5 | GNU 5.4.0 | OpenBLAS 0.2.20 | | 4.1.2 | GNU 5.4.0 | OpenBLAS 0.2.20 | | 3.4.4 | GNU 7.3.0 | OpenBLAS 0.2.20 | | 3.5.2 | GNU 7.3.0 | OpenBLAS 0.2.20 | | 3.5.3 | GNU 7.3.0 | OpenBLAS 0.2.20 | | 3.6.3 | GNU 7.3.0 | OpenBLAS 0.2.20 | | 4.0.5 | GNU 7.3.0 | OpenBLAS 0.2.20 | | 4.1.2 | GNU 7.3.0 | OpenBLAS 0.2.20 | | 3.4.4 | GNU 8.3.0 | OpenBLAS 0.3.7 | | 3.5.2 | GNU 8.3.0 | OpenBLAS 0.3.7 | | 3.5.3 | GNU 8.3.0 | OpenBLAS 0.3.7 | | 3.6.3 | GNU 8.3.0 | OpenBLAS 0.3.7 | | 4.0.5 | GNU 8.3.0 | OpenBLAS 0.3.7 | | 4.1.2 | GNU 8.3.0 | OpenBLAS 0.3.7 | For example the three versions of R 4.1.2 have been compiled with: * GNU 5.4.0 tool chain and OpenBLAS 0.2.20 * GNU 7.3.0 tool chain and OpenBLAS 0.2.20 * GNU 8.3.0 tool chain and OpenBLAS 0.3.7 Environment modules: ^ R ^ Prerequisites ^ Module ^ | 3.4.4 | gnu/5.4.0 | R/3.4.4 | | 3.5.2 | gnu/5.4.0 | R/3.5.2 | | 3.5.3 | gnu/5.4.0 | R/3.5.3 | | 3.6.3 | gnu/5.4.0 | R/3.6.3 | | 4.0.5 | gnu/5.4.0 | R/4.0.5 | | 4.1.2 | gnu/5.4.0 | R/4.1.2 | | 3.4.4 | gnu7/7.3.0 | R/3.4.4 | | 3.5.2 | gnu7/7.3.0 | R/3.5.2 | | 3.5.3 | gnu7/7.3.0 | R/3.5.3 | | 3.6.3 | gnu7/7.3.0 | R/3.6.3 | | 4.0.5 | gnu7/7.3.0 | R/4.0.5 | | 4.1.2 | gnu7/7.3.0 | R/4.1.2 | | 3.4.4 | gnu8/8.3.0 | R/3.4.4 | | 3.5.2 | gnu8/8.3.0 | R/3.5.2 | | 3.5.3 | gnu8/8.3.0 | R/3.5.3 | | 3.6.3 | gnu8/8.3.0 | R/3.6.3 | | 4.0.5 | gnu8/8.3.0 | R/4.0.5 | | 4.1.2 | gnu8/8.3.0 | R/4.1.2 | === R_LIBS_USER environment variable === The R module defines the environment variable R_LIBS_USER with the default value $HOME/local/libraries/R/. So if you intend to install additional R packages, you have to create the directory where the libraries will be installed: ''mkdir -p "$R_LIBS_USER"'' As you can see the value of ''R_LIBS_USER'' does not include the patch level of the software. This means, for example, that the packages installed in ''$HOME/local/libraries/R/4.1'' will be suitable for all versions of R 4.1.x series. === R packages === == Installation of R packages == In this example we will see how to install two R packages. Script ''install-packages.R'': install.packages("parallel", repos="http://cran.mirror.garr.it/mirrors/CRAN") install.packages("MASS" , repos="http://cran.mirror.garr.it/mirrors/CRAN") Script ''install-packages.sh'': #!/bin/bash module load gnu8/8.3.0 module load R/4.1.2 mkdir -p "$R_LIBS_USER" R CMD BATCH install-packages.R rm -f install-packages.Rout Executing ''install-packages.sh'': bash install-packages.sh === R serial job === == Execution of an R serial program == In this example we will see how to submit a serial job. R script ''hello.R'': #!/usr/bin/env Rscript sayHello <- function(){ print('hello') } sayHello() Script ''slurm-R-vrt.sh'': #!/bin/bash #SBATCH --job-name=hello #SBATCH --output=%x.o%j #SBATCH --error=%x.e%j #SBATCH --nodes=1 #SBATCH --ntasks-per-node=1 #SBATCH --mem=512M #SBATCH --partition=vrt #SBATCH --time=0-00:05:00 ##SBATCH --account= module load gnu8/8.3.0 module load R/4.1.2 Rscript --no-save hello.R Submitting ''slurm-R-vrt.sh'': sbatch slurm-R-vrt.sh === R parallel job === == Execution of an R parallel program == In this example we will see how to submit a parallel job on a single node. R script ''loop.R'': #!/usr/bin/env Rscript library(parallel) library(MASS) args = commandArgs(trailingOnly=TRUE) if (length(args)==0) { args[1] = 1 } numCores <- args[1] x <- iris[which(iris[,5] != "setosa"), c(1,5)] trials <- seq(1, 10000) boot_fx <- function(trial) { ind <- sample(100, 100, replace=TRUE) result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit)) r <- coefficients(result1) res <- rbind(data.frame(), r) } system.time({ results <- mclapply(trials, boot_fx, mc.cores = numCores) }) Script ''slurm-R-cpu.sh'': #!/bin/bash #SBATCH --job-name=loop #SBATCH --output=%x.o%j #SBATCH --error=%x.e%j #SBATCH --nodes=1 #SBATCH --ntasks-per-node=4 #SBATCH --mem=512M #SBATCH --partition=cpu #SBATCH --time=0-00:05:00 ##SBATCH --account= module load gnu8/8.3.0 module load R/4.1.2 Rscript --no-save loop.R ${SLURM_NTASKS_PER_NODE:-1} Submitting ''slurm-R-cpu.sh'': sbatch slurm-R-cpu.sh