Skip to content

Instantly share code, notes, and snippets.

@chasset
Last active June 5, 2021 10:15
Show Gist options
  • Save chasset/d7d1a39c8c84a98bd5b7b3538b16cd38 to your computer and use it in GitHub Desktop.
Save chasset/d7d1a39c8c84a98bd5b7b3538b16cd38 to your computer and use it in GitHub Desktop.
Install a package in R
args <- commandArgs(trailingOnly=TRUE)
depot <- args[1]
packages <- args[2:length(args)]
if (depot == "GITHUB") library(devtools)
for (package in packages) {
if (!require(package, character.only = T)) {
message(paste('Installation du paquet', package))
if (depot == "GITHUB") {
install_github(package)
}
if (depot == "CRAN") {
install.packages(pkgs = package, repos = "https://cloud.r-project.org/", dependencies = TRUE)
if (!require(package, character.only = T))
stop(paste("Installation du paquet", package, "interrompue"))
}
} else {
message(paste(package, 'est déjà installé'))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment