且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在YAML中使用R代码或Windows用户变量(“%userprofile%")?

更新时间:2023-10-25 17:27:04

问题是output字段中的参数只能由 rmarkdown 理解. Pandoc无法理解它们,因此您需要确保 rmarkdown 可以评估该表达式.由于 rmarkdown 使用 yaml 包读取YAML元数据,并且 yaml 的R表达式语法为!expr,因此您可以将!expr之后的R表达式,例如

The problem is that the parameters in the output field is only understood by rmarkdown. Pandoc does not understand them, so you need to make sure rmarkdown can evaluate the expression. Since rmarkdown uses the yaml package to read the YAML metadata, and yaml's syntax for R expressions is !expr, you can put the R expression after !expr, e.g.

output:
  word_document:
    fig_caption: yes
    fig_height: 4
    fig_width: 7
    reference_docx: !expr file.path(Sys.getenv('USERPROFILE'), 'Documents', 'template.docx')