Skip to content

Instantly share code, notes, and snippets.

@jrosell
Last active June 12, 2025 15:28
Show Gist options
  • Save jrosell/0e20567dd353dd7ca13dbc3546d2e0b4 to your computer and use it in GitHub Desktop.
Save jrosell/0e20567dd353dd7ca13dbc3546d2e0b4 to your computer and use it in GitHub Desktop.
This is how I like to check for required installed versions and load packages in my R scripts, including non-CRAN packages. It requires {rlang} and {pak} packages.
if (!requireNamespace('rlang')) stop("Please, run install.packages('rlang')")
rlang::check_required("pak")
pkgs <- rlang::chr(
rlang = "r-lib/[email protected]",
purrr = "purrr",
tidyverse = "tidyverse/tidyverse",
tidymodels = "tidymodels/tidymodels",
jrrosell = "jrosell/jrrosell@main",
)
pak::pak(pkgs)
suppressPackageStartupMessages(purrr::walk(names(pkgs), \(p) {
library(p, character.only = TRUE, quietly = TRUE)
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment