add_attr2tb {photobiology}R Documentation

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)

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

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

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

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

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

Arguments

tb

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

mspct

generic_mspct Any collection of spectra.

col.names

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

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.

Value

A tibble With the metadata attributes in separate new variables.

Note

Currently supported attributes are "when.measured", "what.measured" and "where.measured". In the case of "where.measured", which has different components the name "where.measured" is ignored, but instead the following names are recognized: "lon" and "lat" for creating numeric columns of longitudes and latitudes respectively, and "geocode" for creating a column of data frames, in which case, if tb is not already a tibble it is converted into one before adding the new column. The order of the first two arguments is reversed in add_attr2tb() compared to the other functions. This is to allow its use in 'pipes', while the functions for single attributes are expected to be used mostly to create new tibbles.

Examples


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)


[Package photobiology version 0.9.21 Index]