0

I have a dataframe which was scraped from JSCON.

store <- fromJSON(txt='https://openapi.etsy.com/v2/shops/epuu/listings/active?api_key=Redacted')
store_json <- as.data.frame(store$results)

However, when I go to export the dataframe store_json it produces an error

Error in .External2(C_writetable, x, file, nrow(x), p, rnames, sep, eol,  : 
  unimplemented type 'list' in 'EncodeElement'

Now I understand that this is because there is a list within the data.frame. When I inspected the vector I found there were lists, with elements such as c("Jewelry", "Earrings", "Dangle & Drop Earrings"). When I try and use unlist(vector) it does not work. Would gsub work? Perhaps the paste function then remove the c()? I have tried tostring and although the vector does become a character when I export as a csv it does not work correctly.

Inaimathi
  • 13,853
  • 9
  • 49
  • 93
Lowpar
  • 897
  • 10
  • 31
  • Possible duplicates: [Flatten list column inside data frame](http://stackoverflow.com/q/30243510/903061), or [Expand list in data frame into additional rows](http://stackoverflow.com/q/34210669/903061) or from earlier today [how to flatten data frame that contains lists](http://stackoverflow.com/q/34206003/903061). – Gregor Thomas Dec 10 '15 at 21:36

1 Answers1

0

If you're using the jsonlite package...

http://finzi.psych.upenn.edu/library/jsonlite/html/unbox.html

You could do this.. I'm sure there's a better way..

store <- fromJSON(txt='https://openapi.etsy.com/v2/shops/epuu/listings/active?api_key=Redacted', flatten = TRUE)
z <- toJSON(store, auto_unbox = TRUE)
store_json <- as.data.frame(z$results)
Ken Yeoh
  • 876
  • 6
  • 11