How to automatically track manually installed packages outside of R projects


Is there an easy way to track manually installed packages outside R projects? I.e. similar to {renv}, I would like to be able to track what packages I have installed on my system as a list (just the names, not necessarily versions, no source code or binaries) so it can be version controlled and synced across computers. Ideally, it would also track how the package is hosted (i.e. CRAN, GitHub, etc.) so the list can be used to reinstall/compare against to install missing packages.

So far, I created these two scripts with the first one based on an old Stack overflow thread:


user_packages <-[, c(1, 4)])
rownames(user_packages) <- NULL
user_packages <- user_packages[$Priority), ]$Package
write(user_packages, file = "~/.R/user_R_packages.txt")


if(!require(pak)) {
  install.packages("pak", repos = "")

pak::pkg_install(scan("~/.R/user_R_packages.txt", what = "character"))

There are two problems with this approach so far:

  1. The information on what packages are from GitHub gets lost and causes an error when using pak::pkg_install().
  2. The list contains all installed packages, including dependencies installed as part of another package's installation.

Does anyone have a better strategy for automatically tracking manually installed packages?

Edit: Fix formatting

This topic was automatically closed 42 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.