Last active
June 12, 2025 15:28
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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