Last active
October 26, 2022 13:07
-
-
Save pfuehrlich-pik/0b91022d5599831ee29fd7fe416332fb to your computer and use it in GitHub Desktop.
install all pik-piam R packages
This file contains 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
# Please note there's a considerable downside to installing all PIK-PIAM packages, as opposed to just the | |
# packages you need: Not only the PIK-PIAM packages you don't actually use, but also their (recursive) | |
# dependencies, are unnecessarily updated every time you update packages. If you still want to continue | |
# you can run the following line without the leading '#' in R to install all PIK-PIAM R packages: | |
# source("https://gist.githubusercontent.com/pfuehrlich-pik/0b91022d5599831ee29fd7fe416332fb/raw/givemeall.R") | |
# see https://pik-piam.r-universe.dev/ui#builds for a list of the packages | |
local({ | |
installIfMissing <- function(packages, installFunc) { | |
missingPackages <- Filter(x = packages, f = function(x) !requireNamespace(x, quietly = TRUE)) | |
if (length(missingPackages) > 0) { | |
message("installing the following packages:\n", paste(missingPackages, collapse = ", ")) | |
installFunc(missingPackages) | |
} | |
} | |
installWithDeps <- function(x) pak::pkg_install(x, dependencies = TRUE) | |
installIfMissing(c("withr", "pak"), install.packages) | |
withr::with_options(list(repos = c(pikpiam = "https://pik-piam.r-universe.dev", | |
CRAN = "https://cloud.r-project.org")), { | |
# suppress "Registered S3 method overwritten" | |
withr::local_envvar(`_R_S3_METHOD_REGISTRATION_NOTE_OVERWRITES_` = "false") | |
packagesUrl <- "https://pik-piam.r-universe.dev/src/contrib/PACKAGES" | |
pikPiamPackages <- sub("^Package: ", "", grep("^Package: ", readLines(packagesUrl), value = TRUE)) | |
# install packages also on CRAN explicitly first, so their more recent r-universe version is installed | |
installIfMissing(c("madrat", "magclass", "gms", "goxygen", "citation", "GDPuc"), installWithDeps) | |
installIfMissing(pikPiamPackages, installWithDeps) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment