# from https://gist.github.com/stevenworthington/3178163
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE, repos = "http://cran.r-project.org")
sapply(pkg, require, character.only = TRUE)
}
# usage
packages <- c("ggplot2", "gplots", "lattice", "plyr", "reshape2",
"RColorBrewer", "grid", "gridExtra", "igraph", "igraphdata")
suppressMessages(ipak(packages))