My document consists of several subfiles that are imported into my main. However, i would like to run code chunks with R output in each subfile before the document is stitched together by main.tex. I've tried several approaches, but LaTeX only recognizes each chunk in the subfiles as text and not sourcecode thus only gives me the plain text and not the content of the code. Is it possible to force LaTeX to run the underlying chunk?
TLDR question: Is it possible to run code chunks in subfiles?
E.g. I want to run the following code in a subfile, plot the plot in my main through my subfile.
<<echo=TRUE, cache=TRUE>>=
x = 1:10
plot(x)
@
EDIT:
main: main.Rtex
\documentclass{article}
\usepackage{subfiles}
\begin{document}
\subfile{sections/introduction}
\end{document}
subfile: sections/introduction.Rtex
\documentclass[../main.tex]{subfiles}
\begin{document}
<<echo=TRUE, cache=TRUE>>=
x = 1:10
plot(x)
@
\end{document}
\documentclass,\begin{document},\end{document}and loads the necessary packages to compile that document (but not more than that)? Additionally could you show us a minimal subfile or do those only contain the R code bits? – Skillmon Apr 11 '19 at 17:14subfilesisn't supported. You can however include another file containing R with<<child='sections/introduction.tex'>>=and in the next line@. Though you'll have to drop the\documentclass...,\begin{document}and\end{document}. Maybe someone else knows a way to make it work withsubfiles... And in Overleaf yourmain.texshould then be namedmain.Rtex. – Skillmon Apr 11 '19 at 22:36<<child='path/to/file'>>=approach allows for arbitrary TeX code in that file, not only R code. The error lines of LaTeX are pretty messed up with it though. – Skillmon Apr 12 '19 at 07:46