class: center, middle, inverse, title-slide # The R Markdown Ecosystem ## Reproducible Reports, Papers, Books, Websites, and Presentations ###
Yihui Xie
,
RStudio Inc
### 2017/03/02 @ Kansas State University --- # About myself - Native Chinese (1st language: Chinese; 2nd? 3rd?) -- - Statistician by training (Iowa State University) -- - Software engineer for a living (working remotely for RStudio) -- - Authored and co-authored a few R packages (knitr, animation, rmarkdown, shiny, bookdown, blogdown, and so on) -- - Enjoys programming more than data analysis (no, I'm not a data scientist) ```r x11() library(animation) ani.options(nmax = 213, interval = 0.03) quincunx(balls = 200, col.balls = rainbow(200)) library(fun) x11(type = "Xlib") mine_sweeper() ``` --- # Outline - R Markdown - Regular documents - Journal papers - Presentations - Books - Websites --- background-image: url(http://rmarkdown.rstudio.com/images/bandOne.png) background-size: contain class: inverse, center, middle # R Markdown --- # Dynamic Documents --- title: "A Simple Regression" author: "Yihui Xie" output: html_document: toc: true --- # Model We built a linear regression model. ```{r} fit <- lm(dist ~ speed, data = cars) b <- coef(fit) plot(fit) ``` # Results The slope of the regression is `r b[1]`. ??? In fact, I have used this minimal example for a few years, and one day I suddenly realized I made a mistake here: the slope should be `b[2]` instead of `b[1]`. Although it is a little ironic, it is also a good example of why you should generate reports from source code instead of pasting a fixed number. If it is just a fixed number, say, 3.87, it will be difficult to realize that you copied a wrong coefficient. --- # Reproducible research - Keyword: automation (i.e. produce results via code instead of manual operations) - You will be stumbled over and over again by things that cannot be automated (e.g. the source data may be updated) -- .center[<img src="gif/stumble-baby.gif" width=400 />] --- # Reproducible research is hard - The Duke Saga: http://www.economist.com/node/21528593 - If you have 40 minutes, I strongly recommend this video by Keith Baggerly: https://youtu.be/7gYIs7uYbMo - Not easy for large projects -- .center[<img src="gif/pass-chase.gif" width=400 />] --- # A regular R Markdown document - The rmarkdown package http://rmarkdown.rstudio.com ≈ [knitr](https://yihui.org/knitr) + [Pandoc](http://pandoc.org) - Markdown syntax (YAML metadata, section headings, math expressions, figures, tables, ...) - One document, different output formats - Customization - Demos --- # Sounds simple? .center[![](gif/get-into-the-car.gif)] --- background-image: url(https://images.unsplash.com/photo-1466779561253-0a08336ba2ab?dpr=2&auto=format&fit=crop&w=1500&h=844&q=80&cs=tinysrgb&crop=) background-size: cover class: inverse, center, middle # More advanced applications of R Markdown --- # Journal papers - The rticles package https://github.com/rstudio/rticles - Basic idea: translate R Markdown to LaTeX via the template of the journal - Files -> New File -> R Markdown -> From Template --- # Presentations - Built-in presentation formats (ioslides, Slidy, beamer) - My current favorite format: xaringan https://github.com/yihui/xaringan - HTML5 slides (in web browser) - Much more customizable than built-in formats (e.g. easily align elements, set background images, change CSS, create template slides, and so on) - Useful keyboard shortcuts (fullscreen, mirror, presenter mode, ...) ??? Sharingan, from the Japanese anime Naruto ![Sharingan](https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg) --- # Books - The bookdown package (on [CRAN](https://cran.rstudio.com/package=bookdown) and [Github](https://github.com/rstudio/bookdown)); Showcase https://bookdown.org - Why? - books should have been much easier to write (technically) - cheaper to buy (on the order of $10) - richer to read (dynamic content -- imagine you can fit a linear regression right inside the book) - quicker to iterate (not waiting for eight years for a second edition) - and authored by a small number of people but have attracted a large number of contributors (on the order of 100) instead of only relying on the feedback of three anonymous reviewers - How? A series of Rmd files, each being a chapter - Extended the Markdown syntax (number and reference figures / tables / equations / theorems / ...) --- # Websites - The blogdown package https://github.com/rstudio/blogdown - Based on R Markdown and Hugo - Set up a website in one minute! (`blogdown::new_site()` under an empty directory) - Structure of the website --- background-image: url(gif/logo.png) background-position: 90% 50% background-size: 20% # Contact info - Yihui Xie - https://yihui.org - Twitter [@xieyihui](https://twitter.com/xieyihui) Github [@yihui](https://github.com/yihui) - RStudio - https://www.rstudio.com - Twitter [@rstudio](https://twitter.com/rstudio) Github [@rstudio](https://github.com/rstudio)