This R project template uses the renv for setting up a reproducible DataSHIELD client side R environment. This allows to use the appropriate DataSHIELD client R packages, matching the selected server-side DataSHIELD profiles.
The project's R environment includes the following R packages (and their dependencies):
- DSOpal to connect with OBiBa Opal nodes
- DSMolgenisArmadillo to connect with Molgenis Armadillo nodes
- DSLite to connect with a pure R local node
- dsBaseClient to use the base DataSHIELD functions
Start by creating your project source code repository from this template: see instructions in Creating a repository from a template. You could also just download this folder, but it is a good practice to have source code in a version control system (Git).
Read the Introduction to renv vignette to learn the basics of R environment management.
- Open this project in Rstudio by selecting the
project.Rproj
file. - If reported by renv in the R console, run the
renv::restore()
to install the R packages in their specific version (i.e. as described by therenv.lock
file).
Use libPaths()
to locate where the R packages are installed.
- Install the R package using
install.packages()
or using renv::install() which allows to manage R packages installed from an archived version, a GitHub repository, Bioconductor repository or a local package folder - Load the R package in one of your R source code with
library()
(see R/script.R as an example) - Run
renv::snapshot()
to register this package as part of your project environment
- Edit your R source code and remove the
library()
load statements of the R package to remove - Run
renv::snapshot()
to unregister this package from your project environment
Different R environments means different package dependencies, and also potentially different R/DataSHIELD analysis code. In order to maintain/develop different environments in parallel, you can use the Git branches. Upgrading to new versions of dependencies will be facilitated. To make a new branch:
- Select Git tab and New Branch in Rstudio, or command line
git checkout -b branchName
- Install/update R packages
- Update analysis R script to connect to the appropriate DataSHIELD server profiles and to fix any breaking changes
- Run
renv::snapshot()
- Commit changes in Git using Rstudio or command line
See also the vignette Collaborating with renv.