Skip to contents

Row bind spectra into a similar object with multiple spectra stored in long form in an object of the most derived shared class, preserving metadata attributes of individual spectra, and adding a factor distinguishing individual spectra.

Usage

rbind_spct(
  l,
  use.names = TRUE,
  fill = TRUE,
  idfactor = TRUE,
  attrs.source = NULL,
  attrs.simplify = FALSE
)

rbindspct(
  l,
  use.names = TRUE,
  fill = TRUE,
  idfactor = TRUE,
  attrs.source = NULL,
  attrs.simplify = FALSE
)

Arguments

l

A source_mspct, filter_mspct, reflector_mspct, response_mspct, chroma_mspct, cps_mspct, generic_mspct object or a list containing source_spct, filter_spct, reflector_spct, response_spct, chroma_spct, cps_spct, or generic_spct objects.

use.names

logical If TRUE items will be bound by matching column names. By default TRUE for rbindspct. Columns with duplicate names are bound in the order of occurrence, similar to base. When TRUE, at least one item of the input list has to have non-null column names.

fill

logical If TRUE fills missing columns with NAs. By default TRUE. When TRUE, use.names has also to be TRUE, and all items of the input list have to have non-null column names.

idfactor

logical or character Generates an index column of factor type. Default is (idfactor=TRUE) for both lists and _mspct objects. If idfactor=TRUE then the column is auto named spct.idx. Alternatively the column name can be directly provided to idfactor as a character string.

attrs.source

integer Index into the members of the list from which attributes should be copied. If NULL, all attributes are collected into named lists, except that unique comments are pasted.

attrs.simplify

logical Flag indicating that when all values of an attribute are equal for all members, the named list will be replaced by a single copy of the value.

Value

An spectral object of a type common to all bound items containing a concatenation of all the items passed in. If the argument 'idfactor' is TRUE, then a factor 'spct.idx' will be added to the returned spectral object.

Details

Each item of l should be a spectrum, including NULL (skipped) or an empty object (0 rows). rbind_spct() is most useful when there are a variable number of (potentially many) objects to stack. rbind_spct() always returns at least a generic_spct as long as all elements in l are spectra.

dplyr::rbind_fill is called internally and the result returned is the highest class in the inheritance hierarchy which is common to all elements in the list of spectra or collection of spectra passed as argument to l. If not all members of l belong to one of the _spct classes, an error is triggered. If not all spectra in l are expressed on the same base or as the same physical quantity, they are converted for source_spct and response_spct objects into energy-based quantities, and for filter_spct objects into transmittance. If any member spectrum is tagged with colour information, it is untagged before row binding.

rbindspct() is another name for rbind_spct(), retained for backwards compatibility.

Note

Note that any additional 'user added' attributes that might exist on individual items of the input list will not be preserved in the result. The attributes used by the photobiology package are preserved, and if they are not consistent across the bound spectral objects, a warning is issued.

See also

Other Methods for row-binding spectra: rmerge_spct()

Examples

# default, adds factor 'spct.idx' with letters as levels
spct <- rbind_spct(list(sun.spct, sun.spct))
spct
#> Object: source_spct [1,044 x 4]
#> containing 2 spectra in long form
#> Wavelength range 280-800 nm, step 0.9230769-1 nm 
#> Label: sunlight, simulated 
#> spct_1 measured on 2010-06-22 09:51:00 UTC
#> spct_2 measured on 2010-06-22 09:51:00 UTC 
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI 
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 1,044 × 4
#>    w.length s.e.irrad s.q.irrad spct.idx
#>       <dbl>     <dbl>     <dbl> <fct>   
#>  1     280          0         0 spct_1  
#>  2     281.         0         0 spct_1  
#>  3     282.         0         0 spct_1  
#>  4     283.         0         0 spct_1  
#>  5     284.         0         0 spct_1  
#>  6     285.         0         0 spct_1  
#>  7     286.         0         0 spct_1  
#>  8     286.         0         0 spct_1  
#>  9     287.         0         0 spct_1  
#> 10     288.         0         0 spct_1  
#> # ℹ 1,034 more rows
class(spct)
#> [1] "source_spct"  "generic_spct" "tbl_df"       "tbl"          "data.frame"  

# adds factor 'spct.idx' with letters as levels
spct <- rbind_spct(list(sun.spct, sun.spct), idfactor = TRUE)
head(spct)
#> Object: source_spct [6 x 4]
#> Wavelength range 280-284.61538 nm, step 0.9230769 nm 
#> Label: sunlight, simulated 
#> spct_1 measured on 2010-06-22 09:51:00 UTC 
#> spct_1 measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI 
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 6 × 4
#>   w.length s.e.irrad s.q.irrad spct.idx
#>      <dbl>     <dbl>     <dbl> <fct>   
#> 1     280          0         0 spct_1  
#> 2     281.         0         0 spct_1  
#> 3     282.         0         0 spct_1  
#> 4     283.         0         0 spct_1  
#> 5     284.         0         0 spct_1  
#> 6     285.         0         0 spct_1  
class(spct)
#> [1] "source_spct"  "generic_spct" "tbl_df"       "tbl"          "data.frame"  

# adds factor 'spct.idx' with the names given to the spectra in the list
# supplied as formal argument 'l' as levels
spct <- rbind_spct(list(one = sun.spct, two = sun.spct), idfactor = TRUE)
head(spct)
#> Object: source_spct [6 x 4]
#> Wavelength range 280-284.61538 nm, step 0.9230769 nm 
#> Label: sunlight, simulated 
#> one measured on 2010-06-22 09:51:00 UTC 
#> one measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI 
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 6 × 4
#>   w.length s.e.irrad s.q.irrad spct.idx
#>      <dbl>     <dbl>     <dbl> <fct>   
#> 1     280          0         0 one     
#> 2     281.         0         0 one     
#> 3     282.         0         0 one     
#> 4     283.         0         0 one     
#> 5     284.         0         0 one     
#> 6     285.         0         0 one     
class(spct)
#> [1] "source_spct"  "generic_spct" "tbl_df"       "tbl"          "data.frame"  

# adds factor 'ID' with the names given to the spectra in the list
# supplied as formal argument 'l' as levels
spct <- rbind_spct(list(one = sun.spct, two = sun.spct),
                   idfactor = "ID")
head(spct)
#> Object: source_spct [6 x 4]
#> Wavelength range 280-284.61538 nm, step 0.9230769 nm 
#> Label: sunlight, simulated 
#> one measured on 2010-06-22 09:51:00 UTC 
#> one measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI 
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 6 × 4
#>   w.length s.e.irrad s.q.irrad ID   
#>      <dbl>     <dbl>     <dbl> <fct>
#> 1     280          0         0 one  
#> 2     281.         0         0 one  
#> 3     282.         0         0 one  
#> 4     283.         0         0 one  
#> 5     284.         0         0 one  
#> 6     285.         0         0 one  
class(spct)
#> [1] "source_spct"  "generic_spct" "tbl_df"       "tbl"          "data.frame"