Create the observation_ancillary table

create_observation_ancillary(
  L0_flat,
  observation_id,
  variable_name,
  unit = NULL
)

Arguments

L0_flat

(tbl_df, tbl, data.frame) The fully joined source L0 dataset, in "flat" format (see details).

observation_id

(character) Column in L0_flat containing the identifier assigned to each unique observation.

variable_name

(character) Columns in L0_flat containing the ancillary observation data.

unit

(character) An optional column in L0_flat containing the units of each variable_name following the column naming convention: unit_<variable_name> (e.g. "unit_temperature").

Value

(tbl_df, tbl, data.frame) The observation_ancillary table.

Details

This function collects specified columns from L0_flat, converts into long (attribute-value) form by gathering variable_name. Regular expression matching joins unit to any associated variable_name and is listed in the resulting table's "unit" column.

"flat" format refers to the fully joined source L0 dataset in "wide" form with the exception of the core observation variables, which are in "long" form (i.e. using the variable_name, value, unit columns of the observation table). This "flat" format is the "widest" an L1 ecocomDP dataset can be consistently spread due to the frequent occurrence of L0 source datasets with > 1 core observation variable.

Examples

flat <- ants_L0_flat

observation_ancillary <- create_observation_ancillary(
  L0_flat = flat,
  observation_id = "observation_id", 
  variable_name = c("trap.type", "trap.num", "moose.cage"))

observation_ancillary
#> # A tibble: 8,793 x 5
#>    observation_ancillary_id observation_id variable_name value  unit 
#>    <chr>                    <chr>          <chr>         <chr>  <chr>
#>  1 1                        1              trap.type     bait   NA   
#>  2 2                        1              trap.num      1 hour NA   
#>  3 3                        1              moose.cage    NA     NA   
#>  4 4                        2              trap.type     bait   NA   
#>  5 5                        2              trap.num      1 hour NA   
#>  6 6                        2              moose.cage    NA     NA   
#>  7 7                        3              trap.type     bait   NA   
#>  8 8                        3              trap.num      1 hour NA   
#>  9 9                        3              moose.cage    NA     NA   
#> 10 10                       4              trap.type     bait   NA   
#> # ... with 8,783 more rows