我希望在我的R包中内置一个函数,允许用户在他们的rmarkdown的顶部放置一个use_style()
函数调用,当渲染到docx时,会将word文档格式化为软件包inst文件夹中的指定模板。
我知道如何按照here在yaml头中做到这一点,但不知道如何在r代码中做到这一点。
我希望在设置块中执行以下操作:
rmarkdown::word_document(reference_docx = "inst/styles/template.docx")
但这似乎行不通。有没有允许这样做的编织选项?
发布于 2018-06-03 10:19:19
解决方案是在inst中创建一个链接到文件的函数,该函数可以在yams header中调用。例如:
输出: pkgname::rmarkdown_template
rmarkdown_template <- function(template) {
# get the locations of resource files located within the package
file <- system.file(paste0("styles/",template,".docx"), package = "dfeR")
# call the base html_document function
rmarkdown::word_document(reference_docx = file)
}
https://stackoverflow.com/questions/50656245
复制