Choosing R Library Installation Locations
When you load an R module on the MSI system, a base set of R libraries will be available to you from the MSI R module. However, you will likely need to install your own R libraries to accomplish your work. By default, MSI R modules will ask your permission to install libraries in your user home directory. We recommend installing your R libraries for a project into a directory within that MSI project space rather than your MSI user home directory for the following reasons. First, maintaining your R libraries in a directory within a shared project space means that you can share those libraries with other members of your project team if desired. Second, you will be able to control your R library versions for that specific project. Using your user home directory for R libraries across multiple projects may lead to unintentional software updates and conflicts. Lastly, you have more storage available to you in a project space than in your private user home directory. Please note that R libraries are specific to the module version you have loaded on an MSI system; the default version of R (i.e. what’s loaded with “module load R”) can and will change. It is best practice to always specify which version of R you are loading with “module load” so that you can ensure proper version control of your libraries.
Installing R libraries
R libraries (also known as packages) can be installed either using command line R or from within an RStudio interactive job in Open On Demand (OOD). For challenging library installations, we recommend using command line R rather than Rstudio; see the section “Troubleshooting challenging R library installations” for more details. For a particular project, you should use the same version of R for your work with command line R and Rstudio. When installing R libraries via command line R, you should request an interactive compute job first and then install your packages inside the compute job to avoid CPU timeouts. Example steps for installing R libraries via the command line are given below:
- Request an interactive job. See “Interactive Computing with srun” for more details.
srun -n 10 --mem 16G -t 1:00:00 -p interactive --pty bash
- Module load the version of R that you will be using for your project
- Make a new directory for your R libraries.
mkdir $SHARED/MyRlibs_$USER
- Start R
R
- From within R set your .libPaths() to your local installation for your project
.libPaths($SHARED/MyRlibs_$USER)
- Install your package(s) from within R
Example 1: CRAN package
install.packages(“ggplot2”)
Example 2: Bioconductor package
install.packages(“BiocManager)BiocManager::install(“GenomicRanges”)
7. Load your library, using the library() function:
library(“ggplot2”)
Troubleshooting Challenging R Package Installations
Installation of some R packages may require loading system modules. These will need to be loaded when you install your R packages and whenever you want to use your R packages. For interactive OOD RStudio sessions you can include module loads in the custom environment option box.
Common Warning Messages and Issues
You may see a warning (not an error) that a system folder located in “/common/software/” is not writable. This is expected behavior - it means you have not defined a user library you have permissions to modify. You can either follow the previous steps to do so, or follow the prompts provided by this warning (e.g. by typing “yes” in the below example and at the subsequent prompt) to automatically create one in a standard location.
Another common warning you may encounter comes from attempting to install a package not located on CRAN, the default R package repository indexed by the install.packages() function. Despite the message stating this package is unavailable for this version of R, it may be that it needs to be pulled and installed from a different location. Package documentation should tell you if packages need to be installed via Bioconductor or directly from a GitHub repository (see previous instructions).