# [R] Sweave and optional document sections

Max Kuhn mxkuhn at gmail.com
Fri Mar 5 19:50:22 CET 2010

```That isn't hard to do with Sweave.

Within you if branch, you can have your code write out any markup you
choose (including \section). For figures, I would suggest writing the
image file "manually" (i.e with the code chunk option fig = FALSE) and
also write out the \includegraphics statements too.

With odfWeave, it is more difficult. Adding sections isn't obvious to
me, although odfCat might be able to do it. Figures are more
problematic. The way odfWeave works right now, whenever you use fig =
TRUE in the chunk, odfWeave sets up the figure environment in the
document (whether you produce an actual image or not). My recollection
was that there wasn't any way around this, but it's been a thorn in my
side for a while.

I suggest using LaTeX in the short term to do this.

Max

On Fri, Mar 5, 2010 at 12:55 PM, Aleksey Naumov <anaumov at gmail.com> wrote:
> Dear R and Sweave users,
>
> Is there a way to have optional sections in a Sweave-generated report
> document, complete with section header(s), text and code chunks? In other
> words, I'd like for my report to include or omit certain sections based on
> the data itself.
>
> For example, If I examine the input dataset early on in the report and set a
> variable has_daily_data = TRUE, then I'd like to have a section that looks
> at the daily data in detail, with subsections, text and code chunks. What
> facilities do I have in Sweave (or odfWeave) for that?
>
> Perhaps, for code chunks, I could wrap all the code inside in
> if(has_daily_data) {...}? What about inserting conditional text and
> sections? Would it make sense to split the document into subdocuments and
> somehow include the optional subdocuments only if needed? How would I go
>
> Would appreciate any pointers. Thank you,
> Aleksey
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help