2.4 {renv}

Open the slides in a new tab here.

Exercises

  1. Install {renv}, then initialize in your in-class R project with renv::init()

  2. Find and open the renv.lock file to look at the packages that are included.

  3. Install a new R package of your choice. (Not sure what to choose? Try one of these fun packages. For example, I did install.packages("hadley/emo").)

  4. Create an R script and save it in your R project. Include some code that requires the package. For example:

emo::ji("banana")
  1. Run renv::status() to make sure your project picked up the package as a dependency.

  2. Run renv::snapshot() to record that package in your lockfile.

  3. Open your lockfile and look for your new package. For example, mine now has:

"emo": {
      "Package": "emo",
      "Version": "0.0.0.9000",
      "Source": "git",
      "RemoteType": "git",
      "RemoteUrl": "https://github.com/hadley/emo",
      "RemoteHost": "api.github.com",
      "RemoteUsername": "hadley",
      "RemoteRepo": "emo",
      "RemoteRef": "master",
      "RemoteSha": "3f03b11491ce3d6fc5601e210927eff73bf8e350",
      "Requirements": [
        "R",
        "assertthat",
        "crayon",
        "glue",
        "lubridate",
        "magrittr",
        "purrr",
        "rlang",
        "stringr",
        "utils"
      ],
      "Hash": "eb32b8f0bb50621ad498f5d836b546a4"
    },
  1. Commit and push. Now anyone can recreate the state of your packages at this moment!

Resources