When to use YAML vs when to use setup code chunk

Thank you! Since we don't have the limit on the number of characters here, I can type out the characters that I wasn't able to finish on Twitter (which is why I strongly recommend asking questions on forums before trying Twitter):

The YAML approach allows you to set options globally for a specific output format, e.g.

html_document:
  fig_width: 10
pdf_document:
  fig_width: 5

The setup chunk approach sets chunk options globally for the document regardless of the output format, e.g.

```{r, setup}
knitr::opts_chunk$set(fig.width = 10)
```

unless you set the options conditionally, e.g. only for HTML output:

if (knitr::is_html_output()) knitr::opts_chunk$set(fig.width = 10)
3 Likes