Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Last active December 3, 2025 14:49
Show Gist options
  • Select an option

  • Save matt-dray/5fd4d42e7bf17cf499e65be99b005efe to your computer and use it in GitHub Desktop.

Select an option

Save matt-dray/5fd4d42e7bf17cf499e65be99b005efe to your computer and use it in GitHub Desktop.
Look for packages in an R project and either (a) install them (without asking) or (b) add them as imports to a DESCRIPTION file
# Isolate packages used in project
used <- renv::dependencies()$Package
base <- rownames(installed.packages(priority = "base"))
pkgs <- setdiff(used, base) # don't install base packages
# To install:
purrr::walk(pkgs, \(pkg) pak::pak(pkg, ask = FALSE))
# To add to imports:
purrr::walk(pkgs, usethis::use_package)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment