-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working across different levels of nesting? #69
Comments
Perhaps it could use |
@cboettig glad it's making the tidying of Our original thinking was to provide a function that returns all names in the list at any level (e.g. Since that vector of names will be quite long, we might also want to provide a way for the user to ask for all levels of nesting under a certain name, maybe in a way like |
I like @aedobbyn suggestion to use Maybe this deserves its own issue, but another complexity of multiple levels of nesting is different numbers of rows being returned. For example, the twitter data:
In this case there are two values at the
My thought would be we want some kind of long format ie:
|
Thanks to the authors; this is a great idea for a package! Another nested geodata example from the Google Places API returns both the location lat/lon and the viewport (which itself has two lat/lon pairs): response <- list(
html_attributions = list(),
results = list(
list(formatted_address = "4900 Georgia Ave NW, Washington, DC 20011, USA",
geometry = list(location = list(lat = 38.9499476, lng = -77.0274465),
viewport = list(northeast = list(lat = 38.9513095798927, lng = -77.0259576201073),
southwest = list(lat = 38.9486099201073, lng = -77.0286572798927))),
icon = "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
id = "af15897f117bc7e03dfdfbd42d728b49f1e89d9e",
name = "Carquest Auto Parts - CQ of Washington DC",
opening_hours = list(open_now = TRUE, weekday_text = list()),
photos = list(list(
height = 399L,
html_attributions = list("<a href=\"https://maps.google.com/maps/contrib/114756074981885904642/photos\">CARQUEST Auto Parts # 6360</a>"),
photo_reference = "CmRaAAAAn9x83EO46LLgExGB549kblIzfcUsr0YMfvesTcb2wypsF4AItXPTgOj8CsmSm93H7AZTZhkbcq27-_VzSGmsKRK1jcQxwyQ5waTJD4WgH5uQR2OnzVmMJEhTvBkBpD5cEhCISyoZwUC_2cZ9mPN7eCZuGhRVDN2IS7dbVqNVf55RABimFGaneA",
width = 600L)),
place_id = "ChIJr9kFdGzIt4kRUfOVZB-HkpI",
rating = 4.1,
reference = "CmRbAAAAhdTteLADmBP9aoOayLlTVi2uF_Q7Vjv5txpuvtiKpkziA9z_5wKMdjM1kK6hNDEJBLIaHlyDnWZfKdT5X_Fsy6B9B_niHLxeQqbqF5jfV9snXpAxks57TmpJiRgAXSorEhCJFRfMPTis725paCKJHgMXGhSDxyEK0-SvzzBooeKcuW20CHJOpg",
types = list("car_repair", "store", "point_of_interest",
"establishment")),
list(formatted_address = "3908 Pennsylvania Ave SE, Washington, DC 20020, USA",
geometry = list(location = list(lat = 38.8658696, lng = -76.9502563),
viewport = list(northeast = list(lat = 38.8669400798927, lng = -76.9490863201073),
southwest = list(lat = 38.8642404201073, lng = -76.9517859798927))),
icon = "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
id = "933f517d7634fff163e2564804c6ff88cf4e7816",
name = "Addison Auto Parts",
opening_hours = list(open_now = TRUE, weekday_text = list()),
place_id = "ChIJr1N7fxC5t4kRLABe0OVcF4E", rating = 4.7,
reference = "CmRbAAAAw7N5mVqBN4-0RXwoZ38VEvwXLXxZIih__1vR3J7zdr0dBxVMOw-V5EMB0YoRFVNbsaa7AfiE_YJyVP8q8JT_hsk0FHBvKDu3ONGc3Bm8C38DNk8rmzQhLKFJeoYs5_FCEhCB26vfpK6ZXonWG3LNHR3VGhQDlMQm6xDdQ55J0GAADzhmsIQBuA",
types = list("car_repair", "store", "point_of_interest", "establishment"))
),
status = "OK")
roomba::roomba(response, cols = c('name', 'place_id', 'lat', 'lng'), keep = any)
#> # A tibble: 8 x 4
#> name place_id lat lng
#> <chr> <chr> <dbl> <dbl>
#> 1 Carquest Auto Parts - CQ of Washington DC ChIJr9kFdGzIt4kRU… NA NA
#> 2 <NA> <NA> 38.9 -77.0
#> 3 <NA> <NA> 39.0 -77.0
#> 4 <NA> <NA> 38.9 -77.0
#> 5 Addison Auto Parts ChIJr1N7fxC5t4kRL… NA NA
#> 6 <NA> <NA> 38.9 -77.0
#> 7 <NA> <NA> 38.9 -76.9
#> 8 <NA> <NA> 38.9 -77.0 This case can currently be hacked into shape with tidyr, but only making the assumptions that the locations returned are in the order they appear in the response and that the order in the response is consistent. These are pretty safe assumptions, but subsetting notation would make it all moot. I see a few options for the API:
|
@alistaire47 thanks for your comment and response example! For what it's worth I like the idea of allowing the user to specify whether they want the data in nested or unnested format and, if unnested, representing column names in |
Has this ever been resolved? |
It has not -- feel free to submit a PR or throw out an idea of tackling if you have one! |
This package is very exciting, great work! Our
dataspice
team was thrilled to see how nicely it already handles common requests on adataspice.json
file, e.g.:But not clear how to get a repeated column from a different level of nesting:
Probably requires some kind of notation to indicate the different levels, e.g. in this case maybe something like
would be possible?
The text was updated successfully, but these errors were encountered: