An Introduction to knitr === author: Yihui Xie date: 2013/07/17 @ Seattle, BioC 2013 font-import: http://fonts.googleapis.com/css?family=Roboto+Slab font-family: 'Roboto Slab' My first BioC conference === - [badge does not flip](http://yihui.name/en/2013/03/on-enar-or-statistical-meetings-in-general/) (a sign of intelligence of organizers!) - live code! Outline === - motivation (a real one "better homework" and a correct one "reproducible research") - features - discussion of remaining problems - see the lab session by Jeff Johnston on Friday for practical applications Forget about the big words for now... === type: prompt incremental: true - literate programming - designed for software development - heaven for reporting (Sweave, ingenious!) - boring for software (LaTeX package/doc) - reproducible research - sounds like "more work to do"? - I do not want to learn anything new; let me copy and paste - one day they will be doing reproducible research _unconciously_ Consider some practical problems === - the problem of "when you type a backslash, God kills a kitten" - how many kittens were killed after I taught them LaTeX? - the problem of "disappearing summer interns" (coined by [Carlos Scheidegger](http://cscheid.net/)) - one of the [best comments](http://stackoverflow.com/q/184618/559676) in source code ```r # When I wrote this, only God and I understood what I was doing # Now, God only knows ``` Solution: Marmot! === ![](http://i.imgur.com/pbKf56j.jpg) Solution: Markdown! === ![](http://i.imgur.com/jrwbX.jpg) Solution: knitr === - any computing language (not yet) - R, Python, Perl, C++, Shell scripts, awk, sed, CoffeeScript, ... - even SAS - any authoring language - LaTeX, HTML, Markdown, reSructuredText, AsciiDoc One-minute introduction === - see [`002-minimal.Rnw`](https://github.com/yihui/knitr-examples/blob/master/002-minimal.Rnw) and [`001-minimal.Rmd`](https://github.com/yihui/knitr-examples/blob/master/001-minimal.Rmd) What are you waiting for? === ![](http://i.imgur.com/KTPePlj.gif) Everything about knitr === - Documentation: (video) - Development: - Examples: - Questions: The knitr book (coming on July 22) === [![](http://images.tandf.co.uk/common/jackets/crclarge/978148220/9781482203530.jpg)](http://amzn.com/1482203537) Basic features === - R + Markdown, R + LaTeX, R + HTML - numeric output, graphics (also animations), syntax highlighting, code formatting, ... Cache === - if you do not change anything, just load the old results - `lazyLoad()` Engines === - use the `engine` option, e.g. `engine = 'python'`, `engine = 'awk'` - see `knitr-examples/.*engine.*.Rmd` (e.g. `023`) Help! === type: prompt - current design: for each chunk, use a new process, e.g. `system('python -c "print(1+1)"')` - Doug Bates: [engine = Julia?](https://groups.google.com/forum/#!topic/knitr/F78PBMIamwk) - how do I open a persistent sub-process in R, pipe code into it, and get the results back? - socket? - fifo? RPubs === - - tons of reports (R Markdown + knitr + RStudio) R Notebook === Run this locally: ```{r eval=FALSE, cache=FALSE} # please use the latest deveopment version on Github if (!require('knitr') || packageVersion('knitr') <= '1.3') install.packages('knitr', repos = c('http://rforge.net', 'http://cran.rstudio.org'), type = 'source') demo('notebook', package = 'knitr') ``` Vistat === - reproducible statistical graphics - - R Markdown + Jekyll + Github R Presentations (RStudio) === - i.e. what you see here - [RStudio 0.98](http://www.rstudio.com/ide/docs/presentations/overview) (not released yet) Package vignettes === - [Gentleman and Temple Lang (2004)](http://biostats.bepress.com/bioconductor/paper2/) - one R package to rule them all! - `data`, `R`, `man`, `tests`, `demo`, `src`, `vignettes` - `VignetteBuilder: knitr` in DESCRIPTION - `\VignetteEngine{knitr::knitr}` in vignettes - [see details](http://yihui.name/knitr/demo/vignette/) Questions/Comments? === - - ![](http://i.imgur.com/q7ftMqY.gif)