Bruno Rodrigues, head of the statistics and data strategy departments at the Ministry of Research and Higher education in Luxembourg
Slides available online at https://is.gd/repro_boe
Code available at: https://github.com/b-rodrigues/repro_boe
vente-maison-2010-2021.xlsx in the data folderscripts/project_start folder):
We need to answer these questions
Here are the 4 main things influencing an analysis’ reproducibility:
Source: Peng, Roger D. 2011. “Reproducible Research in Computational Science.” Science 334 (6060): 1226–27
Create a renv.lock file in 2 steps!
renv::init() and check the folder for renv.lock(renv::init() will take some time to run the first time)
renv.lock file looks like{
"R": {
"Version": "4.2.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://packagemanager.rstudio.com/all/latest"
}
]
},
"Packages": {
"MASS": {
"Package": "MASS",
"Version": "7.3-58.1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "762e1804143a332333c054759f89a706",
"Requirements": []
},
"Matrix": {
"Package": "Matrix",
"Version": "1.5-1",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "539dc0c0c05636812f1080f473d2c177",
"Requirements": [
"lattice"
]
***and many more packages***
renv.lock filerenv.lock file not just a recordrenv::restore(){renv} conclusionShortcomings:
but… :
renv.lock file is “free”docker build -t hello .docker run --rm --name hello_container hello--rm: remove the container after running--name some_name: name your container some_namerenv.lock file)targets::tar_make()Package manager: tool to install and manage packages
Package: any piece of software (not just R packages)
A popular package manager:
let
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {};
system_packages = builtins.attrValues {
inherit (pkgs) R ;
};
in
pkgs.mkShell {
buildInputs = [ system_packages ];
shellHook = "R --vanilla";
}
There’s a lot to discuss here!
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {};
system_packages: a variable that lists software to installsystem_packages = builtins.attrValues {
inherit (pkgs) R ;
};
pkgs.mkShell {
buildInputs = [ system_packages ];
shellHook = "R --vanilla";
}
system_packages (buildInputs)R --vanilla when started (shellHook){rix} will help!nixpkgs in the rPackages set!{rix} (website) makes writing Nix expression easy!rix() function:renv.lock files can also be used as starting points:library(rix)
renv2nix(
renv_lock_path = "path/to/original/renv_project/renv.lock",
project_path = "path/to/rix_project",
override_r_ver = "4.4.1" # <- optional
)
rix::rix() generates a default.nix filenix-build (in terminal) or rix::nix_build() from Rnix-shell"dplyr@1.0.0")Let’s check out scripts/nix_expressions/rix_intro/
{rix} makes it easy to run pipelines in the right environment{targets})scripts/nix_expressions/nix_targets_pipelinecd /absolute/path/to/pipeline/ && nix-shell default.nix --run "Rscript -e 'targets::tar_make()'"
{targets} pipeline on Github actionsrix::tar_nix_ga() to generate the required filesrenv.lock file{targets}: not only good for reproducibility, but also an amazing tool all aroundContact me if you have questions:
Thank you!