Skip to content

Instantly share code, notes, and snippets.

@casallas
Created May 13, 2014 23:30
Show Gist options
  • Save casallas/a44c4c55ec5f0db03361 to your computer and use it in GitHub Desktop.
Save casallas/a44c4c55ec5f0db03361 to your computer and use it in GitHub Desktop.
knitr include (not input) child
This chunk below is from the child document.
<<set-parent, echo=FALSE, cache=FALSE>>=
if(!exists("master_mode")) master_mode <- F
if(!master_mode)
knitr::set_parent('knitr-include.Rnw')
@
<<test-child, out.width='2in', fig.show='asis'>>=
1+1
rnorm(5)
plot(1)
boxplot(1:10)
str(mtcars)
@
\documentclass{article}
\begin{document}
<<test-main>>=
options(width = 60)
summary(iris)
@
Let's see how to work with child documents in knitr. Below we include
the file \textsf{knitr-include-child.Rnw}:
<<child-demo, echo=FALSE, warning=FALSE>>=
master_mode <- T
knitr::knit("knitr-include-child.Rnw", "knitr-include-child.tex")
#cat("\\input{knitr-include-child}")# Add results='asis' to the chunk options
@
\input{knitr-include-child}
Done!
Modified from: http://yihui.name/knitr/demo/child/
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment