Re: [Rd] error checks

From: Seth Falcon <>
Date: Fri, 13 Nov 2009 09:12:38 -0800

On 11/13/09 8:02 AM, Tony Plate wrote:
> Putting options(error=function() NULL) at the start of the .R will let R
> CMD check continue with commands in a file after stop() is called. (Or
> anything other than the default options(error=NULL)).

But that's a rather heavy handed approach and could easily mask errors that you are not expecting.

Instead, how about using tryCatch so that you limit the errors that you trap and also can verify that an error was indeed trapped. Perhaps something like this:

f <- function(x) if (x) stop("crash!") else NULL

res <- tryCatch(

          f(TRUE)         # this will raise an error
          FALSE           # only get here if no error
          error = function(e) TRUE)

## verify we saw an error

+ seth

Seth Falcon | @sfalcon |

______________________________________________ mailing list
Received on Fri 13 Nov 2009 - 18:16:49 GMT

This archive was generated by hypermail 2.2.0 : Fri 13 Nov 2009 - 19:31:45 GMT