Is there a way to specify intermediates_dir for the Knit button in RStudio?

Viewed 218

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:/")?

1 Answers

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.

Related