Clamp a function to particular values when outside of a given domain (r)

clamp_domain(f, r, value = NA_real_)

Arguments

f

A function that takes x as a first argument.

r

Range of values (vector of length 2)

value

(Single) value to use when out of domain.

Value

A new function

Details

Things like names on input and return vectors are not dealt with very well, and would differ if the function was better constructed. Values falling outwide the domain are not evaluated (which is useful if these would cause crashes, warnings, etc).