I'm currently trying to automate a report-generating routine in R, and I imagine the best way to try this is through Sweave and beamerposter. The report should have one page with several sections in it, so I'm using one frame with several block environments inside it. The problem I'm having is with inserting Sweave-generated figures inside those blocks (or any Sweave code, for that matter). For example, this yields an error:

    1 + 1

From what I've read, block environments are supposed to contain only text, but I can't imagine another way to structure my report that would match my client's expectations (he want it to look as much as possible as their current Excel-generate report). So my primary question is: how can I insert Sweave code inside a block environment?

1 Answer 1


One problem of your MWE is that the both the start and end of the R chunk (<<>>= and @) are not at the beginning of the line.

Another problem is that you have to add the option [fragile] to the frame environment.

If you correct your both problems your example will work, also with figures if you provide the fig=T option, as in this example:


\begin{frame}[fragile]{This is a \texttt{fragile} frame}
\begin{block}{This is a R chunk}
\begin{block}{This is a small figure}
  • So Sweave chunks can't be indented? Hmmm, this might be a problem for my OCD self. Commented Jul 10, 2013 at 11:49
  • 2
    The R code itself can be indented; only the <<>>= and @ lines need to be flush, I think. (But the indentation won't show up in the displayed code.)
    – Alan Munn
    Commented Jul 10, 2013 at 11:53
  • Oh, well. The important thing [fragile] did the trick. Thanks a bunch! Commented Jul 10, 2013 at 13:50
  • 1
    @AlanMunn True. The code inside a R chunk in a noweb file can be formated as any independent R script. What is showed in the in the generated LaTeX file by default is not that code formated in any way, but the result of the executed code similarly as seen in a R console, that is, showing first an echo of each processed instruction preceded by >.
    – Fran
    Commented Jul 10, 2013 at 17:52
  • What does fragile do here? I would plus 10 if I could.
    – dayne
    Commented May 25, 2018 at 11:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .