5

I am trying to create a PDF book using Quarto. In particular, I want to know if there is a way to specify the global chunk options, which would be used for all the chunks in all the qmd pages. The global option is

echo = TRUE

(I think this syntax is in R Markdown, not Quarto.) But only for some code chunks in some of the pages, I want to hide the code (by setting echo = FALSE). How can I do this?

Eva
  • 663
  • 5
  • 13

1 Answers1

10

Setting Global Options

In quarto documents, books or presentation, to set options like echo, eval, warning, error, include, output globally, we need to specify them under execute yaml key.

So in quarto book, to set echo to true globally, we set echo: true under execute.

_quarto.yml

project:
  type: book
  
execute: 
  echo: true

book:
  title: "Quarto book"
  author: "Jane Doe"
  date: "8/7/2022"
  chapters:
    - index.qmd
    - intro.qmd
    - summary.qmd
    - references.qmd

bibliography: references.bib

format:
  pdf:
    documentclass: scrreprt

Setting local options

And setting these options locally (for some specific chunk in a specific qmd page) is same as r-markdown.

Say in my index.qmd, I can specify echo=FALSE for a chunk like this,

index.qmd

# Preface {.unnumbered}

This is a Quarto book.

To learn more about Quarto books visit <https://quarto.org/docs/books>.

```{r echo=FALSE}
1 + 1
```
shafee
  • 15,566
  • 3
  • 19
  • 47
  • I think the correct syntax for options in code cells (aka 'local options') in Quarto is starting each line with `#| `, for example: ```{r}\n #| echo: false\n 1 + 1\n ``` see: https://quarto.org/docs/reference/cells/cells-knitr.html – petzi Jun 07 '23 at 20:26