在我的 yaml 调用中我有
---
title: "`r paste0('Test. Done ', format(Sys.Date(), '%B-%Y'))`"
output:
word_document:
fig_caption: yes
fig_height: 4
fig_width: 7
reference_docx: %userprofile%\Documents\template.docx
---
但 YAML 抱怨%userprofile%
。是否可以包含这样的变量?
我已经尝试过例如
reference_docx: "`r file.path(path.expand('~'), 'skabelon.docx')`"
但这仍然会导致此 YAML 错误。
pandoc.exe: `r file.path(path.expand('~'), 'skabelon.docx')`: openBinaryFile: does not exist (No such file or directory)
我猜这意味着 r 表达式在 yaml 之前没有被处理?我已经检查过该文件是否在那里...或者是因为 pandoc 正在使用另一个“用户配置文件”?我怎样才能检查这个?
但是我可以在Title
变量,根据上面更新的标题。我想这一定是一个特定的针织问题。
问题是参数中output
字段只能理解为降价。 Pandoc 不理解它们,所以你需要确保降价可以评估表达式。自从降价使用yaml包来读取 YAML 元数据,以及yamlR 表达式的语法是!expr
,您可以将 R 表达式放在!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')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)