Skip to content

R

R is a language and environment for statistical computing and graphics.

Installed Versions

The following versions of R are available on Picotte:

  • 4.1.3
  • 4.2.2
  • 4.3.1
  • 4.5.0

To use R, choose a version and load the corresponding module:

module load R/4.5.0

Interactive R

R Studio is not available on Picotte. As an alternative, JupyterLab can be used with an R kernel.

See also: R in Jupyter

Installing packages

You may install third-party R packages privately into your home directory. From the R prompt, type:

install.packages("package_name")

When prompted to create a personal library, type yes and press enter. For more details on package installation, see the official R documentation.

Configuring a default repository

To avoid being asked for a CRAN repository location every time, add the following to ~/.Rprofile:

## Default repo - cloud.r-project.org will get a server near you
local({r <- getOption("repos")
       r["CRAN"] <- "https://cloud.r-project.org"
       options(repos=r)
})

Example Job

Create new file called testjob.R with the following content:

### Name this file: testjob.R
print(sample(1:3))
print(sample(1:3, size=3, replace=FALSE))  # same as previous line
print(sample(c(2,5,3), size=4, replace=TRUE))
print(sample(1:2, size=10, prob=c(1,3), replace=TRUE))

Create new file called test_r.sh with the following content:

#!/bin/bash
#SBATCH -p def
#SBATCH -n 1
#SBATCH --cpus-per-task=8
#SBATCH --mem=64G
#SBATCH --time=2:00:00

### THIS IS FOR PICOTTE

module load R/4.5.0

R CMD BATCH testjob.R

Submit the job by running:

sbatch test_r.sh

See Also