I am new to RNW files, and I am not sure if the following is possible. Suppose that I have the following RNW file:

\usepackage{amsmath}         % Math

<<label=1,echo=FALSE,fig=FALSE, results=hide>>=



\section*{Section 1} %this section is always needed 

Some text here (with graphs and R code).

\section*{Section 2} %this section is only needed if num_sections=2

Some more text here (with graphs and R code).


I always want section 1 in my document. However, I only want section 2 if num_sections==2. Is it possible? Within each section there might not only be text, but also figures or R code in <<>>=. Thanks!


Browse other questions tagged or ask your own question.