03/19/2014, Orange County R User Group

About me

  • first language: Chinese
  • second language: R (10 years)
  • third language: English
  • graduated from Iowa State Univ (stats)
  • joined RStudio
  • (co-)author of thirteen: animation, knitr, cranvas, formatR, testit, highr, Rd2roxygen, iBUGS, fun, servr, MSG, tikzDevice, shiny
  • maintainer of two: evaluate, markdown

Dynamic Documents

Idea

Document formats

  • computing language + documentation language
  • (R | Python | C++ | …) + (LaTeX | Markdown | HTML | …)
  • file extensions: .Rmd, .Rnw/.Rtex, .Rhtml, …

Reproducible research

knitr

As an R package

# install.packages('knitr')
library(knitr)
knit('your-document.Rmd')  # compiles a document

Basic features

  • text output
  • graphics
  • cache
  • cross references
  • output hooks and chunk hooks
  • language engines

The spin() function

  • give me an R script, and I give you a report
  • internally converted to R Markdown/LaTeX/…
#' today I built a model
fit = lm(dist ~ speed, data = cars)

#' and I got the slope `r coef(fit)[2]`

#+ dist-speed, fig.width=5, fig.height=4
plot(cars)
abline(fit)

The stitch() function

  • insert an R script in a predefined template
  • LaTeX, HTML or Markdown

R Markdown

Markdown

  • if you cannot master the basic syntax of Markdown in 10 minutes, I give you 10 dollars
  • RPubs: http://rpubs.com
    • forget about reproducible research, because you are doing it unconsiously

R Markdown v1

R Markdown v2

Applications

Blogging

R Package vignettes

Docco style (knitr's Gangam style)

# see list of vignettes
help(package = 'knitr', help_type='html')
# Docco Classic Style

The knitr book

Learn what other cool kids are doing

Questions?