【问题标题】:Setting word document reference knitr via code通过代码设置word文档参考knitr
【发布时间】:2018-06-02 11:03:52
【问题描述】:

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

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

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

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

但这似乎不起作用。是否有 knitr 选项允许这样做?

【问题讨论】:

    标签: r knitr


    【解决方案1】:

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

    输出: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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 2022-11-07
      相关资源
      最近更新 更多