有没有办法在四开本图形或表格标题中引用参数?在下面的示例中,我可以在常规文本 block 中引用我的输入参数 txt
,但不能在图形标题中引用。在图标题中,仅显示原始文本:
---
title: "example"
format: html
params:
txt: "example"
---
## I can reference it in text
Here I can reference an input parameter: `r params$txt`
```{r}
#| label: fig-example
#| fig-cap: "Example: I cannot reference a parameter using `r params$txt` or params$txt."
plot(1:10, 1:10)
```
最佳答案
尝试使用 !expr
```{r}
#| label: fig-example
#| fig-cap: !expr params$txt
plot(1:10, 1:10)
```
-输出
如果我们需要添加一些文本,paste
或使用 glue
#| fig-cap: !expr glue::glue("This should be {params$txt}")
关于python - Quarto 图形标题中的引用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74619283/