Chapter 7 Uplevel
7.1 Adding output formats
You can also have more than one output format!
If no output options need to be specified, the output format needs to be suffixed by default
.
Your turn
Try adding html_document: default
as an additional output format.
7.2 Adding multiple YAML keys
Sometimes (but only sometimes), you may wish to have multiple items within a single YAML key. Let’s take the author
key for example, because you can have more than one author:
---
title: A compelling manuscript
author:
- Alison Hill
- Peter Higgins
output:
html_document:
toc: true
toc_float: true
---
Your turn
Try adding
7.3 Live preview without reknitting
Install the xaringan
package, which is for making slides using R Markdown. You could use it for this (I do!), but you can just install the package for a single useful Addin that will allow you to live preview any single R Markdown document with an HTML output format as you edit and save the changes.
After installing the package, be sure to restart your R session.
Then use the Addings drop-down menu in RStudio to “turn on” Infinite Moon Reader. Test it out by opening up first-look.Rmd
again, make a change to something, and click the save button in RStudio. Your live preview HTML output document should update immediately.
7.4 Beef up your YAML
ymlthis!
What happens if you want to add two possible output formats? You use your YAML- check out what happens to your knit button when working in RStudio if you update your YAML to look like this:
---
title: "Response and adverse events to chemotherapy: A mock study"
author:
- "Alison Hill, Ph.D."
- "Peter Higgins, MD, Ph.D."
output:
rmarkdown::html_document: default
distill::distill_article: default
---
TODO: show how to use ymlthis this add these output formats
7.5 Knit with parameters
7.6 Knit from the command line
Cover render()
here, and how it can override your YAML
7.7 Extend your R Markdown
There are multiple R Markdown “extension packages” which (once installed) give you even more output formats to choose from (like dashboards, slide presentations, books, and blogs).
The book you are reading is written using the bookdown package, with the bookdown::gitbook
output format.
Here are some packages you can experiment with to extend the output formats available to you for a single R Markdown document:
Package | = R Markdown + | New output format |
---|---|---|
rmarkdown |
Bootswatch CSS | rmarkdown::html_document |
flexdashboard |
flexbox CSS | flexdashboard::flex_dashboard |
xaringan |
remark.js | xaringan::moon_reader |
distill |
Distill CSS | distill::distill_article |
pagedown |
Paged.js / ReLaXedJS | pagedown::html_paged pagedown::html_resume + others |
7.8 R Markdown templates
Use by adding to YAML or knitting at the command line (recommend focusing on beefing up your YAML).
- rticles
- any package like
rmd4edu
- tufte::tufte_html
- distill::distill_article
If you want to add an additional output format without output options, then you need specify : default
.