Skip to content

Self-service R package installation

With the Research Environment, you can create and maintain your own R package libraries. There are also many commonly used R packages pre-installed in centralised locations on the RE.

Creating your own libraries

We suggest creating an Rpackages folder within your working directory, either in your personal space or shared between you and your collaborators.

To do this, follow these steps:

  1. Set up a personal R package library location using bash (this step can be done using file explorer)

    cd /path/to/personal_folder
    mkdir Rpackages
    
  2. Install and load packages from CRAN, BioConductor, and GitHub in R

    #CRAN
    install.packages("ggplot2", lib="/path/to/personal_folder/Rpackages")
    library("ggplot2", lib.loc="/path/to/personal_folder/Rpackages")
    
    #BioConductor
    install.packages("BiocManager", lib="/path/to/personal_folder/Rpackages")
    library(BiocManager, lib.loc="/path/to/personal_folder/Rpackages")
    BiocManager::install("GenomicFeatures", lib="/path/to/personal_folder/Rpackages")
    library(GenomicFeatures, lib.loc="/path/to/personal_folder/Rpackages")
    
    #devtools
    install.packages("devtools", lib="/path/to/personal_folder/Rpackages")
    library(devtools, lib.loc="/path/to/personal_folder/Rpackages")
    devtools::install_github("Displayr/flipTransformations", lib="/path/to/personal_folder/Rpackages")
    library("flipTransformations", lib.loc="/path/to/personal_folder/Rpackages")
    
  3. Mount library locations to .libPaths() and load packages without specifying lib.loc

    Please note: it may take ~5 minutes before these packages become visible after the library paths have been mounted to .libPaths().

    .libPaths(c( .libPaths(), "/path/to/personal_folder/Rpackages"))
    library(tidyverse)
    

    The following code may be run before and after the above commands to check this step has been successful:

    table(as.data.frame(installed.packages())$LibPath)
    print(table)
    

Using pre-installed packages

Pre-installed R packages can be found at:

  • /tools/aws-workspace-apps/ce/R/4.0.2
  • /tools/aws-workspace-apps/ce/R/4.2.1

The best practice for using "Community" packages is to add these folder locations to .libPaths in your R session. For example

Please note: it may take ~5 minutes before these packages become visible after the library paths have been mounted to .libPaths().

.libPaths(c( .libPaths(), "/tools/aws-workspace-apps/ce/R/4.0.2"))
library(tidyverse)

The following code may be run before and after the above commands to check this step has been successful:

table(as.data.frame(installed.packages())$LibPath)
print(table)

Request packages

If you encounter an error when trying to install an R package, please feel free to raise a ticket through the Service Desk portal. In your ticket, please include the following:

  • Version of R being used
  • Name of the package causing the error
  • Command being used
  • Relevant error messages or a screenshot of the observed behaviour

Last update: November 17, 2023