diff --git a/test/ggplot2/init.r b/test/ggplot2/init.r new file mode 100755 index 00000000..64a16f06 --- /dev/null +++ b/test/ggplot2/init.r @@ -0,0 +1,21 @@ +# +# Example R code to install packages +# See http://cran.r-project.org/doc/manuals/R-admin.html#Installing-packages for details +# + +########################################################### +# Update this line with the R packages to install: + +my_packages = c("ggplot2") + +########################################################### + +install_if_missing = function(p) { + if (p %in% rownames(installed.packages()) == FALSE) { + install.packages(p, dependencies = TRUE) + } + else { + cat(paste("Skipping already installed package:", p, "\n")) + } +} +invisible(sapply(my_packages, install_if_missing)) diff --git a/test/ggplot2/install b/test/ggplot2/install new file mode 100755 index 00000000..5ba8e216 --- /dev/null +++ b/test/ggplot2/install @@ -0,0 +1,32 @@ +#!/bin/bash + +shopt -s extglob +set -e + +stack=${1:-cedar} +branch=${2:-cedar} + +dir=`mktemp -d` +cp -r . $dir +pushd $dir + +git init +git add --all +git commit -m "initial" + +heroku create --stack $stack \ + --buildpack https://github.com/virtualstaticvoid/heroku-buildpack-r.git#$branch + +app=`heroku apps:info -s | grep ^name=` +app=${app:5} + +git push heroku master + +# run R console +heroku run "R --no-save -f ./prog.r" --app $app + +popd + +# clean up +heroku apps:destroy $app --confirm $app +rm -rf $dir diff --git a/test/ggplot2/prog.r b/test/ggplot2/prog.r new file mode 100644 index 00000000..6661b265 --- /dev/null +++ b/test/ggplot2/prog.r @@ -0,0 +1,19 @@ +# +# Example R program +# + +# example from http://www.cookbook-r.com/Graphs/Bar_and_line_graphs_(ggplot2)/ + +library(ggplot2) + +dataframe <- data.frame(time=factor(c("Lunch", "Dinner"), levels = c("Lunch", "Dinner")), total_bill = c(14.89, 17.23)) + +plot = ggplot(data=dataframe, aes(x=time, y=total_bill)) + geom_bar(stat="identity") + +filename <- tempfile(fileext='.png') + +ggsave(filename=filename, height=5, width=15, type="cairo", plot) + +# TODO: store output file somewhere persistent. E.g. S3 + +print(filename)