Skip to contents

Return metadata attributes from a single spectrum or a collection of spectra as a tibble.

Usage

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

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.

Value

A tibble With the metadata attributes and an index column.

Details

Attributes are returned as columns in a tibble. If the argument to col.names is a 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.

Some metadata values are stored in lists or data frames, these can be returned as a list columns or the individual fields unnested into separate columns.

Examples


my.mspct <- source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2))

spct_metadata(my.mspct)
#> # A tibble: 2 × 11
#>   spct.idx   lat   lon address    when.measured       what.measured how.measured
#>   <fct>    <dbl> <dbl> <chr>      <dttm>              <chr>         <chr>       
#> 1 sun1      60.2  25.0 Kumpula, … 2010-06-22 09:51:00 sunlight, si… Simulated u…
#> 2 sun2      60.2  25.0 Kumpula, … 2010-06-22 09:51:00 sunlight, si… Simulated u…
#> # ℹ 4 more variables: normalized <dbl>, multiplier <dbl>, time.unit <Duration>,
#> #   bswf.used <chr>

spct_metadata(sun.spct)
#> # A tibble: 1 × 11
#>   spct.idx   lat   lon address    when.measured       what.measured how.measured
#>   <fct>    <dbl> <dbl> <chr>      <dttm>              <chr>         <chr>       
#> 1 sun.spct  60.2  25.0 Kumpula, … 2010-06-22 09:51:00 sunlight, si… Simulated u…
#> # ℹ 4 more variables: normalized <dbl>, multiplier <dbl>, time.unit <Duration>,
#> #   bswf.used <chr>

spct_metadata(my.mspct, na.rm = TRUE)
#> # A tibble: 2 × 11
#>   spct.idx   lat   lon address    when.measured       what.measured how.measured
#>   <fct>    <dbl> <dbl> <chr>      <dttm>              <chr>         <chr>       
#> 1 sun1      60.2  25.0 Kumpula, … 2010-06-22 09:51:00 sunlight, si… Simulated u…
#> 2 sun2      60.2  25.0 Kumpula, … 2010-06-22 09:51:00 sunlight, si… Simulated u…
#> # ℹ 4 more variables: normalized <dbl>, multiplier <dbl>, time.unit <Duration>,
#> #   bswf.used <chr>

spct_metadata(sun.spct, na.rm = TRUE)
#> # A tibble: 1 × 11
#>   spct.idx   lat   lon address    when.measured       what.measured how.measured
#>   <fct>    <dbl> <dbl> <chr>      <dttm>              <chr>         <chr>       
#> 1 sun.spct  60.2  25.0 Kumpula, … 2010-06-22 09:51:00 sunlight, si… Simulated u…
#> # ℹ 4 more variables: normalized <dbl>, multiplier <dbl>, time.unit <Duration>,
#> #   bswf.used <chr>

spct_metadata(my.mspct, col.names = c(geocode = "geo", "instr.desc"))
#> # A tibble: 2 × 8
#>   spct.idx   lat   lon address   spectrometer.name spectrometer.sn bench.grating
#>   <fct>    <dbl> <dbl> <chr>     <chr>             <chr>           <chr>        
#> 1 sun1      60.2  25.0 Kumpula,… NA                NA              NA           
#> 2 sun2      60.2  25.0 Kumpula,… NA                NA              NA           
#> # ℹ 1 more variable: bench.slit <chr>

spct_metadata(sun.spct, col.names = c(geocode = "geo", "instr.desc"))
#> # A tibble: 1 × 8
#>   spct.idx   lat   lon address   spectrometer.name spectrometer.sn bench.grating
#>   <fct>    <dbl> <dbl> <chr>     <chr>             <chr>           <chr>        
#> 1 sun.spct  60.2  25.0 Kumpula,… NA                NA              NA           
#> # ℹ 1 more variable: bench.slit <chr>

spct_metadata(sun.spct, col.names = "where.measured")$where.measured
#> Warning: Unknown or uninitialised column: `where.measured`.
#> NULL