R packages

The Sandbox IVM contains only base and recommended R packages that are distributed with the R software. Users need to install additional packages they require by following the instructions below.

FinnGen register data can be accessed in BigQuery using both R and Python. See also Getting started with R.

How to install new R packages

You can install packages to your Sandbox IVM from a CRAN server installed within the Sandbox environment. It is not connected to the public internet and only contains packages added there by the Sandbox administrators. Your sandbox IVM has been pre-configured to access this CRAN server when you install packages.

You can ask for new packages to be added to the CRAN server by contacting the FinnGen Service Desk.

Package Installation with the R installed in Sandbox

You can install a new package using the following R command (in this example we install the ggplot2 package):

install.packages("ggplot2")

Special Case: Packages with Pre-downloaded binary dependencies

Some packages require specific handling due to pre-downloaded binary libraries. For example, to install the arrow package which is a dependency of the FinnGenUtilsR package, you must first use the pre-downloaded libarrow binary. Follow these steps to install arrow and FinnGenUtilsR packages:

Sys.setenv("ARROW_DOWNLOADED_BINARIES" = "/usr/finngen-repos/cran/source/src/contrib/arrow-16.1.0.zip")

install.packages("arrow")

install.packages("FinnGenUtilsR")

Packages are installed in the default location that depends on the R version (e.g. /home/ivm/Rx86_64-pc-linux-gnu-library/4.3). Installed packages are automatically found only from this location. Please use the .libPaths() variable to access R packages installed for one R version from a different R version. More information is available from here.

Package Installation with the R Lmod modules in Sandbox

When working with R Lmod modules, additional steps are necessary. Here's how to install packages using R Lmod modules (e.g., r-ver/4.2.3):

  1. Load R Module:

module load r-ver/4.2.3

  1. Set SINGULARITY_COMMAND_OPTS:

export SINGULARITY_COMMAND_OPTS="-B /usr/finngen-repos/cran"

  1. Run the following R commands to set the library path and install the package:

.libPaths("/home/ivm/R/x86_64-pc-linux-gnu-library/4.2")

install.packages("ggplot2")

Listing Installed R packages

You can list the installed R packages using the following R command:

library()$results[,1]

To find if a specific R package has been installed please use the following R command (in this example we search for the ggplot2 package):

my_packages <- library()$results[,1]
"ggplot2" %in% tolower(my_packages)

If the package has been installed, the command returns:

[1] TRUE

Create reproducible environments with renv

[Renv](https://rstudio.github.io/renv/index.html) is an R package that helps to keep a project reproducible. It creates an isolated environment where to install and track packages and their version. This way, a project can be reproduced across different machines and time .

Renv works in Sandbox in the same way that it does in your laptop (see [renv](https://rstudio.github.io/renv/index.html) for reference). The only difference is that it has only access to the packages and versions listed in the CRAN server installed within the Sandbox environment.

List of available packages and versions can be found in /usr/finngen-repos/cran/source/src/contrib/

Last updated