Package management for R
{renv}
?{renv}
is an R package for managing project dependencies and creating reproducible environments
{renv}
{renv}
{renv}
.Rprofile
is updated to include:install.packges("package")
or library(package)
it does to the right place (renv/library/R-{version}/{computer-specifics}
)renv.lock
file (really just a text file) is created to store the names and versions of the packages.renv.lock
{
"R": {
"Version": "4.3.0",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cran.rstudio.com"
}
]
},
"Packages": {
"R6": {
"Package": "R6",
"Version": "2.5.1",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "470851b6d5d0ac559e9d01bb352b4021"
},
base64enc": {
"Package": "base64enc",
"Version": "0.1-3",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "543776ae6848fde2f48ff3816d0628bc"
},
{renv}
laterRestore an environment
Install new packages
Update the lockfile
{renv}
renv.lock
file with collaborators to ensure consistent environmentsrenv::restore()
, the correct versions of the packages will be installed on their computerRemove packages that are no longer used:
Check the status of the project library with respect to the lockfile:
This will tell you to renv::snapshot()
to add packages you’ve installed but haven’t snapshotted, or renv::restore()
if you’re missing packages you need but which aren’t installed
{renv}
benefits:
Getting started with {renv}
renv::init()
renv::snapshot()
renv::restore()
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")
.)
Create an R script and save it in your R project. Include some code that requires the package. For example:
Run renv::status()
to make sure your project picked up the package as a dependency.
Run renv::snapshot()
to record that package in your lockfile.
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"
},