Skip to contents

The gmaps_cities data frame contains the results of geocoding five cities (“Houston”, “Washington”, “New York”, “Chicago”, “Arlington”) using the Google Maps API on 2022-06-08. The geocoding data appears in the json list-column.

gmaps_cities
#> # A tibble: 5 × 2
#>   city       json            
#>   <chr>      <list>          
#> 1 Houston    <named list [2]>
#> 2 Washington <named list [2]>
#> 3 New York   <named list [2]>
#> 4 Chicago    <named list [2]>
#> 5 Arlington  <named list [2]>

Two cities, Washington and Arlington, were deliberately picked for their ambiguity: Washington could refer to the city or the state, and Arlington could mean the one in Virginia or the one in Texas. This dataset is useful for exploring the rectangling capabilities of the tidyr package.

library(tidyr)
library(dplyr)

gmaps_cities %>% 
  hoist(json, "results") %>% 
  select(-json) %>% 
  unnest_longer(results) %>% 
  hoist(results, "formatted_address")
#> # A tibble: 7 × 3
#>   city       formatted_address   results         
#>   <chr>      <chr>               <list>          
#> 1 Houston    Houston, TX, USA    <named list [4]>
#> 2 Washington Washington, USA     <named list [4]>
#> 3 Washington Washington, DC, USA <named list [4]>
#> 4 New York   New York, NY, USA   <named list [4]>
#> 5 Chicago    Chicago, IL, USA    <named list [4]>
#> 6 Arlington  Arlington, TX, USA  <named list [4]>
#> 7 Arlington  Arlington, VA, USA  <named list [4]>