renv - the best bit

Because RStudio just won’t stop improving the world for all of us R users, they have recently released a massive upgrade over {packrat}: {renv}.

The basic idea is that you can keep a package library separately for each R project you work on, pinning down the exact package versions you used for each project. This is obviously great for reproducibility of results, but also just for ensuring that R code which works now will continue to work in the future.

On the other hand I do feel like reproducibility of one-off projects is a bit overrated outside of scientific research. CRAN is a tightly curated repository, the authors of big packages tend to be very mindful of deprecating old interfaces gently rather than suddenly, and in practice the need to run old code again does not arise very often.

So for smaller projects I now use renv in a minimal fashion. Just do:

renv::snapshot()

renv will then scan your working directory for dependencies, and output all relevant information on package versions into a lock file in JSON format. Commit this together with your code and if you ever need to reproduce, you will be able to do so relatively easily using renv.

Peace of mind, without having to spend effort on reproducibility up-front 🙏