-
I'd like to run some R code in a figure caption. Something like
This is doable in R markdown, but quarto seems to error out due to the inline execution. Can I execute code in figure captions? If so, what is the right way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi, I don't think you can with the chunk option defined in body, since fig-cap must be a string.
|
Beta Was this translation helpful? Give feedback.
-
As documented, when using R, you need to use the ---
self-contained: true
format: html
---
```{r}
nsims <- 1000
x <- rnorm(nsims)
```
The following does not work with knitr/rmarkdown:
```{r}
#| fig-cap: !expr paste(nsims, "draws from a standard normal")
hist(x)
```
|
Beta Was this translation helpful? Give feedback.
As documented, when using R, you need to use the
!expr
syntax in YAML so that an evaluation happens before YAML parsinghttps://quarto.org/docs/computations/r.html#chunk-options