Created
June 14, 2021 15:17
-
-
Save joundso/a1bc114a9cc1fbe70ceefd7d71389f1f to your computer and use it in GitHub Desktop.
Script to easily install R packages
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
## Packages needed to run the script: | |
packages <- " | |
DIZutils | |
data.table | |
joundso/mainzelliste-connector | |
miracum/misc-dizutils@development | |
# this_one_will_be_ignored | |
" | |
## Make a vector out of the `packages` string: | |
packages <- strsplit(packages, split = "\n")[[1]] | |
## Remove "uncommented" lines (the ones starting with a '#'): | |
packages <- packages[!grepl(pattern = "^(#)", x = packages)] | |
## Remove empty elements: | |
packages <- packages[nchar(packages) > 0] | |
## And install all of them: | |
install.packages("remotes") | |
for (package in packages) { | |
cat(paste0( | |
"\n\n## Starting to install '", | |
package, | |
"' with all dependencies:\n" | |
)) | |
if (grepl(pattern = "/", x = package)) { | |
if (grepl(pattern = "@", x = package)) { | |
## Extract the branch: | |
branch <- | |
gsub(pattern = "^(.*)@", | |
replacement = "", | |
x = package) | |
remotes::install_github(repo = package, ref = branch) | |
} else { | |
## Install the master/main branch: | |
remotes::install_github(repo = package) | |
} | |
} else { | |
remotes::update_packages( | |
packages = package, | |
build_manual = FALSE, | |
quiet = TRUE, | |
upgrade = "always" | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment