Skip to content

R#

R is a free programming language and software environment specially designed for statistics.

R at NHPCC#

We have installed different versions of R. The default version can be loaded and run simply. Just type in your terminal:

ml R

and then:

R

which will open its interactive session.

R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

>

Don't forget to request an interactive job for time consuming jobs or if you need more computation resources.

Using R in batch scripts#

#!/usr/bin/bash
#SBATCH --time=00:10:00
#SBATCH --mem=10G

# load the module
ml R

# run R code
# Function to compute the area of a circle
circle_area <- function(radius) {
  area <- pi * radius^2
  return(area)
}

# Example usage
radius <- 5
area <- circle_area(radius)
print(paste("The area of the circle with radius", radius, "is", area))

Working with Rstudio#

Installing R packages#