add_attr2tb: Copy attributes from members of a generic_mspct

Description Usage Arguments Details Value Note Examples

View source: R/mspct.methods.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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.

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

1
2
3
4
5
6
7
8
9
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)

photobiology documentation built on Aug. 30, 2018, 9:04 a.m.