Using renv to manage R environment for reproducible coding

r
renv
Published

Tuesday, August 8, 2023

Modified

Friday, September 8, 2023

R works by defaultly by installing packages to a central library and shares them between the projects. It sounds like a good and time-saving feature. After all, you don’t need to install the same package in every project. But that’s where the problems arise. You might have a newer version of some package than your coworkers – resulting in a deprecated or not-implemented functionality.

Install renv

pacman::p_load(renv)

renv create separate, reproducible environment that you and your coworkers can use, hassle free

This nice post introduced how to use it to manage dependencies in R projects easily

Remove renv

  1. Deactivate renv in a project
renv::deactivate()
  1. Remove auto loader .Rprofile, but doesn’t touch any other renv files used in the project.
  2. To completely remove renv from a project, delete the project’s renv folder and renv.lock lockfile as desired.
  3. If you want to completely remove any installed renv infrastructure components from your entire system
root <- renv::paths$root()
unlink(root, recursive = TRUE)
### Remove packages
utils::remove.packages("renv")

Reference

Back to top