Description Usage Arguments Details Value Note Examples
Sometimes evaluating a function in R at limit points does not give
the proper limit. eval_lims
manually evaluates the
desired function values at those limit points, and evaluates the function
normally otherwise.
1 |
fun |
Vectorized univariate function that you want to evaluate. Need not
evaluate to anything at points |
arg |
Vector of values to evaluate the function |
replx |
Vector of values for which to manually evaluate the function
|
replf |
Vector of values for which you want |
... |
Other arguments to pass to the function |
To preserve vectorization over the ...
arguments, the vectors/lists
input here that match the length of arg
are subsetted to match those
arguments in arg
that are not the special values replx
.
Vector of evaluations of the function fun
at arg
.
Any NA
's that appear in arg
will be returned as
NA
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ## The function we want to evaluate, and some arguments:
fun <- function(x, alpha=1) exp(-1/x)/x^alpha
arg <- c(0:5, NA)
## Should have fun(0)=0, but we get NaN:
fun(arg)
## Manually evaluate:
eval_lims(fun, arg, replx=0, replf=0)
## Try other alpha values:
fun(arg, alpha=5)
eval_lims(fun, arg, replx=0, replf=0, alpha=5)
fun(arg, alpha=1:7)
eval_lims(fun, arg, replx=0, replf=0, alpha=1:7)
## NaN and numeric(0) work as arguments too:
eval_lims(fun, numeric(0), replx=0, replf=0)
eval_lims(fun, NaN, replx=0, replf=0)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.