public
Created — forked from yihui/main.Rnw

use knit() with a loop to write reports for subsets of data

  • Download Gist
main.Rnw
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
\documentclass{article}
 
\begin{document}
 
<<run-all, results='hide', message=FALSE>>=
library(xtable)
out = NULL
for (g in unique(mtcars$gear)) {
out = c(out, knit_child('template.Rnw', sprintf('gear-%s.tex', g)))
}
<<write-results, echo=FALSE, results='asis'>>=
cat(out, sep = '\n')
@
 
\end{document}
template.Rnw
1 2 3 4 5 6 7 8 9 10 11
<<include=FALSE, cache=FALSE>>=
# make sure figure paths do not collide
opts_chunk$set(fig.path = paste('figure/gear', g, sep = ''))
@
 
\section{Cars with \Sexpr{g} gears}
 
<<results='asis'>>=
df = subset(mtcars, gear == g, 1:5)
print(xtable(df), floating = FALSE)
@

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.