R: Row-bind spectra

rbindspct {photobiology} | R Documentation

## Row-bind spectra

### Description

A wrapper on `dplyr::rbind_fill` that preserves class and other attributes of spectral objects.

### Usage

    rbindspct(l, use.names = TRUE, fill = TRUE, idfactor = TRUE)

### 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 (`TRUE`) is to 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.

### Details

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

### 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.

### 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.

`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. If not all members of the list belong to one of the `_spct` classes, an error is triggered. The function sets all data in `source_spct` and `response_spct` objects supplied as arguments into energy-based quantities, and all data in `filter_spct` objects into transmittance before the row binding is done. If any member spectrum is tagged, it is untagged before row binding.

### Examples

    spct <- rbindspct(list(sun.spct, sun.spct))
    spct
    class(spct)

    # adds factor 'spct.idx' with letters as levels
    spct <- rbindspct(list(sun.spct, sun.spct), idfactor = TRUE)
    head(spct)
    class(spct)

    # adds factor 'spct.idx' with the names given to the spectra in the list
    # supplied as formal argument 'l' as levels
    spct <- rbindspct(list(one = sun.spct, two = sun.spct), idfactor = TRUE)
    head(spct)
    class(spct)

    # adds factor 'ID' with the names given to the spectra in the list
    # supplied as formal argument 'l' as levels
    spct <- rbindspct(list(one = sun.spct, two = sun.spct),
                      idfactor = "ID")
    head(spct)
    class(spct)

[Package photobiology version 0.9.21 Index]