Skip to content

Instantly share code, notes, and snippets.

@kennedymwavu
Created June 22, 2022 11:56
Show Gist options
  • Save kennedymwavu/142192f1016d8475ffa01143ca5d512a to your computer and use it in GitHub Desktop.
Save kennedymwavu/142192f1016d8475ffa01143ca5d512a to your computer and use it in GitHub Desktop.
Selectively install packages. If it's already installed don't reinstall.
# Just copy paste your "library" statements here using {datapasta}:
packages <- c(
"library(shiny)", "library(bs4Dash)", "library(shinyjs)",
"library(shinyWidgets)", "library(firebase)", "library(glue)",
"library(DBI)", "library(RPostgres)", "library(lubridate)",
"library(htmlwidgets)", "library(shinybusy)"
)
# rm "library()" leaving bare pkg chars:
pkg_nms <- gsub(pattern = "library\\(", replacement = "", x = packages) |>
gsub(pattern = "\\)", replacement = "")
# install the packages selectively:
for (package in pkg_nms) {
# if pkg is not installed:
if ( !(package %in% rownames(installed.packages())) ) {
install.packages(package, repos='https://cloud.r-project.org/')
cat('{', package, '} installed!\n', sep = '')
next
}
# if pkg is already installed:
cat('{', package, '} is already installed!\n', sep = '')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment