【发布时间】:2019-03-14 22:22:20
【问题描述】:
我正在创建一个 R 包“mytemplate”,其中包含从rmarkdown::pdf_document 派生的 RMarkdown 格式(作为以报告为输出的 R 脚本函数,它调用 header.tex 文件):
report <- function() {
## location of resource files in the package
header <- system.file("resources/header.tex", package = "mytemplate")
## derives the style from default PDF template
rmarkdown::pdf_document(
latex_engine = "xelatex", fig_caption = FALSE,
includes = rmarkdown::includes(in_header = header)
)
}
在 header.tex 中,我使用 system.file() 检测到的图像文件,该文件位于 inst/ 包目录的 resources/ 文件夹中:
\usepackage{fancyhdr}
\thispagestyle{fancy}
\fancyhead[LC]{
\includegraphics{`r system.file("resources/cover.png", package = "mytemplate")`}
}
在我的包之外并在 .Rmd 文件中提供完整的 YAML 部分,pdf 呈现正常:
---
title: ""
output:
pdf_document:
latex_engine: xelatex
fig_caption: false
header-includes:
\usepackage{fancyhdr}
\thispagestyle{fancy}
\fancyhead[LC]{
\includegraphics{`r system.file("resources/cover.png", package = "mytemplate")`}
}
---
text
但安装后当我使用mytemplate::report作为RMarkdown输出时,我返回错误:
! LaTeX 错误:文件 ``r system.file("resources/cover.png", package = "mytemp 迟到")`' 未找到。
是在导致错误的 R 脚本中调用 header.tex,还是应该修改 header.tex 代码以及如何修改?
【问题讨论】:
标签: r latex yaml r-markdown