[R] Question about Sweave

Friedrich.Leisch@tuwien.ac.at Friedrich.Leisch at tuwien.ac.at
Tue Feb 28 09:03:45 CET 2006


>>>>> On Mon, 27 Feb 2006 11:34:00 -0800,
>>>>> Elizabeth Purdom (EP) wrote:

  > Hi,
  > I'm not sure if Sweave questions should go to the general list, but it 
  > seems to be part of the core R package without a separate maintainer.

  > I am writing a tutorial for R in a latex file. I'd like to use Sweave, 
  > since this seems its ideal usage. The problem is that I want to 
  > purposefully put errors in and then the output that comes with it in the 
  > text of my tutorial. However the errors kill the function Sweave() in R 
  > when what I would like is for Sweave to just run it and include the error 
  > message as part of the output.

  > I have set options(error=NULL). It doesn't seem that the error options 
  > would affect Sweave in the right way, since an error in my .Rnw file causes 
  > an error in Sweave() itself, not just in the processing of the code, but 
  > maybe there's an error-handling system I don't know about that would do it. 
  > (I tried error=expression(NULL) but Sweave couldn't finish regardless). I 
  > don't see any options in the documentation of Sweave that allow this 
  > behavior, either.

There is no direct support, but fortunately R is a full-featured
programming language ;-)

I usually do something along the lines of

**********************************************************

\documentclass[a4paper]{article}

\begin{document}

<<errchunk,eval=false>>=
x=sin("a")
<<echo=false>>=
cat(try({
<<errchunk>>
}))
@ 

\end{document}

**********************************************************

which of course only helps if you know where the error will happen,
but in your application this seems to be the case.

Best,
Fritz Leisch

-- 
-----------------------------------------------------------------------
Friedrich Leisch 

Institut für Statistik                          Tel: (+49 89) 2180 3165
Ludwig-Maximilians-Universität                  Fax: (+49 89) 2180 5308
Akademiestraße 1
D-80799 München                      http://www.ci.tuwien.ac.at/~leisch




More information about the R-help mailing list