4
votes

Im trying to include some R results in a TeX document using RStudio. I have managed to get RStudio to generate, what to me looks to be, a fine tex file but it fails to compile the pdf.

I get errors returned saying ! Undefined control sequence. ' which seems to be returned due to the first lines of str(data) calls and the lines showing significance levels:

"! Undefined control sequence.
<argument> '
            data.frame':    1980 obs. of  5 variables:
l.39 'data.frame':  1980 obs. of  5 variables:

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined."

"! Undefined control sequence. <argument> 
Signif. codes:  0 '
                              ***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
l.95 ...**' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined."

Files with just the summary(data) for instance work fine

Looking around other mailing lists etc Ive seen that this could be because tex cannot find the Sweave package so have copied it to various locations (the same folder as the Rnw and tex files, and a directory without spaces in the path) and tried to rerun the file. Nothing seems to work.

Similarly, this doesnt work, but using summary(cars) instead of str(cars) does. This suggests to me that its something to do with the ' character.

\documentclass [a4paper]{article}
\usepackage{Sweave} 
\title {Sweave Example 1}
\author {Friedrich Leisch}
\begin {document}
\maketitle
In this example we embed parts of the examples from the
\texttt {kruskal.test} help page into a \ LaTeX {} document :
<<>>=
data ( cars )
str(cars)
@
\end{document}

(adapted from the sweave manual) Any ideas on what Im doing wrong?

Any suggestions would be much appreciated.

1

1 Answers

3
votes

Add the [noae] package option to your \usepackage{Sweave} statement.