config icon indicating copy to clipboard operation
config copied to clipboard

Merging unnamed lists gives wrong result

Open vpanfilov opened this issue 6 years ago • 0 comments

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)

vpanfilov avatar Oct 11 '19 07:10 vpanfilov