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.