title: Using relative paths in Rmarkdown when knitting from two different locations
body: <p>My problem is with use of relative links and &quot;compiling&quot; (knitting).</p>
  <p>I'm writing a book using RMarkdown. Since the file will be relatively large, I need to split into subfiles and directories.</p>
  <p>I have a masterfile which only includes links to chapters(chap1, chap2, ...). There is a file for each chapter and each needs references to some figures (fig1,...).</p>
  <p>I would like to be able to knit masterfile.Rmd and chap1.Rmd independently from each others so to get one file for chapters, and one file for the whole book.</p>
  <p>Here is how my files are organized (MVE). Directories are displayed in upper case.</p>
  <ul>
  <li>ROOT
  <ul>
  <li>masterfile.Rmd</li>
  <li>FIGURES
  <ul>
  <li>fig1.pdf</li>
  <li>fig2.pdf</li>
  </ul>
  </li>
  <li>CHAPTERS
  <ul>
  <li>chap1.Rmd</li>
  <li>chap2.Rmd</li>
  <li>...</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <p>The code of masterfile.Rmd is as follows:</p>
  <pre><code>{r child = '/chapters/chap1.Rmd'}
  </code></pre>
  <p>The code of chap1.Rmd is as follows:</p>
  <pre><code>![](../figures/fig1.pdf)
  </code></pre>
  <p>As I knit from <code>chap1.Rmd</code>, everything is fine. As I knit from <code>masterfile</code>, I get the following message:</p>
  <p><em>[WARNING] Could not fetch resource '../figures/fig1.pdf': PandocResourceNotFound &quot;../figures/fig1.pdf&quot;</em></p>
  <p>It seems that <code>fig1.pdf</code> cannot be found. I guess that this is because the include statement in master file only &quot;copies&quot; the code of <code>chap1.Rmd</code> and &quot;executes&quot; it in the <code>ROOT</code> directory (not in the <code>CHAPTERS</code> directory) so &quot;..&quot; drives to location that does not exist (before ROOT) when knitted from <code>masterfile</code>.</p>
  <p>I could change the setting and write <code>![](/figures/fig1.pdf)</code> in <code>chap1.Rmd</code> file. It would work fine when knitting from <code>masterfile</code> but no longer from <code>chap1.Rmd</code>.</p>
  <p>Do you know how to have both?</p>