4

Update:

@harre. I encountered an issue.

It works perfect with mtcars dataset.

But when I try to use a loaded dataframe it says:

Fehler in nrow(df_xxx) : Objekt 'df_xxx' nicht gefunden
Ruft auf: paste -> nrow
Fehler in yaml::yaml.load(meta, eval.expr = TRUE) : 
  Could not evaluate expression: paste(nrow(df_xxx), "blabla")
Ruft auf: .main ... FUN -> parse_block -> partition_chunk -> <Anonymous>
Ausf�hrung angehalten

It seems that quarto looks first #|... in this case df_xxx is not generated. Although it is in the environment we have no access to it. Any idea?

Original question: This is a working quarto exmple:

---
title: "test"
format: revealjs
---

## Quarto example


```{r}
#| label: fig-plot_mtcars
#| fig-cap: nrow(mtcars).

plot(mtcars$mpg, mtcars$disp)
```

output:

enter image description here

How can I add a inline code to fig.cap:: desired output: enter image description here

I have tried with #| fig-cap: paste("bla", nrow(mtcars))

TarJae
  • 72,363
  • 6
  • 19
  • 66

1 Answers1

10

You'll need to tell the quarto YAML that you're parsing an R expression to be evaluated. I.e.:

#| fig-cap: !expr nrow(mtcars)

For reference, see:

https://quarto.org/docs/computations/r.html#chunk-options

harre
  • 7,081
  • 2
  • 16
  • 28
  • 3
    Have you loaded the dataset df_xxx within a block in the quarto document? Markdown documents won't load from your environment. – harre Jun 12 '22 at 14:12
  • can you explain more about your comment? Can you point me to a reference or describe in more detail how one would go about implementing your suggestion? Thanks! – StatsStudent Aug 09 '23 at 18:40