[R] Newbie help with Sweave *on Windows*

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Mar 26 07:52:27 CET 2008


I agree this is a LaTeX on Windows issue -- it is a shame that LaTex is 
unable to accept valid file paths on the platform it runs on (using \ as a 
path separator is also a problem).

I've changed 2.7.0-alpha to use the short path to Sweave.sty, as given by 
shortPathName() but with / as path separator.  That seems the magic needed 
to get at least MikTeX's executables to accept the path.

On Wed, 26 Mar 2008, Vincent Goulet wrote:

> Le mar. 25 mars à 10:19, Duncan Murdoch a écrit :
>
>> On 3/25/2008 10:06 AM, James W. MacDonald wrote:
>>> Hi Kevin,
>>>
>>> I usually install R in e.g., C:\R-2.6.2 to avoid such problems.
>>
>> Explicitly including
>>
>> \usepackage{Sweave}
>>
>> may also help, so that Sweave doesn't try to give an explicit path.
>> Then again, it may not, depending on which LaTeX you're using.  This
>> is
>> really a LaTeX problem, rather than an R problem:  different LaTeX
>> distributions keep changing the rules for how to specify include
>> directories.
>>
>> Duncan Murdoch
>
> I also explicitly include \usepackage{Sweave} in my Sweave documents,
> but in addition I put a copy of the Sweave.sty file in my local texmf
> tree. After updating the TeX database, TeX/LaTeX finds the package
> file without any problem.
>
> (Kevin: email off-list if you're not familiar with the concepts of
> "local texmf tree" and "updating the TeX database".)

You may well need to use 'personal' rather than 'local': the latter is 
usually read-only on shared installations.

>
> HTH
>
>>
>>
>>>
>>> Best,
>>>
>>> Jim
>>>
>>>
>>>
>>> Zembower, Kevin wrote:
>>>> Kevin, thanks for writing. Yes, sorry, I forgot to mention that
>>>> this is
>>>> a Windows XP Professional system running GNU Emacs 22.1.1
>>>> (i386-mingw-nt5.1.2600) from Vincent Goulet, and R 2.6.2 Windows
>>>> version. I pasted in the sessionInfo() output from ESS inside of
>>>> Emacs
>>>> to the end of this note.
>>>>
>>>> Was your TA successful in correcting this error? How? Should I
>>>> report
>>>> this to R-development as something worth fixing for the next
>>>> release?
>>>>
>>>> Thanks, again, for your response and advice.
>>>>
>>>> -Kevin
>>>>
>>>>
>>>>
>>>> -----Original Message-----
>>>> From: Kevin E. Thorpe [mailto:kevin.thorpe at utoronto.ca]
>>>> Sent: Monday, March 24, 2008 9:01 PM
>>>> To: Zembower, Kevin
>>>> Cc: r-help at stat.math.ethz.ch
>>>> Subject: Re: [R] Newbie help with Sweave
>>>>
>>>> Is this in a windows system?  A TA of mine was just getting the
>>>> exact
>>>> same message.  He tracked it down to the pathname for Sweave.sty
>>>> having
>>>> trouble with "Program Files" in the path.
>>>>
>>>> Kevin
>>>>
>>>> Zembower, Kevin wrote:
>>>>> 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}
>>>>
>>>>
>>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ---
>   Vincent Goulet, Associate Professor
>   École d'actuariat
>   Université Laval, Québec
>   Vincent.Goulet at act.ulaval.ca   http://vgoulet.act.ulaval.ca
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list