title: How can I force knitr to input a tikzpicture directly?
body: <p>My aim is to produce a document by mixing hand-written .tex files and .tex files generated from an Rmarkdown file using knitr with figures rendered as tikzpicture.</p>
  
  <p>How do I achieve the generated .tex file to simply contain</p>
  
  <pre><code>\begin{figure}
    \input{unnamed-chunk-1-1.tex}
  \end{figure}
  </code></pre>
  
  <p>I am struggling with tikz as device. I tried the <code>tikzDevice</code> library as well as <code>knitr::opts_chunk$set(dev="tikz")</code> I managed to create a .tex file with a tikzpicture environment for every chunk. Unfortunately knitr rendered said .tex file to pdf and generated an <code>\includegraphics</code> command. The most annoying problem with that is, I need to copy-paste my header into <code>options(tikzLatexPackages)</code> redundantly or "TeX is unable to calculate metrics".</p>
  
  <p>Additionally I did not manage to put the graphics into a <code>figure</code> environment. If I simply enclose the chunk with <code>\begin{figure}</code> and <code>\end{figure}</code>, it will not include the pdf at all anymore and replace the command with <code>![](figures/unnamed-chunk-1-1.pdf)&lt;!-- --&gt;</code>. </p>
  
  <p>After going through the Rmarkdown documentation, I tried setting the chunkoption <code>external=TRUE</code>, but that had  no effect. </p>
  
  <p>EDIT: The environment should be generated when setting the chunk option <code>fig.env='figure'</code>, but like <code>external=TRUE</code>, that had no effect on the generated .tex file.</p>