Research compendium for file organization
Writing functions for code optimization
Quarto (or RMarkdown) for literate programming
git for version control
GitHub for sharing & collaboration
These tools aim to make your code and data more reproducible.
What about the computational environment?
Research compendium for file organization
Writing functions for code optimization
Quarto (or RMarkdown) for literate programming
git for version control
GitHub for sharing & collaboration
These tools aim to make your code and data more reproducible.
What about the computational environment?
Questions
We have to specify, the required packages, their versions, and the repositories in which they are accessible!
renv package| Function | Description |
|---|---|
init() |
Initialize renv in a project |
status() |
Check consistencies between lockfile & project library |
snapshot() |
Record current state of the project library in the lockfile |
restore() |
Restore project library from a lockfile |
install() |
Install packages in the project library |
remove() |
Remove packages from the project library |
deactivate() |
Temporary deactivate renv for the project |
activate() |
(Re)activate renv in the project |
PACKAGE
A well-structured collection of functions, documentation, data, and tests.
LIBRARY
A directory in which packages will be installed.
PACKAGE
A well-structured collection of functions, documentation, data, and tests.
LIBRARY
A directory in which packages will be installed.
PACKAGE
A well-structured collection of functions, documentation, data, and tests.
LIBRARY
A directory in which packages will be installed.
[1] is the User library
[2] is the System library



renv

renvrenv in a projectrenv::init() to intialize renv in an existing projectR version 4.5.2 (2025-10-31) -- "[Not] Part in a Rumble"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu
- Project '~/Documents/myproject' loaded. [renv 1.1.5]
>
Alternatively, for a new project with Positron:

.
├── .Rprofile
│
├── renv/
│ ├── .gitignore
│ ├── activate.R
│ ├── library/
│ └── settings.dcf
│
└── renv.lock
.
├── .Rprofile # Activate renv on project opening
│
├── renv/
│ ├── .gitignore
│ ├── activate.R
│ ├── library/
│ └── settings.dcf
│
└── renv.lock
.
├── .Rprofile # Activate renv on project opening
│
├── renv/
│ ├── .gitignore # Ignore large renv files (e.g. packages)
│ ├── activate.R # R script to launch renv
│ ├── library/ # R packages
│ └── settings.dcf # renv settings
│
└── renv.lock
.
├── .Rprofile # Activate renv on project opening
│
├── renv/
│ ├── .gitignore # Ignore large renv files (e.g. packages)
│ ├── activate.R # R script to launch renv
│ ├── library/ # R packages
│ └── settings.dcf # renv settings
│
└── renv.lock # Packages metadata, a.k.a the Lockfile
It’s a simple JSON (JavaScript Object Notation) file that specifies package metadata:
Preview of a lockfile (renv.lock)
{
"R": {
"Version": "4.5.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
"Packages": {
"renv": {
"Package": "renv",
"Version": "1.1.5",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"utils"
],
"Hash": "47623f66b4e80b3b0587bc5d7b309888"
}
}
}
It’s a simple JSON (JavaScript Object Notation) file that specifies package metadata:
Preview of a lockfile (renv.lock)
To collaborate you only need to share the renv.lock
{
"R": {
"Version": "4.5.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
"Packages": {
"renv": {
"Package": "renv",
"Version": "1.1.5",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"utils"
],
"Hash": "47623f66b4e80b3b0587bc5d7b309888"
}
}
}
renvrenv::status() is your friendUse this function at any time to check inconsistencies between
lockfile,libraryandcode
renvrenv::status() is your friendUse this function at any time to check inconsistencies between
lockfile,libraryandcode
Package used but not installed in the project library
use renv::install()
renvrenv::status() is your friendUse this function at any time to check inconsistencies between
lockfile,libraryandcode
Package used but not installed in the project library
use renv::install()
renvrenv::status() is your friendUse this function at any time to check inconsistencies between
lockfile,libraryandcode
Package used but not installed in the project library
use renv::install()
Package not used but recorded in the lockfile
use renv::snapshot() and renv::remove("fs") (optional)
renv::install() to install packages in your project libraryYou can install the latest version of a package, a specific version of a package, a package from GitHub, GitLab, etc.
renv::snapshot() to update the lockfile (package metadata)This function will add and/or remove package metadata in the lockfile
fs package metadata from the lockfilecli package metadata to the lockfilerenv::remove(...) to uninstall package(s) from project library (optional)renv You just need to share the renv.lock file
1. Colleague A
renv in the project w/ renv::init().Rprofile & renv/ to .gitignorerenv::install()renv::install() ]renv::snapshot()GitHubrenv You just need to share the renv.lock file
1. Colleague A
renv in the project w/ renv::init().Rprofile & renv/ to .gitignorerenv::install()renv::install() ]renv::snapshot()GitHub2. Colleague B / C / …
GitHubrenv w/ renv::init(bare = TRUE)renv::restore()renv::install() ]renv::snapshot()GitHubrenv You just need to share the renv.lock file
1. Colleague A
renv in the project w/ renv::init().Rprofile & renv/ to .gitignorerenv::install()renv::install() ]renv::snapshot()GitHub2. Colleague B / C / …
GitHubrenv w/ renv::init(bare = TRUE)renv::restore()renv::install() ]renv::snapshot()GitHub3. Colleague A
GitHubrenv::restore()renv::install() ]renv::snapshot()GitHubrenv You just need to share the renv.lock file
1. Colleague A
renv in the project w/ renv::init().Rprofile & renv/ to .gitignorerenv::install()renv::install() ]renv::snapshot()GitHub2. Colleague B / C / …
GitHubrenv w/ renv::init(bare = TRUE)renv::restore()renv::install() ]renv::snapshot()GitHub3. Colleague A
GitHubrenv::restore()renv::install() ]renv::snapshot()GitHub4. Colleague B / C / …
GitHubrenv::restore()renv::install() ]renv::snapshot()GitHub

Define ONE person in charge of updating the renv.lock with renv::snapshot()
1. Colleague A (team leader)
renv in the project w/ renv::init().Rprofile & renv/ to .gitignorerenv::install()renv::install() ]renv::snapshot()GitHub2. Colleague B / C / …
GitHubrenv w/ renv::init(bare = TRUE)renv::restore()renv::install() ]renv::snapshot()GitHub3. Colleague A (team leader)
GitHubrenv::restore()renv::install() ]renv::snapshot()GitHub4. Colleague B / C / …
GitHubrenv::restore()renv::install() ]renv::snapshot()GitHub Use renv at the end of the project to freeze your packages environment
Team leader
renv in the project w/ renv::init().Rprofile & renv/ to .gitignorerenv::install()renv::snapshot()GitHub
Alternatively, visit this page