knitr
R markdown
Usign knitr via Rmd
Rnw knitr style
L. Collado Torres for JHSPH Biostat computing club
http://lcolladotor.github.com/Rmd-intro/
knitr
R markdown
Usign knitr via Rmd
Rnw knitr style
It's a framework for producing reproducible reports
Sweave()
?md
) advantagesHTML
which opens new horizons besides PDF
PDF
: mostly through Rnw
filesHTML
: via R Markdown files (Rmd
)
More at the knitr showcase
HTML
citations: exampleknitr
instead of Sweave()
(change the option)Markdown's syntax is simple
The only major change in Rmd are the R code chunks
RStudio (desktop) has a great syntax description. They have another great page online. Check it out!
This blog post goes over the basics pretty well.
Knit HTML
MD
(Markdown quick reference)Knit HTML
Basic chunk
```r
hola()
```
You can add chunk labels after r
http://yihui.name/knitr/options
fig.width
, fig.height
: R controlout.width
, out.height
: output controlfig.keep
: useful for >=2 plots in 1 chunkfig.cap
: caption in Rnw onlycache
: whether to cache a chunkdependson
: which other chunks this chunk depends onresults
: similar to the same option in Sweave()
message
, error
, warning
: whether to print them or notopts_chunk$set(fig.width = 5, fig.height = 5, cache = TRUE)
set.seed(20130404)
x <- rnorm(100)
hist(x, col = "light blue", freq = FALSE)
set.seed(20130404)
x <- rnorm(100)
hist(x, col = "light blue", freq = FALSE)
For EDA
For sharing quick code
For quick presentations: no LaTeX
For blogging
Sexpr()
works for in-line codePDF
output!Quick example through RStudio
Longer template
library(slidify)
author("Rmd-intro")
## Edit the text
slidify("index.Rmd")
## Created the GitHub repo 'Rmd-intro'
## Initialized my git repository locally
## Added the github repo as a remote
## These steps are described here
## https://github.com/ramnathv/slidify/issues/99
publish("lcolladotor", "Rmd-intro")
## Slides are live at http://lcolladotor.github.com/Rmd-intro/