You should be able to provide some option to the chunk.
One of them is changing the template used - see this knitr example knitr-examples/058-engine-tikz.Rmd at master · yihui/knitr-examples · GitHub
You can pass some options to the engine by defining engine.opts
, e.g. use your own template instead of the default one to include the tikz code: engine.opts = list(template = "mytemplate.tex")
. The default template can be found under system.file('misc', 'tikz2pdf.tex', package = 'knitr')
.
Providing your own template would allow you to customize the content based on your external file.
Some chunk options are passed to the template and you may not it to provided your own:
-
classoption
passed to %% TIKZ_CLASSOPTION %%
: use that for passing class option to standalone
document class
-
extra.preamble
passed to %% EXTRA_TIKZ_PREAMBLE_CODE %%
: use to add any content in preamble. You can do extra.preamble = xfun::read_utf8("external.tex")
to read from an external file. Maybe that is what you look for.
Hope it helps