2
votes

I don't want to use knitr-chunks directly in my global tex-file. This file has of course \documentclass \begin{document} etc.

I want to do the knitr-stuff on sub-files and include the knitr-generatet tex-files then with \input into my global tex-file. This make it easier for me to manage and control my code.

<<example.Rnw>>
x <- 7
x
@

Running knitr() on this produces code that can not be build with xelatex.

I know from examples that knitr() normaly add a lot of new definitions between \documentclass and \begin{document}.

How could I handle this an elegant way with my sub-tex files?

Of course a workaround could be just to copy the relevant code in the header to my global document. But I don't know if this code would changed by knitr() depending on the code-chunk.

1
If I understand correctly, another way would be to source a R script at the beginning of the document and use the results in appropriate sub-files.Roman Luštrik

1 Answers

0
votes

See ?knitr::knit_child and the web documentation http://yihui.name/knitr/demo/child/