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. Thanks, Elizabeth
On Mon, 27 Feb 2006, Elizabeth Purdom 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.The usual way is to put the erroneous command inside try(), and mix blocks with echo=FALSE or TRUE and cat() of the object returned by try() of your command. See: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/60984.html for an example.> > Thanks, > Elizabeth > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
>>>>> 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