Home > Blockchain >  YAML parser error when rendering Quarto document
YAML parser error when rendering Quarto document

Time:10-28

I was trying to re-render a Quarto document after adding some more code. The code previously rendered fine.

However, this time the render failed, with this error:

Error in yaml::yaml.load(meta, handlers = list(expr = parse_only)) : 
  Parser error: while parsing a block mapping at line 1, column 1 did not find expected key at line 2, column 27
Calls: .main ... FUN -> parse_block -> partition_chunk -> <Anonymous>
Execution halted

I thought this was referring to the YAML bit at the top, but I hadn't made any changes to that, and the document previously rendered fine. I simplified the YAML to the simplest case, but the error persisted.

---
title: "Test"
format: html
---

```{r}
#| label: tbl-exibble
#| tbl-cap: "Exibble Bla Bla")

gt::gt(exibble)
```

This was caused by a typo - I'm posting this and answering it here because I think the error message is not particularly helpful and it might mislead other people

CodePudding user response:

The bug lies in the table caption chunk option, not in the YAML block at the start.

I had an extra ) at the end of the line; this fixed it:

---
title: "Test"
format: html
---

```{r}
#| label: tbl-exibble
#| tbl-cap: "Exibble Bla Bla"

gt::gt(exibble)

So if you get YAML parser errors similar to mine, please check your YAML; not only in the top part of the Quarto document, but also in your chunk options.

CodePudding user response:

You do not even need ", e.g.

---
title: "Test"
format: html
---

```{r}
#| label: tbl-exibble
#| tbl-cap: Exibble Bla Bla)))))

gt::gt(mtcars)
```

enter image description here

inline code

---
title: "Test"
format: html
---

```{r}
#| label: tbl-exibble
#| tbl-cap: !expr paste0("mtcars")

gt::gt(mtcars)
```
  • Related