Skip to content

R (Programming Language)

Important Security Notice: Upgrade to R Version 4.4.0

A critical security vulnerability (CVE-2024-27322) has been identified in R versions prior to 4.4.0, which poses a risk of allowing malicious arbitrary code execution through deserialization of untrusted data. It is recommended to use the latest release, v4.4.0, which includes crucial security patches.

Learn More »

Overview

R (more info) is a popular programming language used for statistical computing and visualizing data. We've seen its use increase in projects relating to data science and bioinformatics.

Looking for RStudio?

Instead of using the command line for running R commands, you also can use our online version of RStudio Server, which is similar to what you might run on your desktop. This software is still under preview mode and is looking for feedback.

Learn More »

Availability

Cluster Module/Version
BOSE R/4.0.4
R/4.0.5
R/4.2.1
R/4.3.1
R/4.4.0
BGSC R/3.4.4
R/3.6.3
R/4.0.2
R/4.4.0

Note: You can simply use "module load R" to activate the most recently installed version of this software.

Installing Packages

Interactive Mode vs Script Files

R is primarily used in two ways: interactively (manually typing each command) and through running scripts (running all commands together).

Interactive Mode

If you want to run R commands manually and see each of their results, you'd use the R command directly, then type each command you want to run.

Start R
sinteract           # Start an interactive session on the cluster
module load R       # Load the R module
R                   # Start the R program
Run R Commands (in R)
> 1+1
[1] 2

> text <- "Hello"
> paste(text, "World")
[1] "Hello World"

> q()
Quit Interactive Mode
exit

Scripts Mode

Rather than typing each R command individually, you can use the Rscript command to run a list of multiple R commands in a file. This is especially useful when using sbatch in Slurm to submit your work to a compute node for long-running calculations.

my-script.R
1+1

text <- "Hello"
paste(text, "World")
Run Script
sinteract       # Start an interactive session on the cluster (if not using 'sbatch')
module load R   # Load the R module
Rscript my-script.R     # Run R script
Output
[1] 2
[1] "Hello World"
Quit Interactive Mode
exit           # If you used 'sinteract' above

Sample Slurm Script

submit.sh
#!/bin/bash
# -- SLURM SETTINGS -- #
# [..] other settings here [..]

# The following settings are for the overall request to Slurm
#SBATCH --ntasks-per-node=32     # How many CPU cores do you want to request
#SBATCH --nodes=1                # How many nodes do you want to request

# -- SCRIPT COMMANDS -- #

# Load the needed modules
module load R   # Load R
Rscript my-script.R
Submit Job
sbatch submit.sh

Real Example

Has your research group used R in a project? Contact the HPC Team and we'd be glad to feature your work.

Resources