Skip to content

Instantly share code, notes, and snippets.

@air-drummer
Last active August 29, 2015 14:09
Show Gist options
  • Save air-drummer/d722484cdec2b7bc8d8b to your computer and use it in GitHub Desktop.
Save air-drummer/d722484cdec2b7bc8d8b to your computer and use it in GitHub Desktop.
Loading packages in R in one shot
#Loading packages in R in one shot
load.packages <- function(..., install = TRUE){
reqFun <- function(pack) {
if(!suppressWarnings(suppressMessages(require(pack, character.only = TRUE)))) {
message(paste0("unable to load package ", pack,
": attempting to download & then load"))
install.packages(pack)
require(pack, character.only = TRUE)
}
}
lapply(..., reqFun)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment