sessionInfo() into R install

Is there a way I can share my sessionInfo() with collaborators such that the output of packages is in an R user friendly form for installing any packages they don't have e.g. a named vector of package names and versions, or similar?
I never realised how unfriendly the sessionInfo() output is to work with until people told me they were going through it in text form with a ctrl + f to see if they had each package installed: this is obviously not ideal and I would appreciate any advice.

Here is a piece of code I picked up somewhere. Is it of any help?

installed.packages()[names(sessionInfo()$otherPkgs), "Version"]
pkg  <- installed.packages()[,1]
attributes(pkg) <- NULL
# example of installed packages
have <- pkg[1:10]
# the sf package has been included
reqr <- sessionInfo()
# would have to loop through the first list
# in an actual case3
need <- reqr$otherPkgs[1][[1]][1][[1]]
# doesn't work in reprex because if library(sf) were added ...
# to install
to_add <- setdiff(have,need)
#>  [1] "abind"         "admiral"       "admiraldev"    "afex"         
#>  [5] "agricolae"     "AlgDesign"     "annotate"      "AnnotationDbi"
#>  [9] "anytime"       "arsenal"
# not run
# install.packages(to_add)

Created on 2023-07-30 with reprex v2.0.2

1 Like

May I suggest an alternative solution? If you want to keep track of installed packages in a reproducible way, use renv. It installs and maintains packages for you, it creates a JSON file called renv.lock with not only the names, but also versions of installed packages. You create renv.lock file with


and your collaborator can recreate all your packages, with exactly the same version numbers using


Certainly a better way of sharing package environment than sessionInfo().


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.