| 1 |
--- |
| 2 |
title: "packrat vs. renv" |
| 3 |
output: rmarkdown::html_vignette |
| 4 |
vignette: > |
| 5 |
%\VignetteIndexEntry{packrat vs. renv} |
| 6 |
%\VignetteEngine{knitr::rmarkdown} |
| 7 |
%\VignetteEncoding{UTF-8} |
| 8 |
--- |
| 9 |
|
| 10 |
```{r, include=FALSE} |
| 11 |
knitr::opts_chunk$set( |
| 12 |
collapse = TRUE, |
| 13 |
comment = "#>", |
| 14 |
eval = FALSE |
| 15 |
) |
| 16 |
``` |
| 17 |
|
| 18 |
```{r setup} |
| 19 |
library(renv) |
| 20 |
``` |
| 21 |
|
| 22 |
Our first attempt at solving the problem of reproducible environments was [packrat](https://rstudio.github.io/packrat/). |
| 23 |
While we learned a lot from packrat, it ultimately proved challenging to use in ways that were difficult to fix. |
| 24 |
This led us to create renv, a system with fewer surprises and better defaults. |
| 25 |
If you're an existing packrat user, you can call `renv::migrate()` to switch renv, then read on to learn about the main differences: |
| 26 |
|
| 27 |
1. The renv lockfile `renv.lock` is formatted as [JSON](https://www.json.org/). |
| 28 |
This should make the lockfile easier to use and consume with other tools. |
| 29 |
|
| 30 |
2. renv no longer attempts to explicitly download and track R package source tarballs within your project. |
| 31 |
This was a frustrating default that operated under the assumption that you might later want to be able to restore a project's private library without access to a CRAN repository. |
| 32 |
In practice, this is almost never the case, and the time spent downloading + storing the package sources seemed to outweigh the potential reproducibility benefits. |
| 33 |
|
| 34 |
3. Packrat tried to maintain the distinction between so-called *stale* packages; that is, R packages which were installed by Packrat but were not recorded in the lockfile for some reason. |
| 35 |
This distinction was (1) overall not useful, and (2) confusing. |
| 36 |
renv no longer makes this distinction: `snapshot()` saves the state of your project library to `renv.lock`, `restore()` loads the state of your project library from `renv.lock`, and that's all. |
| 37 |
|
| 38 |
4. In renv, the global package cache is enabled by default. |
| 39 |
This should reduce overall disk-space usage as packages can effectively be shared across each project using renv. |
| 40 |
|
| 41 |
5. renv's dependency discovery machinery is more configurable. |
| 42 |
The function `renv::dependencies()` is exported, and users can create `.renvignore` files to instruct renv to ignore specific files and folders in their projects. |
| 43 |
(See `?renv::dependencies` for more information.) |