我有一个参数化的Quarto文档,并希望自动渲染,并使用YAML中的一些参数以及Sys.Date()
来命名生成的html文件,以便每次渲染Quarto文档时,输出的html文件不会覆盖前一个.
我在Quarto中try 了适用于RMarkdown显示here的解决方案,但没有成功,因为在Quarto中的YAML中使用键Knit
时似乎不存在,所以html使用与.qmd文件相同的名称.以下是我根据上面提到的链接try 的最小示例
---
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)
---
我还try 了用于Quarto文档的output-file
和output-ext
键(如图here所示),但它只能用于没有类似代码的字符串,因此下面的YAML也不起作用.
---
params:
variable = "variable1"
format:
html:
output-file: "`r paste0("file_name","_",params$variable)`"
output-ext: "html"
title: "Testing Output filename"
---
在上一个YAML中try output-file: "File {{< meta params.variable>}}"
也不起作用(尽管这种方法在title:
键中使用时确实有效).
因此,如果可能的话,我想通过在YAML中添加相关代码来自动生成html文件名.感谢您的帮助,谢谢!