Skip to content

Commit

Permalink
added test project for ggplot2
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualstaticvoid committed Mar 3, 2015
1 parent 1a3b773 commit 89f091b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 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))
32 changes: 32 additions & 0 deletions 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
19 changes: 19 additions & 0 deletions 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)

0 comments on commit 89f091b

Please sign in to comment.