photobiology (version 0.9.25)

add_attr2tb: Copy attributes from members of a generic_mspct

Description

Copy the when.measured, where.measured or what.measured attribute from members of a generic_mspct object into a tibble or data.frame.

Usage

add_attr2tb(tb, mspct, col.names = NULL, idx = "spct.idx")

when_measured2tb(mspct, tb = NULL, col.names = "when.measured", idx = "spct.idx")

lonlat2tb(mspct, tb = NULL, col.names = c("lon", "lat"), idx = "spct.idx")

lon2tb(mspct, tb = NULL, col.names = "lon", idx = "spct.idx")

lat2tb(mspct, tb = NULL, col.names = "lat", idx = "spct.idx")

geocode2tb(mspct, tb = NULL, col.names = "geocode", idx = "spct.idx")

what_measured2tb(mspct, tb = NULL, col.names = "what.measured", idx = "spct.idx")

Arguments

tb

tibble or data.frame to which to add the data (optional).

mspct

generic_mspct Any collection of spectra.

col.names

named character vector Name(s) of column(s) to create. Values are the names of the attributes to copy, while if named, the names provide the name for the column.

idx

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

Value

A tibble With the metadata attributes in separate new variables.

Details

The attributes are copied to a column in a tibble or data frame. If the tb formal parameter receives NULL as argument, 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. If the argument to col.names is aa named vector, with the names of members matching the names of attributes, then the values are used as names for the columns created. This permits setting any valid name for the new columns. If the vector passed to col.names has no names, then the values are interpreted as the names of the attributes to add, and also used as names for the new columns.

Examples

Run this code
# NOT RUN {
library(dplyr)

my.mspct <- source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2))
q_irrad(my.mspct) %>%
  add_attr2tb(my.mspct, c(lat = "latitude",
                          lon = "longitude",
                          when.measured = "time"))

when_measured2tb(my.mspct)

# }

Run the code above in your browser using DataLab