四开图标题中的参考参数

Col*_*inB 2 python r quarto

有没有办法在四开图或表格标题中引用参数?在下面的示例中,我可以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)
```
Run Code Online (Sandbox Code Playgroud)

akr*_*run 6

尝试用!expr

   ```{r}
   #| label: fig-example
   #| fig-cap: !expr params$txt
   plot(1:10, 1:10)
    ```
Run Code Online (Sandbox Code Playgroud)

-输出

在此输入图像描述


如果我们需要添加一些文本,或者paste使用glue

#| fig-cap: !expr glue::glue("This should be {params$txt}")
Run Code Online (Sandbox Code Playgroud)

  • 使用“胶水”的解决方案效果非常好。谢谢你! (2认同)