Research compendium
for file organizationfunctions
for code optimizationQuarto
| RMarkdown
for literate programminggit
for version controlGitHub
for sharing & collaborationAll these tools aim to make your code and data more reproducible.
What about the computational environment?
Research compendium
for file organizationfunctions
for code optimizationQuarto
| RMarkdown
for literate programminggit
for version controlGitHub
for sharing & collaborationAll 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
packageAvailable at: https://rstudio.github.io/renv/
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
in a projectR version 4.4.2 (2024-10-31) -- "Pile of Leaves"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu
- Project '~/Documents/myproject' loaded. [renv 1.0.11]
>
Alternatively, for a new project:
.
├── .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.4.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
"Packages": {
"renv": {
"Package": "renv",
"Version": "1.0.11",
"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.4.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
"Packages": {
"renv": {
"Package": "renv",
"Version": "1.0.11",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"utils"
],
"Hash": "47623f66b4e80b3b0587bc5d7b309888"
}
}
}
renv
renv::status()
is your friend:Use this function at any time to check inconsistencies between lockfile, library, and dependencies
renv
renv::status()
is your friendUse this function at any time to check inconsistencies between lockfile, library, and dependencies
Package used but not installed in the project library
renv
renv::status()
is your friendUse this function at any time to check inconsistencies between lockfile, library, and dependencies
Package used but not installed in the project library
renv
renv::status()
is your friendUse this function at any time to check inconsistencies between lockfile, library, and dependencies
Package used but not installed in the project library
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 (renv.lock
)This function will add and/or remove package metadata in the lockfile
fs
package metadata from the lockfilecli
package metadata to the lockfilerenv
renv.lock
fileThen your colleague will have to initialize renv
in the project and follow instructions:
## Initialize renv & restore environment ----
renv::init()
## This project already has a lockfile. What would you like to do?
##
## 1: Restore the project from the lockfile.
## 2: Discard the lockfile and re-initialize the project.
## 3: Activate the project without snapshotting or installing any packages.
## 4: Abort project initialization.
##
## Selection: 1
## The following package(s) will be updated:
##
## # CRAN -----------------------------------------------------------------
## - fs [* -> 1.6.5]
## - renv [* -> 1.0.11]
##
## # Downloading packages -------------------------------------------------
##
## ...
##
## # Installing packages --------------------------------------------------
## - Installing fs ... OK [linked from cache]
## - Installing renv ... OK [built from source and cached in 8.6s]
##
## - Project '~/Documents/myproject' loaded. [renv 1.0.11]
All packages (w/ the good version) listed in the lockfile will be automatically installed in the project library
Use renv
at the end of the project to freeze your packages environment and share the renv.lock
Do not forget to add renv/
and .Rprofile
to the .gitignore