This function does some cleaning and simplifying to allow efficient specification of elements in the YAML fragments.

simplify_by_flattening(x, simplify = ".*", .level = 1)

Arguments

x

Extracted (and loaded) YAML fragments

simplify

A regular expression specifying which elements to simplify (default is everything)

.level

Internal argument to enable slightly-less-than-elegant 'recursion'.

Value

A simplified list (but still a list)

Examples

yamlFragmentExample <- '
---
source:
  -
    id: src_1
    label: "Label 1"
  -
    id: src_2
    label: "Label 2"
assertion:
  -
    id: assertion_1
    label: "Assertion 1"
  -
    id: assertion_2
    label: "Assertion 2"
---
';
loadedExampleFragments <-
  load_yaml_fragments(yamlFragmentExample);
simplified <-
  simplify_by_flattening(loadedExampleFragments);

### Pre simmplification:
str(loadedExampleFragments);
#> List of 1
#>  $ :List of 2
#>   ..$ source   :List of 2
#>   .. ..$ :List of 2
#>   .. .. ..$ id   : chr "src_1"
#>   .. .. ..$ label: chr "Label 1"
#>   .. ..$ :List of 2
#>   .. .. ..$ id   : chr "src_2"
#>   .. .. ..$ label: chr "Label 2"
#>   ..$ assertion:List of 2
#>   .. ..$ :List of 2
#>   .. .. ..$ id   : chr "assertion_1"
#>   .. .. ..$ label: chr "Assertion 1"
#>   .. ..$ :List of 2
#>   .. .. ..$ id   : chr "assertion_2"
#>   .. .. ..$ label: chr "Assertion 2"
#>  - attr(*, "class")= chr [1:2] "yumFromFile" "list"

### Post simmplification:
str(simplified);
#> List of 4
#>  $ source   :List of 2
#>   ..$ id   : chr "src_1"
#>   ..$ label: chr "Label 1"
#>  $ source   :List of 2
#>   ..$ id   : chr "src_2"
#>   ..$ label: chr "Label 2"
#>  $ assertion:List of 2
#>   ..$ id   : chr "assertion_1"
#>   ..$ label: chr "Assertion 1"
#>  $ assertion:List of 2
#>   ..$ id   : chr "assertion_2"
#>   ..$ label: chr "Assertion 2"