Last active
September 1, 2022 09:53
-
-
Save JoseAlanis/86da75bf223e10344b7c16791f45bafe to your computer and use it in GitHub Desktop.
Checks if multiple R packages are installed. If yes, they are required. If not, they are installed and required.
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
load.package <- function(package, repos) { | |
# list of packages missing | |
missing <- package[!package %in% installed.packages()[, 'Package']] | |
# check wich packages are not intalled and install them | |
if (!is.null(missing)) { | |
if (missing(repos)) { | |
# use Goettingen (Germany) mirror as default | |
repos <- 'https://ftp.gwdg.de/pub/misc/cran/' | |
} | |
install.packages(missing, dependencies = TRUE, | |
repos = repos) | |
} | |
# load all packages | |
sapply(package, require, character.only = TRUE) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment