Skip to content

Instantly share code, notes, and snippets.

@wmcraver
Last active September 1, 2016 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmcraver/c175b8e011389a8e5b8f671c3671273e to your computer and use it in GitHub Desktop.
Save wmcraver/c175b8e011389a8e5b8f671c3671273e to your computer and use it in GitHub Desktop.
Checks for package installation. If the package does not exist, it installs them.
needed = c("lubridate", "dplyr", "data.table", "stringr")
is.installed = function(pkg){
is.element(pkg, installed.packages()[,1])
}
# For loop to run through each of the packages
for (p in 1:length(needed)){
ifelse(!is.installed(needed[p]), install.packages(needed[p], dependencies = T), print(paste(needed[p], " is already installed", sep = "")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment