# RNW, different sections depending on the value of a variable. Possible? [closed]

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

\documentclass[12pt,a4paper]{article}
\usepackage{Sweave}
\usepackage{amsmath}         % Math
\usepackage{longtable}
\usepackage{framed}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage[parfill]{parskip}

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

@

\begin{document}
\SweaveOpts{concordance=TRUE}

\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).

\end{document}

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!