Quarto options

Chunk options

In your Quarto document, you had a chunk:

```{r}
#| echo: false
2 * 2
```

#| echo: false tells knitr not to show the code within that chunk

Without the | this would just be a comment, and spacing/position (at the top of the chunk) is important!

Chunk options

Some of the ones I find myself using most often:

  • #| eval: false: Don’t evaluate this chunk! Really helpful if you’re trying to isolate an error, or have a chunk that takes a long time
  • #| error: true: Render this even if the chunk causes an error
  • #| cache: true: Store the results of this chunk so that it doesn’t need to re-run every time, as long as there are no changes
  • #| warning: false: Don’t print warnings
  • #| message: false: Don’t print messages

Document options

You can tell the entire document not to evaluate or print code (so just include the text!) at the top:

my-document.qmd

---
title: "My document"
author: Louisa Smith
format: html
execute:
  eval: false
  echo: false
---

Careful! YAML is really picky about spacing, so I recommend copying and pasting from an example you know works.

Allow errors

Sometimes it can be hard to pinpoint errors during the rendering process.

When people are starting out with quarto, I often recommend setting the whole document to

execute:
  error: true

But then you have to remember to read the document for errors!

Render as you go

Rendering starts a fresh R session. Your document has to build using only what’s in it – not the objects sitting in your environment.

Run the chunks top to bottom as you go, but also stop to render occasionally to make sure everything is working.

Tip

This is the single best check on any code, whether you’ve written it, but especially if you’ve copied it from somewhere else, including another file or elsewhere in the same script.

Document options

There are lots of different options for the document

  • For example, you can choose a theme:

my-document.qmd

---
format:
  html:
    theme: yeti
---
  • Remember the pickiness: when you have a format option, html: moves to a new indented line and the options are indented 2 more spaces

Exercises

Download the quarto document with some {gtsummary} tables from yesterday

  • Change some options to hide code and output
  • Add another code chunk
  • Play with themes
  • Deal with errors
  • Add some text