class: center, middle, inverse, title-slide # New Packages in the R Markdown Ecosystem ## Creating Documents, Presentations, Papers, Dashboards, Books, and Websites ###
Yihui Xie, RStudio
### 2017/06/26 @ The Statistics in Marketing Section, ASA --- background-image: url(https://images.unsplash.com/photo-1428908728789-d2de25dbd4e2?dpr=2&auto=format&fit=crop&w=1500&h=1000&q=80&cs=tinysrgb&crop=) background-size: cover # Outline - Examples to show basic features of R Markdown - [**rticles**](https://github.com/rstudio/rticles): LaTeX journal articles - [**tufte**](https://github.com/rstudio/tufte): the Tufte style - [**flexdashboard**](https://github.com/rstudio/flexdashboard): HTML output with dashboard layouts - [**xaringan**](https://github.com/yihui/xaringan): using the JS slideshow library remark.js - [**bookdown**](https://github.com/rstudio/bookdown): write books with R Markdown - [**blogdown**](https://github.com/rstudio/blogdown): create websites with R Markdown --- class: middle, center # The rmarkdown Package # http://rmarkdown.rstudio.com --- # An R Markdown document --- title: "A Simple Regression" author: "Yihui Xie" output: html_document: toc: true --- We built a linear regression model. ```{r} fit <- lm(dist ~ speed, data = cars) b <- coef(fit) plot(fit) ``` 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. --- # The Knit button - It calls `rmarkdown::render()` - R Markdown ≈ knitr (R) + Pandoc (Markdown) - `rmarkdown::render()` ≈ `knitr::knit()` + a `system()` call to `pandoc` - R Markdown (`.Rmd`) -> `knit()` -> Markdown (`.md`) -> `pandoc` -> - `.html` - `.pdf` (LaTeX) - `.docx` - `.epub` - `.rtf` - ... --- .pull-left[ ![](https://raw.githubusercontent.com/yihui/knitr-talks/master/useR2014/images/grommit.jpg) - **knitr**: https://yihui.org/knitr - the most important page: https://yihui.org/knitr/options ] -- .pull-right[ ![the knitr book](https://db.yihui.org/imgur/yYw46aF.jpg) ] --- # Pandoc's Markdown - You should read the Pandoc Manual at least once to learn the possibilities of Pandoc's Markdown: http://pandoc.org/MANUAL.html#pandocs-markdown - Two major contributors of Pandoc: Markdown extensions, and multiple output formats --- # Examples of Documents and Presentations - Tables - Citations - Notebooks - Different language engines - Other issues? --- 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 # Extension Packages --- # rticles - The key idea: LaTeX templates for Pandoc (through the `template` argument of output format functions) - Currently supported journals: https://github.com/rstudio/rticles/tree/master/inst/rmarkdown/templates - Most rticles format functions just calls `rmarkdown::pdf_document()` and modifies the returned list (a natural hack), instead of using `rmarkdown::output_format()` --- # tufte - https://github.com/rstudio/tufte - History: originally `rmarkdown::tufte_handout` and only supports PDF articles - **tufte** extended the style to PDF books and HTML documents - Key pieces: - Tufte-LaTeX - Tufte-CSS - **knitr** output hooks --- # flexdashboard - https://github.com/rstudio/flexdashboard - Responsive and interactive dashboards --- background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg) background-position: 50% 70% background-size: 20% # xaringan - https://github.com/yihui/xaringan - Porting the JavaScript library remark.js for slideshows into R ??? A lot of cool things about remark.js: background images, alignment of elements, keyboard shortcuts, ... --- background-image: url('gif/karl-broman.jpeg') background-size: contain class: center, bottom, inverse # You only live once! ### [`yolo = TRUE`](https://twitter.com/_inundata/status/798970002992873472) ??? This is the Monalisa in rstats world! --- # bookdown - https://github.com/rstudio/bookdown - Organize multiple R Markdown documents into a "book" - Multiple output formats - Markdown extensions (figure/table numbers, equations, theorems, ...) - Slides: http://slides.yihui.org/2016-webinar-bookdown-Yihui-Xie.html - Video: https://www.rstudio.com/resources/webinars/introducing-bookdown/ --- # blogdown - https://github.com/rstudio/blogdown - Creating websites based on R Markdown and Hugo - Slides: https://slides.yihui.org/2017-rstudio-webinar-blogdown-Yihui-Xie.html - Video: https://www.rstudio.com/resources/webinars/introducing-blogdown/ --- 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)