jeroen / jsonlite

A Robust, High Performance JSON Parser and Generator for R
http://arxiv.org/abs/1403.2805
Other
379 stars 40 forks source link

Bug: Flatten does not work when used with simplifyVector/simplifyDataframe #99

Closed amin04 closed 9 years ago

amin04 commented 9 years ago

So I have the following json data:

"[{\"count\":20,\"subject\":{\"name\":\"United States\",\"alpha2\":\"US\"}},{\"count\":3,\"subject\":{\"name\":\"Canada\",\"alpha2\":\"CA\"}},{\"count\":3,\"subject\":{\"name\":\"Trinidad and Tobago\",\"alpha2\":\"TT\"}},{\"count\":2,\"subject\":{\"name\":\"France\",\"alpha2\":\"FR\"}},{\"count\":1,\"subject\":{\"name\":\"Czech Republic\",\"alpha2\":\"CZ\"}},{\"count\":1,\"subject\":{\"name\":\"United Kingdom\",\"alpha2\":\"GB\"}},{\"count\":1,\"subject\":{\"name\":\"Korea, Republic of\",\"alpha2\":\"KR\"}},{\"count\":1,\"subject\":{\"name\":\"Peru\",\"alpha2\":\"PE\"}},{\"count\":1,\"subject\":{\"name\":\"Brazil\",\"alpha2\":\"BR\"}},{\"count\":1,\"subject\":{\"name\":\"Taiwan, Province of China\",\"alpha2\":\"TW\"}},{\"count\":1,\"subject\":{\"name\":\"Namibia\",\"alpha2\":\"NA\"}},{\"count\":1,\"subject\":{\"name\":\"Faroe Islands\",\"alpha2\":\"FO\"}},{\"count\":1,\"subject\":{\"name\":\"Barbados\",\"alpha2\":\"BB\"}}]"

When I try

as.data.frame(fromJSON(jsontext, flatten=TRUE))

it works fine, gives me a flat data frame. However, when I do

as.data.frame(fromJSON(jsontext, simplifyDataFrame=FALSE, flatten=TRUE))

the flatten option doesn't work at all. Not what I expected.

jeroen commented 9 years ago

What do you expect? The docs state that:

flatten: automatically flatten nested data frames into a single non-nested data frame

If there are no data frames in the data, there is nothing to flatten.

amin04 commented 9 years ago

Sorry, meant simplifyVector=False instead of simplifyDataFrame=FALSE.

Those two calls give different results, even though Flatten=TRUE for both. Why is that?

jeroen commented 9 years ago

simplifyVector=FALSE implies simplifyDataFrame=FALSE because a data frame consists of vectors.

amin04 commented 9 years ago

So Flatten=TRUE won't work together with simplifyVector=FALSE?

jeroen commented 9 years ago

No it won't. simplifyVector=FALSE means that the output will only contain nested lists, so there are no data frames to flatten.

On Tue, May 5, 2015 at 1:45 PM, Amin Ali notifications@github.com wrote:

So Flatten=TRUE won't work together with simplifyVector=FALSE?

— Reply to this email directly or view it on GitHub.