Package versions with renv

R
packaging
Published

July 29, 2023

Versions snapshot

renv::snapshot() creates an renv.lock file that includes the versions of all R packages used in R code in the current project folder.

This is something I have looked for for a long time. In Python, I like to use pip-compile to pin my dependencies to specified versions. For R, I have just not realized that renv can also do that without creating a full renv project.

The full renv workflow has seemed to me to be overhead. I prefer to create fully reproducible environments with Rocker.

Find project packages

renv::dependencies() can be used to find all the packages used in a project.

library(renv)

dependencies() |> select(-Source)
Finding R package dependencies ... Done!
Package Require Version Dev
dplyr FALSE
purrr FALSE
renv FALSE
callr FALSE
conflicted FALSE
dplyr FALSE
rmarkdown FALSE
rmarkdown FALSE
dplyr FALSE
purrr FALSE
renv FALSE
callr FALSE
conflicted FALSE
dplyr FALSE

Package version number can be added with some tidyverse magic.

dependencies() |>
  mutate(version = map_chr(Package, \(.x) as.character(packageVersion(.x)))) |>
  select(Package, version) |>
  arrange(Package) |>
  distinct()
Finding R package dependencies ... Done!
Package version
callr 3.7.6
conflicted 1.2.0
dplyr 1.1.4
purrr 1.1.0
renv 1.1.4
rmarkdown 2.29

Customized session info

This led me to a condensed version of loading all project packages before calling sessionInfo()

conflicted::conflicts_prefer(callr::run)
map_lgl(dplyr::pull(dependencies(), Package), require)
Finding R package dependencies ... Done!
 [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
sessionInfo()
R version 4.5.1 (2025-06-13)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rmarkdown_2.29   conflicted_1.2.0 callr_3.7.6      renv_1.1.4      
[5] purrr_1.1.0      dplyr_1.1.4     

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5       cli_3.6.5         knitr_1.50        rlang_1.1.6      
 [5] xfun_0.52         processx_3.8.6    generics_0.1.4    jsonlite_2.0.0   
 [9] glue_1.8.0        htmltools_0.5.8.1 ps_1.9.1          evaluate_1.0.4   
[13] tibble_3.3.0      fastmap_1.2.0     yaml_2.3.10       lifecycle_1.0.4  
[17] memoise_2.0.1     compiler_4.5.1    htmlwidgets_1.6.4 pkgconfig_2.0.3  
[21] digest_0.6.37     R6_2.6.1          tidyselect_1.2.1  pillar_1.11.0    
[25] magrittr_2.0.3    tools_4.5.1       withr_3.0.2       cachem_1.1.0