Project Environments - Introduction
The main tool for project environment handling in R is the package {renv}.
If you are not familiar with the {renv} approach the introductory package vignette “Introduction to renv” is a good starting point. While the use of Package Manager snapshots within Workbench instances (see article Package Manager snapshots) configured by cynkra mitigates version management issue substantially, we highly recommend the use of {renv}
for every project.
{renv}
allows full control of a project’s R (package) environment. This makes a project reproducible and allows collaborators to get started easily as they only need to call renv::restore()
to install all required dependencies. In addition, thanks to the shared {renv}
cache (see section below), package installation is almost instant on Workbench instances as packages get symlinked instead of downloaded and reinstalled.
Furthermore the use of {renv}
makes it easier for Connect to install dependencies and reduces the risk of running into incompatibility during publication.
{renv} Helpers in {cynkrathis}
The {cynkrathis} package has some {renv} related helper functions to make {renv} project management easier. For example, cynkrathis::renv_switch_r_version()
allows for a simplified R version upgrade of an {renv}
project which is coupled to an Package Manager snapshot. Assuming you want to bump an {renv}
project running on R 4.1.3 to R 4.2.1, you can call renv_switch_r_version("4.2.1")
and the function will replace the “repos” definition in renv.lock
with the corresponding Package Manager snapshot of the respective R version.
Footnotes
By default,
{renv}
places its cache on the user-level, i.e., at~/.local/
which means that each user would only profit from their own cache.↩︎