Ensures nonfailure and possibly finiteness of a function evaluation.
1 2 
f 
A function. 
fail.value.default 
Value that will be used as on failure of

protect
returns a function with arguments
1 2 
The ...
arguments are all passed through to the underlying
function f
, fail.value
contains the value to return in
the event of a failure (e.g., an error occuring). If finite
is
TRUE
, then fail.value
is also returned where the value
is NA
, NaN
or infinite.
Some functions, such as optim
with method
LBFGSB
(and therefore find.mle
), require that
every value is finite. Optimisation with these functions also
requires that the target functions to not generate errors.
protect
catches these issues, returning the value of
fail.value
instead.
No check is made that f
returns a single value, but it should.
Richard G. FitzJohn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.