5

Is there a way to reproduce the functionality of knitr::opts_knit$set(root.dir = '/path/to/dir') from Rmarkdown (which does work in Quarto as well, when ran from a chunk) but straight from the YAML block? Something like:

---
knitr:
  options:
    root.dir: "/path/to/dir"
---

(I've tried it, and also substituting options with opts_knit, and it doesn't work either way.

Thank you!

Dijkie85
  • 1,036
  • 8
  • 21
  • Alternative option could be using [quarto project](https://quarto.org/docs/tools/rstudio.html#projects) with [`execute_dir`](https://quarto.org/docs/projects/code-execution.html#working-dir) option set as "project" and with `{here}` package and [see this related answer](https://stackoverflow.com/a/73244900/10858321) – shafee Sep 06 '22 at 05:31
  • 2
    @shafee that works only when rendering the final document. But not when interactively executing chunks in a Qmd document (ie., using it as an R Notebook) – Dijkie85 Sep 06 '22 at 14:06
  • Can you add the code that worked (i.e. code of using `opts_knit` in a chunk) – shafee Sep 06 '22 at 14:40
  • @shafee I posted it in the OP: `knitr::opts_knit$set(root.dir = '/path/to/dir')` – Dijkie85 Sep 06 '22 at 18:44
  • 1
    Yes, I saw that, but wondering if that code worked by specifying once in the setup chunk then why you would want that thing in yaml? I mean in both cases you have to specify it only once. – shafee Sep 06 '22 at 18:57
  • That's true, but the YAML version would be way more idiomatic and easy to remember. The current working method looks a bit hacky and against Quarto principles, which are based on hassle-free reproducible research. Doc configuration belong in the YAML block, not in a code chunk. – Dijkie85 Sep 07 '22 at 19:30

0 Answers0