Last active
January 3, 2025 20:29
-
-
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.
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('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