R Virtual Environments#
renv
Basics#
The renv
package helps create reproducible
environments for R projects.
There are a few core commands when using renv
.
renv::init()
: Initialize new project-local environment with a private R
library
renv::snapshot()
: Save the current state of the project library
renv::restore()
: Restore the previously saved state of the project library,
e.g. reloading the environment on another machine
GitHub and renv
Demo#
Create new Git repository on GitHub
Clone the new repository on the cluster
Create new RStudio project in RStudio via the Portal
Install
renv
if needed viainstall.packages("renv")
Create clean package environment via
renv::init()
Quit and restart your R session.
Install custom packages, e.g.
renv::install("rstan")
Create environment snapshot via
renv::snapshot(packages="mcmc")
Commit and push changes to the Git repository