【问题标题】:Set output_file in YAML在 YAML 中设置 output_file
【发布时间】:2019-12-26 09:31:55
【问题描述】:

当我使用这些 YAML 参数运行 render("test.Rmd") 时,输出仍然是 test.docx 而不是 teeeeeeeest.docx

---
title: "mytitle"
author: "Me, myself and I"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: word_document
output_file: "teeeeeeeest.docx"
---

但是,如果我在渲染函数中设置参数 (rmarkdown::render("test.Rmd", output_file = "teeeeeeeest.docx")),它可以正常工作。

是否可以在 YAML 标头中设置 output_file 参数?否则,我的目的是在使用 RStudio 编织时将当前日期包含在输出文件名中,我该怎么做?

【问题讨论】:

标签: r-markdown


【解决方案1】:

here 所示,可以通过自定义 YAML 标头中的 knit 函数来在 YAML 中设置输出文件名。为此,您只需要在标题中添加一个 'knit:' 钩子,例如在此示例中:

knit: (function(inputFile, encoding) { 
      rmarkdown::render(inputFile,
                    encoding=encoding, 
                    output_file='new_file_name.html')) })

【讨论】:

    猜你喜欢
    • 2017-12-21
    • 2014-09-15
    • 2022-06-27
    • 2012-12-05
    • 2018-12-18
    • 2020-08-08
    • 2021-01-22
    • 1970-01-01
    • 2015-04-27
    相关资源
    最近更新 更多