Skip to content

Instantly share code, notes, and snippets.

@jrosell
Last active January 3, 2025 20:29
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 and load packages in my R scripts, including non-CRAN packages. It requires {rlang} and {pak} packages.
if (!requireNamespace('pak')) stop("Please, run install.packages('pak')")
pkgs <- c(
rlang = "rlang",
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