Skip to content

Instantly share code, notes, and snippets.

@chasset
Last active Jun 5, 2021
Embed
What would you like to do?
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