From seth at userprimary.net  Fri Nov 13 18:12:38 2009
From: seth at userprimary.net (Seth Falcon)
Date: Fri, 13 Nov 2009 09:12:38 -0800
Subject: [Rd] error checks
In-Reply-To: <4AFD8321.7030107@acm.org>
References: <1258123410.17658.6.camel@punchbuggy> <4AFD8321.7030107@acm.org>
Message-ID: <4AFD9386.6010002@userprimary.net>

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
stopifnot(res)

+ seth

-- 
Seth Falcon | @sfalcon | http://userprimary.net/users



[Rd] error checks
Seth Falcon