R

R is a programming language that is tailored towards Statistical computing. For more information, you can find out more here: https://www.r-project.org/

If you are looking for ISU's mirror link for browsing packages, you can find it here: https://mirror.las.iastate.edu/CRAN/

Table of Contents

Getting Started

The following guide is meant to be run on a compute node, not the head node.  Please see: Slurm for information on how to request a compute node.  Likewise, one can use Open OnDemand to start an RStudio instance on a compute node.

Transferring Your R Scripts to Nova

There are several utilities that can be used to transfer scripts to and from the cluster.  Please see: Transferring Files for a detailed list of options and a brief explanation on how to use them.

Viewing Available R Versions

Nova has several versions of R available.  One can view the available versions by the following command:
module spider r

Loading an R module

To load the default R module simply issue the command:
module load r

Otherwise to specify a specific version of R:

module load r/4.4.3-py311-xspgsan

Installing Packages

By default, R installs in your /home directory which is not ideal since it only has a 10GB quota.  You should switch it to use either /work or /lustre.  This can be done by setting the R_LIBS_USERenvironmental variable.  For example:
export R_LIBS_USER=/lustre/hdd/LAS/pinetid-lab/your_netid/R/library

This can be added to your .bashrc to avoid having to issue it every time you start R. 

Once the module is loaded, an interactive R session can be started by invoking

R

Please note that packages installed using one R module may not work with other R modules. Please be sure to use the same R module every time you install packages.

Once an interactive session is running (or an RStudio session) the command to install packages is:
install.packages('<somepackage>')

For more detailed and extensive documentation, please visit the following links: install.packages

Note:  You may be asked to select a CRAN mirror, it is recommended to use the Iowa mirror.

Installing Packages from Github

To install packages from Github, you will need to install the remotes library.

install.packages("remotes")

Then to install from Github issue:
remotes::install_github("GithubUser/RepositoryName")

Installing Packages in a Script

To install packages in a script, you will need to specify both the location to save them and the repository to use.  The following is an example installing RColorBrewer

install.packages("RColorBrewer", lib="/work/LAS/your-lab/yournetid/Rlibs", repos="https://mirror.las.iastate.edu/CRAN")

Installing Packages with BioConductor

You will need to install BiocManagerin order to install from BioConductor's repositories.  

install.packages("BiocManager")

Then packages can be installed like this:

BiocManager::install(version="3.22")
BiocManager::install('<somepackage>')

For more information please see: BioConductor Install

Loading Modules Inside of RStudio

Often when installing packages some modules will need to be loaded.  If using an interactive R session then the standard module commands will work.  If using RStudio some additional steps are needed to load modules.  First:
source("/usr/share/lmod/lmod/init/R")

Then modules will be available to be loaded like this:
module("load <some_module>")

Common Problems

Pre-packaged R modules

Some R libraries with complicated requirements are pre-packaged on Nova. These packages are tied to specific R versions.

To see if an R package you need already exists on Nova you can run:

module purge
module avail

This will list all the available packages. You can navigate through the list to see which R packages are available. (You can go down the list by pressing the spacebar or 'D' key)

Alternatively, you can run module spider <package_name> to search for a specific package.

Avoid Using Different R Modules

Using 'module spider' as discussed above, you may notice there are multiple modules available for some R versions. For example, at the time of this write up the following modules exist for R 4.*:

        r/4.1.3
        r/4.2.2-py310-ly4mhww
        r/4.3.2-py311-f4gswux
        r/4.4.0-py311-jwce5sj
        r/4.4.1-py311-6qu6scb
        r/4.4.3-py311-xspgsan

If you use one install.packages to install modules in your R library, using any of these, those packages will be installed into the same folder in your R library, and will work under that R module. However, if you later load a different R module, those packages you installed might not work when you try to use this with this R module. This happens frequently for packages with compiled C extensions. We recommend you use the load same R module each time you install packages and in all of your scripts.