Loops with captions with knitr
I am wondering if there is an easy way to produce a bunch of tables or graphics with variable captions in knitr . The only way I know is this: (simplified from https://github.com/yihui/knitr-examples/blob/master/075-knit-expand.Rnw ). But it is a drag to collect the output into src and then print it after the loop, because I want to write a function to produce such a loop from an arbitrary dataset. \documentclass{article} \title{Using knit\_expand() for templates} \author{Yihui Xie} \begin{document} \maketitle \tableofcontents <<lm-mtcars, tidy.opts=list(width.cutoff=55)>>= # the template tpl