A dataset's source: block holds its dataset reference (the dataset itself, keyed by its dataset_id) as a single entry, and its source references (for a compilation, the studies observations were taken from, each named in the data's source_id) and secondary references (later publications re-using the same data) as lists:

util_flatten_sources(source, strict = TRUE)

Arguments

source

The source element of a metadata list, as read by read_metadata()

strict

Stop on an entry that is not in the expected shape (the default), or flatten it and flag it in the legacy column

Value

A tibble with one row per reference: slot (the entry's name in metadata.yml), type (dataset, source or secondary; an old name is given its current type), key, legacy (TRUE for an entry not in the expected shape: written in an old shape, or a bare value such as secondary: Smith_2021 where a reference's fields belong) and entry, a list-column holding the reference's fields.

Details

source:
  dataset:
    key: Smith_2020
    ...
  source:
  - key: Jones_1999
    ...
  - key: Brown_2005
    ...
  secondary:
  - key: Smith_2021
    ...

Either list may instead name a .yml file (holding the list) or a .bib file kept beside metadata.yml, source: sources.yml; read_metadata() reads it in place.

Earlier versions of traits.build wrote the dataset's reference as primary, original sources as original_source or original, and every reference as its own named entry (secondary_01, original_01, ...). Those shapes are no longer read: with strict = TRUE they are an error naming the entry, and metadata_convert_sources() converts them. dataset_test() reads with strict = FALSE, so that it can report the old shape as a failure and still check everything else about the file.

Examples

source <- list(
  dataset = list(key = "Smith_2020", bibtype = "Article"),
  source = list(
    list(key = "Jones_1999", bibtype = "Thesis"),
    list(key = "Brown_2005", bibtype = "Book")
  )
)
util_flatten_sources(source)
#> # A tibble: 3 × 5
#>   slot    type    key        legacy entry           
#>   <chr>   <chr>   <chr>      <lgl>  <list>          
#> 1 dataset dataset Smith_2020 FALSE  <named list [2]>
#> 2 source  source  Jones_1999 FALSE  <named list [2]>
#> 3 source  source  Brown_2005 FALSE  <named list [2]>