eval_lims: Evaluate a function at limit points

Description Usage Arguments Details Value Note Examples

View source: R/eval_lims.R

Description

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.

Usage

1
eval_lims(fun, arg, replx, replf, ...)

Arguments

fun

Vectorized univariate function that you want to evaluate. Need not evaluate to anything at points replx.

arg

Vector of values to evaluate the function fun at.

replx

Vector of values for which to manually evaluate the function fun at.

replf

Vector of values for which you want replx to evaluate to.

...

Other arguments to pass to the function fun. Expecting these arguments to be vectors or lists. Any vectorization in these arguments is preserved (see details to see how).

Details

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.

Value

Vector of evaluations of the function fun at arg.

Note

Any NA's that appear in arg will be returned as NA.

Examples

 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)

vincenzocoia/copsupp documentation built on Aug. 23, 2020, 7:37 a.m.