How to automatically track manually installed packages outside of R projects

Hi!

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:

save_user_R_packages.R

user_packages <- as.data.frame(installed.packages()[, c(1, 4)])
rownames(user_packages) <- NULL
user_packages <- user_packages[is.na(user_packages$Priority), ]$Package
write(user_packages, file = "~/.R/user_R_packages.txt")

setup_R.R

if(!require(pak)) {
  install.packages("pak", repos = "https://cran.rstudio.com/")
}

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.