Converts data frames or matrices containing spectral data to rspec object

as.rspec(object, whichwl = NULL, interp = TRUE, lim = NULL,
  exceed.range = TRUE)

is.rspec(object)

Arguments

object

(required) a data frame or matrix containing spectra to process.

whichwl

a numeric or character vector specifying which column contains wavelengths. If NULL (default), function searches for column containing equally spaced numbers and sets it as wavelengths "wl". If no wavelengths are found or whichwl is not given, returns arbitrary index values.

interp

whether to interpolate wavelengths in 1-nm bins (defaults to TRUE).

lim

vector specifying wavelength range to interpolate over (e.g. c(300, 700)).

exceed.range

logical. Should data be interpolated to the limits specified by lim if lim exceeds the range of the actual data? Useful, and relatively safe, when the data range falls slightly within lim (e.g. 300.1 - 699 nm), but will produce spurious results if lim far exceeds the range of input data. Defaults to TRUE.

Value

an object of class rspec for use in further pavo functions

a logical value indicating whether the object is of class rspec

Examples

# Generate some fake reflectance data fakedat <- data.frame(wl = 300:700, refl1 = rnorm(401), refl2 = rnorm(401)) head(fakedat)
#> wl refl1 refl2 #> 1 300 -1.400043517 -0.8452478 #> 2 301 0.255317055 -0.9615715 #> 3 302 -2.437263611 1.0174911 #> 4 303 -0.005571287 -1.4960537 #> 5 304 0.621552721 -1.1848187 #> 6 305 1.148411606 0.6302344
# Determine if is rspec object is.rspec(fakedat)
#> [1] FALSE
# Convert to rspec object fakedat2 <- as.rspec(fakedat)
#> wavelengths found in column 1
#> The spectral data contain 401 negative value(s), which may produce unexpected results if used in models. Consider using procspec() to correct them.
is.rspec(fakedat2)
#> [1] TRUE
head(fakedat2)
#> wl refl1 refl2 #> 1 300 -1.400043517 -0.8452478 #> 2 301 0.255317055 -0.9615715 #> 3 302 -2.437263611 1.0174911 #> 4 303 -0.005571287 -1.4960537 #> 5 304 0.621552721 -1.1848187 #> 6 305 1.148411606 0.6302344