You
should
use
renv.

(probably.)

agenda

why

how

why

we have a standards problem

what makes a project an R project?

what is a project?

an individual or collaborative enterprise that is carefully planned to achieve a particular aim.

– Oxford Languages

what is a project?

a project ships.

I thought this guy works at RStudio

ceci n’est pas un projet

*.Rproj

*.Rproj

Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

You don’t ship your editor.

🙈 I have shipped my editor.



*.Rproj

necessary (if you use RStudio)
but not sufficient

what is a project?

12factor.net

A twelve-factor app never relies on implicit existence of system-wide packages.

It declares all dependencies, completely and exactly, via a dependency declaration manifest.

It uses a dependency isolation tool […] to ensure that no implicit dependencies “leak in”

leak-in

leak-in

install_github("tidyverse/dtplyr")

install_github("tidyverse/dtplyr")

panic, a haiku

when do you think you
want to discover that you’ve
broken your dashboard?

how

isolate.

install.packages("renv")

renv::init()

or,

.libPaths()

> .libPaths()
[1] "~/Library/R/x86_64/4.2/library" # user                
[2] "/Library/Frameworks/R.framework/Versions/4.2/Resources/library" # system
* Project '~/Documents/projects/sample-project' loaded. [renv 0.16.0]
> .libPaths()
[1] "~/Documents/projects/sample-project/renv/library/R-4.2/x86_64-apple-darwin17.0"         
[2] "~/Documents/projects/sample-project/renv/sandbox/R-4.2/x86_64-apple-darwin17.0/fb4b0a46"

renv::install("tidyverse/dtplyr@main")

renv::init(); renv::install()

cache, money

enumerate.

renv::snapshot()

{
  ...
  "Packages": {
    "DBI": {
      "Package": "DBI",
      "Version": "1.1.1",
      "Source": "Repository",
      "Repository": "CRAN",
      "Hash": "030aaec5bc6553f35347cbb1e70b1a17"
    },
    ...
  }
}

renv::snapshot()

  "R": {
    "Version": "4.1.1",
    "Repositories": [
      {
        "Name": "RSPM",
        "URL": "https://packagemanager.rstudio.com/cran/latest"
      }
    ]
  },

renv::snapshot()

"gitcellar": {
  "Package": "gitcellar",
  "Version": "0.0.0.9000",
  "Source": "Repository",
  "Repository": "https://ropensci.r-universe.dev",
  "RemoteUrl": "https://github.com/ropensci-org/gitcellar",
  "RemoteRef": "main",
  "RemoteSha": "5c761b993720ef51aeea81a94f01e34ae0c71c84",
  "Hash": "95fe2a4c4002b5d8fd674d460c6af4c1",
  "Requirements": [
    "R6",
    "gh",
    "purrr",
    "tibble",
    "withr"
  ]
},

renv.lock

is the project artifact we’re looking for.

collaborate.

renv::status()

The following package(s) are recorded in the lockfile but not installed:
              _
  R6            [2.5.0]
  Rcpp          [1.0.6]
  askpass       [1.1]
  base64enc     [0.1-3]
  bslib         [0.2.4]
  ...
  sourcetools   [0.1.7]
  sys           [3.4]
  withr         [2.4.0]
  xtable        [1.8-4]
  yaml          [2.2.1]

Use `renv::restore()` to install these packages.

renv::status()

The following package(s) are used in the project, but are not installed:

    vitessceR

Consider installing these packages, and then using `renv::snapshot()`
to record these packages in the lockfile.

renv::status()

The following package(s) are no longer used in this project:
            _
  gh          [1.3.0]
  gitcellar   [0.0.0.9000]
  gitcreds    [0.1.1]
  ini         [0.3.1]

Use `renv::snapshot()` to remove them from the lockfile.

the workflow

renv::init()

renv::install()
renv::snapshot()
ship
renv::restore()

probably?

I don’t intend to re-use this code

I’m purely a package developer

article: isolation for package dev

we have an opportunity

Let’s coalesce on a project standard.

Use renv.

special thanks

Kevin Ushey