Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 37 lines (33 sloc) 2.243 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
## Online questionnaire with Google Docs and report with knitr markdown
```{r setup, echo=FALSE}
opts_knit$set(upload.fun = imgur_upload) # upload all images to imgur.com
opts_chunk$set(fig.width=5, fig.height=5, cache=FALSE)
```
```{r google_doc_data, echo=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](https://github.com/gimoya/theBioBucket-Archives/blob/master/R/Functions/google_ss.R)) to read the data from Google Docs ([source](https://docs.google.com/spreadsheet/ccc?key=0AmwAunwURQNsdFplUTBZUTRLREtLUDhabGxBMHBRWmc#gid=0)) .
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](https://github.com/gimoya/theBioBucket-Archives/blob/master/R/knitr/Questionnaire.Rmd)) that I used for knitting to produce the .md file ([source](https://raw.github.com/gimoya/theBioBucket-Archives/master/R/knitr/Questionnaire.md)) 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.

```{r barplot, echo=FALSE}
## 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)))
```
Something went wrong with that request. Please try again.