Hi there,
I have a large report which I preparing using RMarkdown (specifically using {bookdown}
package but it is probably irrelevant to my question).
As it is large report, I'm using child Rmd documents to make it more manageable. I put my child Rmd's in subfolder to make it more organized (and to prevent {bookdown}
to use them as chapters of the report). In the first chunk of the child Rmd I'm setting a root.dir knitr::opts_knit$set(root.dir = dirname(dirname(getwd())))
which is main directory of the project 2 steps above the subfolder with child Rmd. It works fine when I knit or build a report, but I can't figure out how to set a working directory to play with the code in the "notebook" format (i.e. executing chunks one-by-one, editing, re-executing, etc.).
knitr::opts_knit$set(root.dir = dirname(dirname(getwd())))
does not affect working directory in such case while setwd()
works only for a chunk where it was called and reset for the all other chunks to the default (i.e. document directory):
The working directory was changed to XXXX inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.
setwd()
from the console does not work at all.
Any ideas how I can make it work without adding setwd()
in each chunk?