Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
37 lines (33 sloc) 2.243 kb

Online questionnaire with Google Docs and report with knitr markdown

opts_knit$set(upload.fun = imgur_upload) # upload all images to imgur.com
opts_chunk$set(fig.width=5, fig.height=5, cache=FALSE)
google_ss <- function(gid = NA, key = NA)
    {
    if (is.na(gid)) {stop("\nWorksheetnumber (gid) is missing\n")}
    if (is.na(key)) {stop("\nDocumentkey (key) is missing\n")}
    require(RCurl)
    url <- getURL(paste("https://docs.google.com/spreadsheet/pub?key=", key,
                        "&single=true&gid=", gid, "&output=csv", sep = ""),
                  cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
    read.csv(textConnection(url), header = T, sep = ",")
    }

## this is the key for the spreadsheet with the questoinaire responses
## key = 0AmwAunwURQNsdFplUTBZUTRLREtLUDhabGxBMHBRWmc taken from the documents url
## and used in the below function
data <- google_ss(gid = 0, key = "0AmwAunwURQNsdFplUTBZUTRLREtLUDhabGxBMHBRWmc")

I use a function (source) to read the data from Google Docs (source) . With the data I produce a simple barplot with the responses to the questionnaire (this was uploaded to imgur.com). Then I push the .md-file to github for publishing. Here is the .Rmd file (source) that I used for knitting to produce the .md file (source) which is rendered here by Github. I use some inline code here - like so: There were r table(data[,2])[2] responses with 'NO', r table(data[,2])[3] responses with 'YES' and r table(data[,2])[1] responses were indefinite.

## get the qestionnaires` question & make plot
q <- paste(gsub("\\.", " ", colnames(data)[2]), "??", sep = "")
require(lattice)
barplot(table(data[,2]),    
        main = paste(strwrap(q, width = 40), collapse = "\n"),
        sub = paste("N = ", nrow(data)))
Jump to Line
Something went wrong with that request. Please try again.