mspct2fdata: Convert spectra into 'fda.usc::fdata' objects

View source: R/fdata-conversion.R

mspct2fdataR Documentation

Convert spectra into 'fda.usc::fdata' objects

Description

Convert spectral objects (xxxx_spct, xxxx_mspct) as defined in package 'photobiology' into fda.usc::fdata objects, preserving as much information as possible. As fdata objects can contain other kinds of data, the reverse conversion is supported (experimentally) and mainly for 'fdata' objects returned by the functional data analysis methods from package fda.usc to spectral data previosuly exported in the opposite direction.

Usage

mspct2fdata(x, spct.data.var = NULL, multiplier = 1, ...)

spct2fdata(x, spct.data.var = NULL, multiplier = 1, ...)

fdata2spct(x, multiplier = 1, member.class = NULL, drop.idx = FALSE, ...)

fdata2mspct(x, multiplier = 1, member.class = NULL, drop.idx = FALSE, ...)

Arguments

x

generic_mspct or generic_spct object or an object belonging to a derived class, or an object of class 'fdata' depending on the function.

spct.data.var

character The name of the column containing data to export. If NULL the first spectral data column found is used.

multiplier

numeric A multiplier to be applied to the 'spc' data to do unit or scale conversion.

...

possibly additional named arguments passed to object constructors.

member.class

character Name of the class of the spectrum or of the members of the collection of spectra.

drop.idx

logical Flag indicating whether to drop or keep idx.var in the collection members.

Warning!

When converting multiple spectra, all the spectra to be included in the fdata object must share the same wavelength values. Spectra that do not fulfil this condition will be skipped. The data variable needs also to be present in all individual spectra as no conversions are applied automatically by this function. If a different name, indicating a different quantity or a different base of expression is encountered, the affected spectrum is skipped with a warning.

Examples

if (requireNamespace("fda.usc", quietly = TRUE)) {
# from spectra to fdata
  sun.fdata <- spct2fdata(sun.spct)
  str(sun.fdata)
  polyester.fdata <- spct2fdata(polyester.spct)
  str(polyester.fdata)
# from fdata to spectra
  fdata2spct(sun.fdata)
  fdata2spct(sun.fdata, drop.idx = TRUE)
  fdata2spct(polyester.fdata, drop.idx = TRUE)
}


photobiologyInOut documentation built on July 26, 2023, 5:15 p.m.