diff --git a/swarmlab/Makefile b/swarmlab/Makefile index a25c492..da91058 100644 --- a/swarmlab/Makefile +++ b/swarmlab/Makefile @@ -1,4 +1,8 @@ -all: hello piechart +all: required_packages hello piechart + +required_packages: + + Rscript ../examples/required.packages.R hello: diff --git a/swarmlab/required.packages.R b/swarmlab/required.packages.R new file mode 100644 index 0000000..7b1b2b2 --- /dev/null +++ b/swarmlab/required.packages.R @@ -0,0 +1,12 @@ +#create a function to check for installed packages and install them if they are not installed +install <- function(packages){ + new.packages <- packages[!(packages %in% installed.packages()[, "Package"])] + if (length(new.packages)) + install.packages(new.packages, dependencies = TRUE) + sapply(packages, require, character.only = TRUE) +} + +# usage +#required.packages <- c("ggplot2", "dplyr", "reshape2", "devtools", "shiny", "shinydashboard", "caret","randomForest","gbm","tm","forecast","knitr","Rcpp","stringr","lubridate","manipulate","Scale","sqldf","RMongo","foreign","googleVis","XML","roxygen2","plotly","parallel","car") +required.packages <- c("plotrix") +install(required.packages)