R is a system for statistical computation and graphics. It consists of a language plus a run-time environment with graphics, a debugger, access to certain system functions, and the ability to run programs stored in script files. Some of R’s main features include:
Once the virtual environment is created, it can be launched at any time by ensuring that the python3 module is loaded, using the command
module load python3/anaconda/5.2.0 conda create -n r-environment r-essentials r-base source activate r-environment export R_LIBS_USER=/home/$USER/.conda/envs/r-environment/lib/R/library/
and then launching the environment by using
module load python3/anaconda/5.2.0
Next, you can install any packages you need inside this environment.
These packages will only be available within this environment.
Packages can be installed with the install.packages() function in R.
For example, to load the ggplot2 package, which is an R system for creating graphics, use the command
source activate r-environment
To exit the R virtual environment, use the command
2. Create a R script. This repository provides a simple script, test.r, which demonstrates some of R's basic features.
3. Prepare the submission script, which is the script that is submitted to the Slurm scheduler as a job in order to run the R script. This repository provides the script job.sh as an example.
print("Starting tests.") x <- 1:10 # initializes x as values from 1 to 10 print(x) # print x y <- sample(1:100, 10, replace=T) # generate 10 random numbers from 1 to 100 print(y) # print y mean(x) # find mean of x print(x*y) # print product of x and y a <- c(2, 4, 6, 8, 10, 12) # a is a vector b <- a[a>4] # b is the vector of all indices in a greater than 4 print(a) print(b)
#!/bin/sh #SBATCH --job-name=r_test #SBATCH -o r_out%j.out #SBATCH -e r_err%j.err #SBATCH -N 1 #SBATCH --tasks-per-node=1 echo -e '\n submitted R job' echo 'hostname' hostname # loads python module module load python3/anaconda/5.2.0 # activates R virtual environment source activate r-environment # runs R program R < test.r --no-save # exit the virtual environment source deactivate
4. Submit the job using:
5. Examine the results.