4

I have a .Rmd file (say it's called "file.Rmd") that I would like to knit into a pdf by pressing the "Knit" button in RStudio. However, it yields an error because I can't figure out how to specify a value for intermediates_dir in the render function (for some reason I need to do this in the C drive).

Note that this works fine:

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

Is there a way to tell RStudio to knit using intermediates_dir = "C:/")?

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
user1713174
  • 307
  • 2
  • 7

1 Answers1

3

You can use a custom knitting function in the knit field in the YAML frontmatter, e.g.,

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

Then when you press the Knit button in RStudio, this custom function will be called to render your Rmd document. For more info, see https://bookdown.org/yihui/rmarkdown-cookbook/custom-knit.html.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Wow, great! Didn´t know that! – J_F Mar 19 '20 at 17:06
  • Oh, what a nice and simple solution! Thank you! For some bizarre reason (to me, anyway) adding that YAML line crashes the knitr call if the code contains a call of the `source` function -- the document knits nicely when that `source` call is removed! Cool beans. Much appreciated. – user1713174 Mar 19 '20 at 21:56