colearendt / tidyjson

Tidy your JSON data in R with tidyjson
Other
183 stars 15 forks source link

Throw error on spread_all in case of name conflict #76

Open jeremystan opened 8 years ago

jeremystan commented 8 years ago

If spread_all generates a name that already exists in the data frame, then throw a meaningful error about the name conflict.

colearendt commented 7 years ago

Not sure whether the focus here is to throw a more meaningful error when the dedup fails or to remove the deduplication behavior altogether (it can make exploring nice, but it can also be hard to tell where a value comes from). I made a change supporting the former in 291cf53. Naming is not necessarily nice... as each iteration will append a new series of ".#".

Would like to get feedback on whether the API should be deduping or not. If so, perhaps the method of doing so could be cleaned up somehow.

'{"a.b": 1, "a": {"b.2": 2, "b":3}}' %>% spread_all()
#> Warning in spread_all(.): results in duplicate column names, appending .#
#> for uniqueness

#> Warning in spread_all(.): results in duplicate column names, appending .#
#> for uniqueness
#> # A tbl_json: 1 x 4 tibble with a "JSON" attribute
#>           `attr(., "JSON")` document.id   a.b a.b.2 a.b.2.2
#>                       <chr>       <int> <dbl> <dbl>   <dbl>
#> 1 "{\"a.b\":1,\"a\":{\"..."           1     1     2       3