renv
2023-07-04
“I tried to run your code but it says I’m missing X” 😟
“Your code used to run fine but now it’s not working” 😖
“I upgraded my software and now your code is junk” 💔
Crucial for collaboration and transparency in science
Software and package versions can differ between computers
Potential code failure or inconsistent results
Solution: Replicate the environment
Manual replication of the environment is impractical
Potential solutions
Virtual environments (Python, Conda, etc)
Docker
Binder/Jupyter Notebooks
Extend base R with more functionality
Called libraries or packages in other languages
Can require compilation on your machine (source) or pre-compiled as a binary package
Source of packages 📦
Many different available
CRAN
Bioconductor
Posit Public Package Manager
R Universe
Store packages installed for current R version
System libraries
User
Site
Default
renv
📚renv::init()
install.packages()
renv::snapshot()
to lock file (renv.lock
)renv::snapshot()
) or revert to previous if updates introduce new problems (renv::restore()
)dependencies()
library("dplyr")
dplyr::mutate()
renv
global package cache for re-useactivate()
File | Usage |
---|---|
.Rprofile |
Updated to activate renv for new project R sessions |
renv.lock |
The lockfile |
renv/ |
Folder containing all environment details |
renv/activate.R |
Activation script run by the project .Rprofile . |
renv/library |
The private project library |
renv/settings.json |
Project settings |
renv/.gitignore |
renv specific gitignore |
renv.lock
🔒renv
{
"R": {
"Version": "4.2.3",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
"Packages": {
"markdown": {
"Package": "markdown",
"Version": "1.0",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "4584a57f565dd7987d59dda3a02cfb41"
},
"here": {
"Package": "here",
"Version": "0.7",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "908d95ccbfd1dd274073ef07a7c93934"
}
}
}
renv::restore()
and renv::install()
~/.local/share/renv
Function | Shim |
---|---|
install.packages() |
renv::install() |
remove.packages() |
renv::remove() |
update.packages() |
renv::update() |
renv::isolate()
: copies all dependencies into the local libraryrenv
in the version controlled project folderrenv
generated onesrenv
will now bootstrap the project environment on collaborators computersrenv::history()
dplyr
update from version 1.0.10 to 1.1.12 replaced summarise()
with reframe()
renv
project in shiny app dir (shared shiny user cache)renv/activate.R
in app.R
renv
Collaborating on project and sharing results
Ensure forward compatibility
Project small enough to not warrant using more intense encapsulation
Use of more robust encapsulation problematic (eg. Docker on Shiny Server)
dplyr
caused a change in the functionality of if_else()
where Surveiller
relied on the