我有一个带参数的Quarto文档,并且想要自动化渲染并在YAML中使用其中一些参数与
我尝试了在RMarkdown中有效的解决方案(here),但在Quarto中却没有成功,因为在Quarto的YAML中使用时,键
我也尝试了键
尝试在最后的YAML中使用
因此,如果可能的话,我想通过在YAML中添加相关代码来自动化生成HTML文件名。非常感谢您的帮助!
Sys.Date()
一起命名生成的html文件,以便每次渲染Quarto文档时,输出的html文件不会覆盖之前的文件。我尝试了在RMarkdown中有效的解决方案(here),但在Quarto中却没有成功,因为在Quarto的YAML中使用时,键
Knit
似乎不存在,所以html文件与.qmd文件具有相同的名称。以下是我根据上述链接尝试的最简示例。---
title: "Example"
author: "Anthony"
date: "`r Sys.Date()`"
output: html_document
params:
variable: "var1"
knit: >
(function(input_file, encoding) {
metadata <- rmarkdown::yaml_front_matter(input_file)
output_file <- with(metadata, paste0(title,"_",params$variable, "_", author, "_",date))
rmarkdown::render(input = input_file, output_file = output_file)
---
我也尝试了键
output-file
和output-ext
,如这里所示,用于quarto文档,但它只能用于没有代码外观的字符串,所以下面的YAML也不起作用。---
params:
variable = "variable1"
format:
html:
output-file: "`r paste0("file_name","_",params$variable)`"
output-ext: "html"
title: "Testing Output filename"
---
尝试在最后的YAML中使用
output-file: "File {{< meta params.variable>}}"
也没有起作用(尽管在title:
键中使用这种方法是有效的)。因此,如果可能的话,我想通过在YAML中添加相关代码来自动化生成HTML文件名。非常感谢您的帮助!