Report generation using R script

spinning in knitr package

@kohske

Here is the script generating this html
https://gist.github.com/gists/2975392


Contents


How to use

  1. Write a script
  2. Put comments with markdown
  3. spin it.
  4. Open it in web browser.
> library(knitr)
+ spin("script.R")
+ browseURL(normalizePath("script.html"))

An example of chunk opttion

The followings will generate

#+ echo = TRUE
mean(rnorm(100))

#+ echo = FALSE
sample(1:10)

this kind of html

mean(rnorm(100))
## [1] 0.1076
##  [1]  5  1 10  2  7  6  4  8  9  3

Figure

library(ggplot2)
qplot(rnorm(100), rnorm(100), colour = rnorm(100)) + 
    guides(colour = "colourbar")

plot of chunk unnamed-chunk-5


Table

xtable is available for generating html-compatible table from data.frame.
You need results = "asis" in chunk option

#+ results = 'asis'
library(xtable)
print(xtable(head(iris)), type = "html")
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.10 3.50 1.40 0.20 setosa
2 4.90 3.00 1.40 0.20 setosa
3 4.70 3.20 1.30 0.20 setosa
4 4.60 3.10 1.50 0.20 setosa
5 5.00 3.60 1.40 0.20 setosa
6 5.40 3.90 1.70 0.40 setosa