TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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}
share|improve this answer
So Sweave chunks can't be indented? Hmmm, this might be a problem for my OCD self. – Waldir Leoncio Jul 10 '13 at 11:49
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 Jul 10 '13 at 11:53
Oh, well. The important thing [fragile] did the trick. Thanks a bunch! – Waldir Leoncio Jul 10 '13 at 13:50
@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 Jul 10 '13 at 17:52
@Fran Thanks for the clarification. – Alan Munn Jul 10 '13 at 18:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.