Inspired from one of Hadley's functions (in plyr or something?)
failWith(
default = NULL,
expr,
frame = parent.frame(),
message = geterrmessage(),
silent = FALSE,
file = stderr()
)
the value to return if expr
fails
the expression to take a shot at
the frame to evaluate the expression in
the error message to display if expr
fails. Deafults
to base::geterrmessage()
if TRUE
, sends the error message to msg()
where msg sends the message
the result of expr
if successful, otherwise default
value.
# look, this doesn't throw an error, it just returns NULL
x <- failWith(NULL, stop("no error, just NULL"), silent = TRUE)