python - Quarto 图形标题中的引用参数

标签 python r quarto

有没有办法在四开本图形或表格标题中引用参数?在下面的示例中,我可以在常规文本 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)
    ```

-输出

enter image description here


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

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

关于python - Quarto 图形标题中的引用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74619283/

相关文章:

Python爬取表格元素

python - Pipenv 无法正确解析列出的两个来源的依赖关系

python - 在 or 条件下运行时如何使用 pyspark

python - 在四开本中并排显示 R 和 Python 绘图

python - 克服 python 中的 appengine 500 字节字符串限制?考虑文本

r - 晶格中具有不同 y 轴比例的多个面板的尺寸相同

r - 在 igraph 中创建新度量

c++ - Rcpp/RcppArmadillo C++/R 平衡性能

r-markdown - 如何在 Quarto -> HTML 中并排放置*多个*代码块?

r - 在 Quarto/Rmarkdown 中包含透明 ggplot,无需保存到磁盘