Skip to content

Instantly share code, notes, and snippets.

@ZeccaLehn
Last active November 11, 2016 22:05
Show Gist options
  • Save ZeccaLehn/ebb03a18e197c44aee11 to your computer and use it in GitHub Desktop.
Save ZeccaLehn/ebb03a18e197c44aee11 to your computer and use it in GitHub Desktop.
[R] Check and Load Packages
# Allows for install check and automatic download
# Note: Rerun line 6 after CTRL + ALT + F10 Restart
# Adapted from: http://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them
packages <- c("data.table", "dplyr", "doParallel")
packagesCheck <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(packagesCheck)>0) {install.packages(packagesCheck)}; rm(packagesCheck)
lapply(packages, function(x) {do.call("require", list(x))})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment