Modify a function so that it returns a default value when there is an error.

failwith(default = NULL, f, quiet = FALSE)

Arguments

default

default value

f

function

quiet

all error messages be suppressed?

Value

a function

See also

Examples

f <- function(x) if (x == 1) stop("Error!") else 1 if (FALSE) { f(1) f(2) } safef <- failwith(NULL, f) safef(1)
#> Error in f(...) : Error!
#> NULL
safef(2)
#> [1] 1