Learn R Programming

photobiology (version 0.9.6)

normalize_range_arg: Normalize a range argument into a true numeric range

Description

Several functions in this package and the suite accept a range argument with a flexible syntax. To ensure that all functions and methods behave in the same way this code has been factored out into a separate function.

Usage

normalize_range_arg(range, default.range = c(0, Inf))

Arguments

range
a numeric vector of length two, or any other object for which function range() will return two
default.range
a numeric vector of length two, missing values are not allowed, but Inf amd -Inf are.

Value

  • a numeric vector of length two, guaranteed not to have missing values.

Details

The range argument can contain NAs which are replaced by the value at the same position in default.range. In addition a NULL argument for range is converted into default.range. The default.range is also the limit to which the returned value is trimmed. The idea is that the value supplied as default is the whole valid range, and as we use range only for wavelength, the default is 0 to Inf.

Examples

Run this code
normalize_range_arg(sun.spct)
normalize_range_arg(c(NA, 500))
normalize_range_arg(c(NA, 500), c(100, Inf))
normalize_range_arg(c(-100, 500), c(-Inf, Inf))

Run the code above in your browser using DataLab