[R] Newbie help with Sweave

Zembower, Kevin kzembowe at jhuccp.org
Mon Mar 24 21:14:40 CET 2008


I think I've gotten my Emacs/Sweave/R system set up correctly, thanks to
Vincent and Jim, but I haven't been successful getting my first document
produced. I'm trying to use one of Friedrich Leisch's examples,
http://www.ci.tuwien.ac.at/~leisch/Sweave/example-1.Snw. I cut and
pasted the text into a document sweaveexample.Rnw in Emacs. It seemed to
be processed successfully with R:
> Sweave("sweaveexample.Rnw")
Writing to file sweaveexample.tex
Processing code chunks ...

You can now run LaTeX on 'sweaveexample.tex'
>

However, when I try to open the file sweaveexample.tex and process it
with Latex in Emacs, I get this error:
ERROR: Missing \endcsname inserted.

--- TeX said ---
<to be read again> 
                   \protect 
l.7 \begin
          {document}
--- HELP ---
>From the .log file...

The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

I've tried a variety of examples, but the error messages are the same.

Can anyone point out my errors or mistakes? I've pasted in the full
files below. Thanks so much for your help and advice.

-Kevin

Kevin Zembower
Internet Services Group manager
Center for Communication Programs
Bloomberg School of Public Health
Johns Hopkins University
111 Market Place, Suite 310
Baltimore, Maryland  21202
410-659-6139 
==============================
sweaveexample.tex:
==============================
\documentclass[a4paper]{article}

\title{Sweave Example 1}
\author{Friedrich Leisch}

\usepackage{C:/PROGRA~1/R/R-26~1.2/share/texmf/Sweave}
\begin{document}

\maketitle

In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:

\begin{Schunk}
\begin{Sinput}
> data(airquality)
> library(ctest)
> kruskal.test(Ozone ~ Month, data = airquality)
\end{Sinput}
\begin{Soutput}
	Kruskal-Wallis rank sum test

data:  Ozone by Month 
Kruskal-Wallis chi-squared = 29.2666, df = 4, p-value = 6.901e-06
\end{Soutput}
\end{Schunk}
which shows that the location parameter of the Ozone 
distribution varies significantly from month to month. Finally we
include a boxplot of the data:

\begin{center}
\includegraphics{sweaveexample-002}
\end{center}

\end{document}
================================
sweaveexample.Rnw:
==============================
\documentclass[a4paper]{article}

\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(airquality)
library(ctest)
kruskal.test(Ozone ~ Month, data = airquality)
@
which shows that the location parameter of the Ozone 
distribution varies significantly from month to month. Finally we
include a boxplot of the data:

\begin{center}
<<fig=TRUE,echo=FALSE>>=
boxplot(Ozone ~ Month, data = airquality)
@
\end{center}

\end{document}



More information about the R-help mailing list