Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

\documentclass{beamer}
\usepackage[OT1]{fontenc}
%\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry} %set the margins
\usepackage{Sweave}

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

<<echo=FALSE, eval=TRUE>>=
    library(xtable)
    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)
@


\begin{document}  


\begin{frame}
\frametitle{First Slide}
Contents of the first slide
\end{frame}

\begin{frame}
\frametitle{Second Slide}
<<>>=
    xtable(format(addmargins(table(Aye, Sea))))
@

\end{frame}


\end{document}
share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.