通过代码设置word文档参考编织器

时间:2018-06-02 11:03:53

标签: r knitr

我希望在我的R包中构建一个函数,允许用户在其rmarkdown的顶部放置一个use_style()函数调用,当渲染到docx时,将word文档格式化为指定的模板包inst文件夹。

我理解如何在yaml标头中按照here执行此操作,但无法在r代码中解决此问题。

我希望在设置块中执行以下操作:

rmarkdown::word_document(reference_docx = "inst/styles/template.docx")

但这似乎不起作用。是否有针织选项允许这个?

1 个答案:

答案 0 :(得分:0)

解决方案是创建一个链接到inst中的文件的函数,该函数可以在yams头中调用。 e.g。

输出: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)
}
相关问题