try_either | R Documentation |
Try and catch_either.
try_either(expr, alt_value, catchfn = NULL, silent = TRUE)
expr |
Function which should be executed. |
alt_value |
return value when expr throw exception. |
catchfn |
Function which will be called when expr throw exception with error message as argument. |
silent |
Logical value: if TRUE, the error message is not shown. |
f = function(i){
if(i<0)stop("negative value")
return(i)
}
x = try_either(f(3),NULL)
#x == 3
a = try_either(f(-1),NULL)
#a == NULL
b = try_either(f(-1),0)
#b == 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.