Learn R Programming

photobiology (version 0.13.0)

spct_metadata: Access metadata

Description

Return metadata attributes from a single spectrum or a collection of spectra as a data.frame. A wrapper on add_attr2tb providing an alternative order of formal parameters and constrained functionality.

Usage

spct_metadata(
  x,
  col.names = NULL,
  idx = "spct.idx",
  na.rm = is.null(col.names),
  unnest = TRUE
)

Value

A data.frame or a tibble With the metadata attributes in separate new variables.

Arguments

x

generic_mspct or generic_spct Any collection of spectra or spectrum.

col.names

named character vector Name(s) of column(s) to create.

idx

character Name of the column with the names of the members of the collection of spectra.

na.rm

logical Flag controlling deletion of columns containing only NA values.

unnest

logical Flag controlling if metadata attributes that are lists of values should be returned in a list column or in separate columns.

Details

Each attribute is by default copied to a column in a tibble or a data.frame. If the argument for tb is NULL, as by default, a new tibble will be created. If an existing data.frame or tibble is passed as argument, new columns are added to it. However, the number of rows in the argument passed to tb must match the number of spectra in the argument passed to mspct. Only in the case of methods add_attr2tb() and spct_metadata() if the argument to col.names is a named vector, the names of members are used as names for the columns created. This permits setting any valid name for the new columns. If the members of the vector passed to col.names have no names, then the value is interpreted as the name of the attributes to add, and also used as name for the new column.

Valid values accepted as argument to col.names are NULL, or a vector containing one or more of the following character strings: "lon", "lat", "address", "geocode", "where.measured", "when.measured", "what.measured", "how.measured", "comment", "normalised", "normalized", "scaled", "bswf.used", "instr.desc", "instr.settings", solute.properties, "filter.properties", "Tfr.type", "Rfr.type", "time.unit".

See Also

add_attr2tb for more details.

Other measurement metadata functions: add_attr2tb(), getFilterProperties(), getHowMeasured(), getInstrDesc(), getInstrSettings(), getSoluteProperties(), getWhatMeasured(), getWhenMeasured(), getWhereMeasured(), get_attributes(), isValidInstrDesc(), isValidInstrSettings(), select_spct_attributes(), setFilterProperties(), setHowMeasured(), setInstrDesc(), setInstrSettings(), setSoluteProperties(), setWhatMeasured(), setWhenMeasured(), setWhereMeasured(), spct_attr2tb(), subset_attributes(), trimInstrDesc(), trimInstrSettings()

Examples

Run this code
# collection of spectra
spct_metadata(sun_evening.mspct)

spct_metadata(sun_evening.mspct, na.rm = FALSE)

spct_metadata(sun_evening.mspct,
              col.names = "geocode",
              unnest = FALSE)

spct_metadata(sun_evening.mspct,
              col.names = c(when.measured = "time", "what.measured"))

# multiple spectra in long form
spct_metadata(sun_evening.spct,
              col.names = c("geocode", "when.measured"))

# single spectrum
spct_metadata(sun.spct,
              col.names = c("geocode", "when.measured"))

Run the code above in your browser using DataLab