Find file
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (33 sloc) 2.19 KB

Online questionnaire with Google Docs and report with knitr markdown

opts_knit$set( = imgur_upload) # upload all images to
opts_chunk$set(fig.width=5, fig.height=5, cache=FALSE)
google_ss <- function(gid = NA, key = NA)
    if ( {stop("\nWorksheetnumber (gid) is missing\n")}
    if ( {stop("\nDocumentkey (key) is missing\n")}
    url <- getURL(paste("", 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 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 = "")
        main = paste(strwrap(q, width = 40), collapse = "\n"),
        sub = paste("N = ", nrow(data)))