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

Every time I run the code below, it runs without error. It is only when I try to sweave the output in the last frame requested does it fail. What's more confusing to a LaTeX/Sweaving newbie like myself is that I paste the xtable(....) function into another R session, it produces LaTeX output to my output window. I even pasted the generated LaTeX output back into my document as a new slide and it worked swimmingly.

Any help you can provide will be greatly appreciated.

%\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry} %set the margins

% before compiling, need to change working directory in open version of R

<<echo=FALSE, eval=TRUE>>=
    Aye <- sample(c("Yes", "Si", "Oui"), 177, replace = TRUE)
    Bee <- sample(c("Hum", "Buzz"), 177, replace = TRUE)
    Sea <- sample(c("White", "Black", "Red", "Dead"), 177, replace = TRUE)


\frametitle{First Slide}
Contents of the first slide

\frametitle{Second Slide}
    xtable(format(addmargins(table(Aye, Sea))))


share|improve this question
up vote 4 down vote accepted

Although you didn't tell us what error you are getting, and what exactly you want to achieve, I believe that the problem is that Sweave tries to include the R output in the tex file verbatim. Beamer does not like verbatim in frames, and throws an error.

Change the <<>>= to <<echo=false, results=tex>> if you want to include the table in the frame.

If you do want to include the LaTeX code tor the table verbatim, you have to make the frame "fragile", so it will accommodate the verbatim environment inserted by Sweave.

share|improve this answer

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.