Equivalent of "throw" in R
Beyond the base functions that Dirk mentions:
The R.oo package has additional exception handling functionality, including a throw() function which is very useful. You can catch exceptions with the usual try or trycatch functions:
> try(throw("Division by zero.")); print("It's ok!");
Error: [2009-10-22 10:24:07] Exception: Division by zero.
[1] "It's ok!"
You can read more about it here: http://www1.maths.lth.se/help/R/R.oo/
See help(tryCatch)
:
Conditions are signaled by '
signalCondition
'. In addition, the
'stop
' and 'warning
' functions have been modified to also accept
condition arguments.
and later under 'See Also':
'
stop
' and 'warning
' signal conditions, and 'try
' is essentially a simplified version of 'tryCatch
'.
so you probably want stop
.
Simple example:
f <- function(a, b){
if (a == 0){
stop("error message")
}
}