class: center, middle, inverse, title-slide # Customizing R Markdown ## R-Ladies St. Louis
### Mine Çetinkaya-Rundel ###
bit.ly/custom-rmd-stl
--- class: middle, inverse # R ❤️ Markdown sitting in a tree # K-I-S-S-I-N-G --- ## What is Markdown? - Lightweight markup language with plain text formatting syntax - Designed so that it can be converted to HTML (and many other formats) <img src="images/markdown.png" title="On the left, a README written in markdown. On the right, the rendered version in HTML." alt="On the left, a README written in markdown. On the right, the rendered version in HTML." width="90%" /> --- ## What is R Markdown? - Markdown + R - Text + R code (in chunks) gets converted to text + R code + R output in HTML (and many other formats) <img src="images/simple-rmd.png" title="On the left, an R Markdown file. On the right, the rendered version in HTML." alt="On the left, an R Markdown file. On the right, the rendered version in HTML." width="90%" /> --- ## Options for hands on activities - Go to [bit.ly/custom-rmd-stl-cloud](https://bit.ly/custom-rmd-stl-cloud), create an account/log in, save a permanent copy of the project - Go to [github.com/rladiesstl/intro-meetup4-oct-2021/](https://github.com/rladiesstl/intro-meetup4-oct-2021/), clone the repo, follow along in `exercises/` --- background-image: url("images/amboseli-land.jpeg") background-size: cover ## demo: `01-rmd-simple.Rmd` <br><br><br><br><br> .midi[ .hand[follow along at] [bit.ly/custom-rmd-stl-cloud](https://bit.ly/custom-rmd-stl-cloud) ] --- class: middle, inverse # Aside: Visual editor --- ## Visual editor .pull-left[ - Visual editing for all of text, tables, lists, etc. - Support for citations - Cross-refs, footnotes, equations, LaTeX ] .pull-right[ - Real time spell-checking, outline navigation - Tight integration with source editing - Insert anything with catch-all `⌘ /` shortcut ] <img src="images/visual-editor.png" title="On the left, R Markdown file opened with the visual editor. On the right, the rendered version in HTML." alt="On the left, R Markdown file opened with the visual editor. On the right, the rendered version in HTML." width="90%" /> --- background-image: url("images/amboseli-land.jpeg") background-size: cover ## demo: `02-visual-editor.Rmd` <br><br><br><br><br> .midi[ .hand[follow along at] [bit.ly/custom-rmd-stl-cloud](https://bit.ly/custom-rmd-stl-cloud) ] --- class: middle, inverse # Customizing .brown[chunk options] --- ## Show / hide - `message = FALSE` and `warning = FALSE` to suppress messages and warnings (with caution!) - `error = TRUE` to knit despite an error - `include = FALSE` to run, but hide output, messages, warnings, etc. --- ## Chunk options for figures - Recommended chunk options: - `fig.retina = 3` - `out.width = "70%"` - `fig.width = 6` - `fig.asp = 0.618` - `fig.alt`: Alternative text - More on this: - [R for Data Science - Graphics for communication](https://r4ds.had.co.nz/graphics-for-communication.html) - [Tips and tricks for working with images and figures in R Markdown documents](https://www.zevross.com/blog/2017/06/19/tips-and-tricks-for-working-with-images-and-figures-in-r-markdown-documents/) --- ## Setting global options ```r knitr::opts_chunk$set( fig.retina = 3, out.width = "70%", fig.width = 6, fig.asp = 0.618 ) ``` --- background-image: url("images/amboseli-land.jpeg") background-size: cover ## demo: `03-chunk-options.Rmd` <br><br><br><br><br> .midi[ .hand[follow along at] [bit.ly/custom-rmd-stl-cloud](https://bit.ly/custom-rmd-stl-cloud) ] --- class: middle, inverse # Customizing .brown[output] --- ## Same input, different outputs with a simple change in the YAML ```r output: html_document output: pdf_document output: word_document output: tufte::tufte_html ... ``` --- background-image: url("images/amboseli-land.jpeg") background-size: cover ## demo: `04-outputs.Rmd` <br><br><br><br><br> .midi[ .hand[follow along at] [bit.ly/custom-rmd-stl-cloud](https://bit.ly/custom-rmd-stl-cloud) ] --- class: middle, inverse # Customizing .brown[theme] --- ## Change output options <img src="images/themes.png" title="Edit R Markdown document options window." alt="Edit R Markdown document options window." width="90%" /> --- ## bslib & thematic - [**bslib**](https://rstudio.github.io/bslib/): Tools for customizing [Bootstrap themes](https://getbootstrap.com/docs/4.6/getting-started/theming/) directly from R, making it much easier to customize the appearance of Shiny apps & R Markdown documents - [**thematic**](https://rstudio.github.io/thematic/): Simplified theming of ggplot2, lattice, and base R graphics, automatically styled in R Markdown documents (and Shiny apps, and in the RStudio IDE) --- background-image: url("images/amboseli-land.jpeg") background-size: cover ## demo: `05-theme.Rmd` <br><br><br><br><br> .midi[ .hand[follow along at] [bit.ly/custom-rmd-stl-cloud](https://bit.ly/custom-rmd-stl-cloud) ] --- class: middle, inverse # Customizing .brown[format] --- ## Same-ish source, different format Using R Markdown, you can write - books: **bookdown** - websites: **blogdown**, **distill**, **pkgdown** - slide decks: **xaringan** - dashboards: **flexdashboard** - ... --- <iframe src="https://app.sli.do/event/tvtffkpx" height="100%" width="100%" frameBorder="0" style="min-height: 560px;" title="Slido"></iframe> ```r countdown(minutes = 0, seconds = 30) ```
00
:
30
--- background-image: url("images/amboseli-land.jpeg") background-size: cover ## demo: `06-xaringan.Rmd` <br><br><br><br><br> .midi[ .hand[follow along at] [bit.ly/custom-rmd-stl-cloud](https://bit.ly/custom-rmd-stl-cloud) ] --- class: middle, inverse # Learn .brown[more] --- .center[ .midi[ [rmarkdown.rstudio.com/gallery.html](https://rmarkdown.rstudio.com/gallery.html) ] ] <img src="images/rmd-gallery.png" title="R Markdown Gallery." alt="R Markdown Gallery." width="90%" style="display: block; margin: auto;" /> --- .center[ .midi[ [rstudio.com/resources/cheatsheets/](https://www.rstudio.com/resources/cheatsheets/) ] ] <img src="images/cheatsheet.png" title="R Markdown cheat sheet." alt="R Markdown cheat sheet." width="90%" style="display: block; margin: auto;" /> --- ## Acknowledgements - RStudio R Markdown team + community - RStudio cheat sheets intern Averi Perny - Fernando Campos for the [**ramboseli**](https://github.com/amboseli/ramboseli) package (and Jenny Tung for the pointer!) --- class: middle, inverse .center[ .large[ .hand[ thank you! <br><br> [bit.ly/custom-rmd-stl](https://bit.ly/custom-rmd-stl) ] ] ]