On Wed, 7 Sep 2005, Douglas Bates wrote: > On 9/7/05, Doran, Harold <[EMAIL PROTECTED]> wrote: > > You could use <<eval=FALSE>>= and the code inside the chunk will not > > be evaluated. I suppose two other options could be to comment out the > > bad code inside the code chunk or to use verbatim to make it look like > > a code chunk in your output. > > > > > > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Vincent > > Goulet > > Sent: Wednesday, September 07, 2005 11:44 AM > > To: r-help@stat.math.ethz.ch > > Subject: [R] Avoid Sweave from stopping on errors > > > > Hi all, > > > > Is there an option in Sweave to avoid it from stopping on a code chunk > > with an error? (I purposefully want to include code with an error in > > class notes.) > > > > I suspect the answer is "no" and that I will be pointed to > > options("error"). That'd be fine, but which error parameter will just > > "do nothing" in case of an error? > > > > Thanks in advance! > > > > Another option is to wrap the call that will produce an error in > try(). You still get the error report, etc. but execution does not > stop.
This works very nicely for the original purposes, as the try() can be hidden and the command in error echoed: <<echo=TRUE,eval=TRUE>>= y <- rnorm(10) is.na(y) <- 1 y @ <<echo=TRUE,eval=FALSE>>= lm(y ~ 1, na.action=na.fail) @ <<echo=FALSE,eval=TRUE,results=verbatim>>= try_out <- try(lm(y ~ 1, na.action=na.fail)) cat(try_out) @ looks in output as it should, with the error message set after the command that provoked it. Sweave is a remarkable tool. -- 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: [EMAIL PROTECTED] ______________________________________________ R-help@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