Skip to contents

Copy metadata attributes from members of a generic_mspct object into a tibble or data.frame.


  tb = NULL,
  col.names = NULL,
  idx = "spct.idx",
  unnest = FALSE

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

geocode2tb(mspct, tb = NULL, col.names = "geocode", 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")

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

  tb = NULL,
  col.names = "what.measured",
  idx = "spct.idx"

how_measured2tb(mspct, tb = NULL, col.names = "how.measured", idx = "spct.idx")

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

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

instr_desc2tb(mspct, tb = NULL, col.names = "instr.desc", idx = "spct.idx")

  tb = NULL,
  col.names = "instr.settings",
  idx = "spct.idx"

BSWF_used2tb(mspct, tb = NULL, col.names = "BSWF.used", idx = "spct.idx")

  tb = NULL,
  col.names = "",
  idx = "spct.idx"

Tfr_type2tb(mspct, tb = NULL, col.names = "Tfr.type", idx = "spct.idx")

Rfr_type2tb(mspct, tb = NULL, col.names = "Rfr.type", idx = "spct.idx")

time_unit2tb(mspct, tb = NULL, col.names = "time.unit", idx = "spct.idx")

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



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


generic_mspct Any collection of spectra.


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


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


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


A tibble With the metadata attributes in separate new variables.


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. Only in the case of method add_attr2tb() 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 vector passed to col.names has no names the names of the attributes are used for the new columns. If the fields of the attributes are unnested their names are used as names for the columns.

Valid accepted as argument to col.names are NULL, "lon", "lat", "address", "geocode", "where.measured", "when.measured", "what.measured", "how.measured", "comment", "normalised", "normalized", "scaled", "bswf.used", "instr.desc", "instr.settings", "", "Tfr.type", "Rfr.type", "time.unit".


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.


#> Attaching package: 'dplyr'
#> The following object is masked from 'package:testthat':
#>     matches
#> The following objects are masked from 'package:stats':
#>     filter, lag
#> The following objects are masked from 'package:base':
#>     intersect, setdiff, setequal, union

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"))
#> # A tibble: 2 × 5
#>   spct.idx Q_Total latitude longitude time               
#>   <fct>      <dbl>    <dbl>     <dbl> <dttm>             
#> 1 sun1     0.00126     60.2      25.0 2010-06-22 09:51:00
#> 2 sun2     0.00251     60.2      25.0 2010-06-22 09:51:00

#> # A tibble: 2 × 2
#>   spct.idx when.measured      
#>   <fct>    <dttm>             
#> 1 sun1     2010-06-22 09:51:00
#> 2 sun2     2010-06-22 09:51:00