View source: R/uniroot_noerr.R
uniroot_noerr | R Documentation |
Runs the uniroot
root finding algorithm and returns NULL
instead of erroring if no solution is found.
uniroot_noerr(f, interval, ...)
f |
The function whose roots to find (must have one argument only) |
interval |
The range within which to search for a root |
... |
Additional parameters for |
The uniroot
function errors if no solution is found, which
is undesirable when looking for multiple roots across a range, or when
looking for roots as part of a bigger pipeline. This function catches the
error produced by uniroot
if no solution is found and returns
NULL
instead.
A root, or NULL
uniroot
f <- function(x) x^2 - 1
uniroot_noerr(f, c(-50, -30))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.