How renv works: The core workflow
mainThe renv workflow revolves around managing a project library and a lockfile (renv.lock).
- Initialize: Use
renv::init()to create a private project library and a.Rprofilethat ensures this library is used whenever the project is opened. - Manage Packages: Install or upgrade packages using standard R functions like
install.packages()andupdate.packages(), orrenvspecific functions likerenv::install()andrenv::update(). - Record State: Use
renv::snapshot()to update therenv.lockfile with the exact package versions and sources currently installed in your project library. - Restore State: Use
renv::restore()to install the specific package versions recorded in therenv.lockfile into a project library. This is used when moving to a new machine or sharing code with collaborators. - Verify: Use
renv::status()to compare the current state of the project library against the metadata in the lockfile.
# Typical workflow sequence
renv::init()
renv::install("somepackage")
renv::snapshot()
# On another machine:
renv::restore()