【问题标题】:Is there a way to specify intermediates_dir for the Knit button in RStudio?有没有办法为 RStudio 中的 Knit 按钮指定 intermediates_dir?
【发布时间】:2020-06-30 04:57:19
【问题描述】:

我有一个 .Rmd 文件(比如说它称为“file.Rmd”),我想通过按 RStudio 中的“编织”按钮将其编织成 pdf。但是,它会产生错误,因为我不知道如何在 render 函数中为 intermediates_dir 指定值(出于某种原因,我需要在 C 驱动器中执行此操作)。

请注意,这可以正常工作:

rmarkdown::render(file.Rmd, intermediates_dir = "C:/")

有没有办法告诉 RStudio 使用 intermediates_dir = "C:/") 编织?

【问题讨论】:

    标签: r rstudio r-markdown knitr


    【解决方案1】:

    您可以在 YAML frontmatter 的 knit 字段中使用自定义编织功能,例如,

    ---
    knit: (function(inputFile, encoding) {
        rmarkdown::render(inputFile, intermediates_dir = "C:/")
      })
    ---
    

    然后当您在 RStudio 中按下 Knit 按钮时,将调用此自定义函数来渲染您的 Rmd 文档。如需更多信息,请参阅https://bookdown.org/yihui/rmarkdown-cookbook/custom-knit.html

    【讨论】:

    • 哇,太好了!不知道!
    • 哦,多么好的简单解决方案啊!谢谢!出于某种奇怪的原因(对我来说,无论如何),如果代码包含对 source 函数的调用,则添加 YAML 行会使 knitr 调用崩溃——当删除 source 调用时,文档会很好地编织!凉豆。非常感谢。
    猜你喜欢
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    相关资源
    最近更新 更多