[Tex/LaTex] Looping a code-chunk in LaTeX

knitrsweave

I want to generate a report for three types of analysis I am performing. But each time when I perform the analysis it can happen that one or more than one type of analysis occur. I want to put condition in the report that will run the part of report according to the type of analysis performed. For each analysis I need to repeat the chunk say n times. I am stuck at writing a for loop for the code chunk.
'a' is a vector
eg code:

\myboolean\Sexpr{myboolean}
for(i in 1:n)
\section{Frequency Analysis}
<<for-loop>>=
print(a[i])
@

Best Answer

See https://gist.github.com/3145751 for an example with knitr. You cannot insert LaTeX into R code directly (it is not like PHP), but you can knit a child document for n times with different values of i.

Related Question