Skip to contents

Create a single database output that merges together the information in all relational tables within a traits.build database. Trait measurements are still output in long format (1 row per trait value), but all measurement-related metadata (methods, location properties, context properties, contributors, references) are now included as additional columns in a single table. References are joined by join_sources(), so vars$sources selects among its columns, and the reference columns of the methods table are not repeated.

Usage

flatten_database(database, format, vars, include_description)

Arguments

database

traits.build database (list object)

format

A parameter for the locations, contexts and data contributors tables specifying how data are packed. All three can be formatted as a single compacted column(s) will have a human readable column ("single_column_pretty") or using json ("single_column_json") syntax. For location properties or context properties there is also the option to add each location_property or context_property to the traits table as its own column ("many_columns"); the contributors column defaults to "single_column_pretty" when this option is selected.

vars

List specifying which columns or properties to include from each table. The detail is for all columns/properties to be included.

include_description

A logical indicating whether to include (TRUE) or omit (FALSE) the context_property descriptions; defaults to TRUE.

Value

A table combining information in 8 traits.build relational tables: traits, locations, contexts, methods, taxa, taxonomic_updates, contributors, and identifiers. It is a tibble of class traits.build_flat, stamped with the database it came from: the attribute traits.build_stamp is a list of its title, version, doi, data_model_version and traits_build_version (each NA if the database does not record it). The stamp is kept by saveRDS() and, with the class, by arrow::write_parquet(), which stores it in the file's metadata, and is shown when the table is printed. extract_trait(), extract_taxa(), extract_dataset(), summarise_database() and the plots take this table as well as the relational database, and keep the stamp on what they return.

Examples

flat <- austraits_lite %>%
  extract_dataset("Falster_2003") %>%
  flatten_database()
flat
#> # A traits.build_flat table: 114 × 66
#> # From:                      AusTraits: a curated plant trait database for the
#> #   Australian flora, version 7.0.0.9000, doi:10.5281/zenodo.3568417
#>    dataset_id   source_id    taxon_name    observation_id trait_name value unit 
#>    <chr>        <chr>        <chr>         <chr>          <chr>      <chr> <chr>
#>  1 Falster_2003 Falster_2003 Acacia flori… 01             leaf_area  142   mm2  
#>  2 Falster_2003 Falster_2003 Acacia flori… 01             leaf_incl… 57    deg  
#>  3 Falster_2003 Falster_2003 Acacia flori… 02             leaf_comp… simp… NA   
#>  4 Falster_2003 Falster_2003 Acacia myrti… 03             leaf_area  319   mm2  
#>  5 Falster_2003 Falster_2003 Acacia myrti… 03             leaf_incl… 66.1  deg  
#>  6 Falster_2003 Falster_2003 Acacia myrti… 04             leaf_comp… simp… NA   
#>  7 Falster_2003 Falster_2003 Acacia suave… 05             leaf_area  562   mm2  
#>  8 Falster_2003 Falster_2003 Acacia suave… 05             leaf_incl… 71.7  deg  
#>  9 Falster_2003 Falster_2003 Acacia suave… 06             leaf_comp… simp… NA   
#> 10 Falster_2003 Falster_2003 Angophora hi… 07             leaf_area  1590  mm2  
#> # ℹ 104 more rows
#> # ℹ 59 more variables: entity_type <chr>, value_type <chr>,
#> #   basis_of_value <chr>, replicates <chr>, basis_of_record <chr>,
#> #   life_stage <chr>, population_id <chr>, individual_id <chr>,
#> #   repeat_measurements_id <chr>, temporal_context_id <chr>, location_id <chr>,
#> #   entity_context_id <chr>, plot_context_id <chr>, treatment_context_id <chr>,
#> #   collection_date <chr>, measurement_remarks <chr>, method_id <chr>, …
attr(flat, "traits.build_stamp")$version
#> [1] "7.0.0.9000"