title: Using both in_header and header_includes in Rmarkdown and knitr
body: <p>I have a long .txt file that contains packages and settings that I want to used in my Rmarkdown file. I also want to add statements to the header, based on the output of R calculations. In this particular case I want to add a titlegraphic that is located in another directory, like this:</p>
  
  <pre><code>working directory
  |--- reports
  |----| my_report.Rmd
  |--- www
  |----| image.png
  </code></pre>
  
  <p>So the header of the Rmarkdown file would look like:</p>
  
  <pre><code>output:
    beamer_presentation:
      keep_tex: true
      includes:
        in_header: header.txt
  header-includes:
  - \titlegraphic{\includegraphics[width=0.3\paperwidth]{`r paste0("dirname(getwd()),"image.png")`}}
  </code></pre>
  
  <p>If only one of the statements is included (in_header or header-includes), they work fine. But when I use them both, <strong>the content of header-includes seems to be overwritten</strong>. An example is given in the files below, where upon inspecting the resulting .tex file, I find that <code>\usepackage{fancyhdr}</code> is in the header, but there is no mention of the `\titlegraphic' expression. </p>
  
  <hr>
  
  <p>header.txt</p>
  
  <pre><code>\usepackage{fancyhdr}
  </code></pre>
  
  <hr>
  
  <p>example.Rmd</p>
  
  <pre><code>title: Example 1
  output:
    beamer_presentation:
      keep_tex: true
      includes:
        in_header: header.txt
  header-includes:
        \titlegraphic{\includegraphics[width=0.3\paperwidth]{`r paste0("just_an_example_","logo.png")`}}
  ---
  
  ### This is a test
  </code></pre>