title: choose working directory in code option of r chunk
body: <p>So I am using RMarkdown and I am sourcing code from a script contained in a separate folder (Scripts) at the same level as the folder which contains the Markdown file (Report). Both directories are at the root of the R project.</p>
  <p>I achieve that first by setting the working directly using the following code in the setup chunk:</p>
  <pre><code>knitr::opts_knit$set(root.dir = normalizePath(&quot;..&quot;))
  </code></pre>
  <p>Then calling the following in a R chunk:</p>
  <pre><code>```{r datacreation, echo = FALSE}
  source(&quot;./Scripts/20212022Summary.R&quot;)
  ```
  </code></pre>
  <p>All that is great but I also want to display later on in the knitted document, the whole code contained in that script so it can be reviewed if necessary.</p>
  <p>To achieve this, I do :</p>
  <pre><code>```{r 20212022Summary_readlinesversion, code = readLines(&quot;../Scripts/20212022Summary.R&quot;),echo=TRUE,include = knitr::is_html_output(),cache=FALSE,eval = FALSE}```
  </code></pre>
  <p>Which just shows the code without running it, with a nice formatting.</p>
  <p>What I would like to know is how I would go about defining once and for all what is my working directory for consistency sake. Specifically when I call code = readLines(&quot;../Scripts/20212022Summary.R&quot;) I clearly operate with the knowledge it will consider the working directory to be the one containing the report instead of the one (parent directly aka project root directory) which I defined previously in the set up chunk.</p>
  <p>Ideally I would define things once and for all, especially as then I could pick those up programmatically and source from anywhere within the project folder, consistently.</p>
  <p>Anyone has tips on how to achieve this? What I have done works, it's just ugly, manual and not consistent. And it bugs me :)</p>