Skip to content

Merging unnamed lists gives wrong result #24

Description

@vpanfilov

When I use sequences of mappings in YAML format (see example 2.4 on https://yaml.org/spec/1.2/spec.html#id2759963) I can't override this array in another config section. Sequences of mappings from YAML are represented as unnamed lists in R.

Here is a simple example (section2 values are not overriden with conf2):

library(yaml)
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 3.6.1
#> Warning: package 'tidyr' was built under R version 3.6.1
#> Warning: package 'dplyr' was built under R version 3.6.1

conf1 <- yaml::yaml.load("
  param1: 123
  param2: 123
  section1:
    param1: test
    param2: 4
    params3: 8
  section2:
    - key: 1
      value: test1
    - key: 2
      value: test2
    - key: 3
      value: test3
")

conf2 <- yaml::yaml.load("
  param1: 456
  section1:
    param1: test_override
    param2: 8
  section2:
    - key: 4
      value: test4
    - key: 5
      value: test5
")

config::merge(conf1, conf2) %>%
  glimpse()
#> List of 4
#>  $ param2  : int 123
#>  $ section1:List of 3
#>   ..$ params3: int 8
#>   ..$ param1 : chr "test_override"
#>   ..$ param2 : int 8
#>  $ section2:List of 3
#>   ..$ :List of 2
#>   .. ..$ key  : int 1
#>   .. ..$ value: chr "test1"
#>   ..$ :List of 2
#>   .. ..$ key  : int 2
#>   .. ..$ value: chr "test2"
#>   ..$ :List of 2
#>   .. ..$ key  : int 3
#>   .. ..$ value: chr "test3"
#>  $ param1  : int 456

Created on 2019-10-11 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions