Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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(arg.range, wl.range, trim = TRUE)

Arguments

arg.range

a numeric vector of length two, or any other object for which function range() will return a range of wavelengths (nm).

wl.range

a numeric vector of length two, or any other object for which function range() will return a range of wavelengths (nm), missing values are not allowed.

trim

logical If TRUE the range returned is bound within wl.range while if FALSE it can be broader.

Details

The arg.range argument can contain NAs which are replaced by the value at the same position in wl.range. In addition a NULL argument for range is converted into wl.range. The wl.range is also the limit to which the returned value is trimmed if trim == TRUE. The idea is that the value supplied as wl.range is the wavelength range of the data.

Value

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

Examples

normalize_range_arg(c(NA, 500), range(sun.spct))
normalize_range_arg(c(300, NA), range(sun.spct))
normalize_range_arg(c(100, 5000), range(sun.spct), FALSE)
normalize_range_arg(c(NA, NA), range(sun.spct))
normalize_range_arg(c(NA, NA), sun.spct)

photobiology

Photobiological Calculations

v0.10.10
GPL (>= 2)
Authors
Pedro J. Aphalo [aut, cre] (<https://orcid.org/0000-0003-3385-972X>), Titta K. Kotilainen [ctb] (<https://orcid.org/0000-0002-2822-9734>), Glenn Davis [ctb], Agnese Fazio [ctb]
Initial release
2022-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.