And*_*eas 6 yaml r user-profile knitr r-markdown
在我的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
---
Run Code Online (Sandbox Code Playgroud)
但YAML抱怨%userprofile%
.是否可以包含这样的变量?
我试过例如
reference_docx: "`r file.path(path.expand('~'), 'skabelon.docx')`"
Run Code Online (Sandbox Code Playgroud)
但这仍然会导致YAML错误.
pandoc.exe: `r file.path(path.expand('~'), 'skabelon.docx')`: openBinaryFile: does not exist (No such file or directory)
Run Code Online (Sandbox Code Playgroud)
我想这可能是在yaml之前没有处理r表达式吗?我已经检查过该文件是否存在...或者是因为pandoc正在使用另一个'userprofile'?我怎么检查这个?
然而Title
,根据上面更新的标题,我可以在变量中使用这样的调用.我想这一定是特定的针织问题.
问题是该output
字段中的参数仅由rmarkdown理解.Pandoc不理解它们,因此您需要确保rmarkdown可以评估表达式.由于rmarkdown使用yaml包来读取YAML元数据,并且yaml的R表达式的语法是!expr
,你可以将R表达式放在后面!expr
,例如
output:
word_document:
fig_caption: yes
fig_height: 4
fig_width: 7
reference_docx: !expr file.path(Sys.getenv('USERPROFILE'), 'Documents', 'template.docx')
Run Code Online (Sandbox Code Playgroud)