Last active
June 5, 2021 10:15
-
-
Save chasset/d7d1a39c8c84a98bd5b7b3538b16cd38 to your computer and use it in GitHub Desktop.
Install a package in R
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
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