View source: R/utils-helpers.R
| mobdb_extract_locations | R Documentation |
Helper function to extract and unnest location information from search results.
The locations field in search results is a list of data frames; this function
flattens it into a more usable format.
mobdb_extract_locations(results, unnest = TRUE)
results |
A tibble returned by |
unnest |
Logical. If |
A tibble with location information. If unnest = TRUE, each row represents
a feed-location pair. If unnest = FALSE, returns one row per feed with
concatenated location strings.
# Create sample data matching mobdb_search() output structure
sample_results <- tibble::tibble(
id = c("mdb-1", "mdb-2"),
provider = c("Agency A", "Agency B"),
locations = list(
data.frame(
country_code = "US",
country = "United States",
subdivision_name = "California",
municipality = "San Francisco"
),
data.frame(
country_code = "CA",
country = "Canada",
subdivision_name = "British Columbia",
municipality = "Vancouver"
)
)
)
# Extract and unnest locations
mobdb_extract_locations(sample_results)
# Get summary without unnesting
mobdb_extract_locations(sample_results, unnest = FALSE)
# With real API data:
results <- mobdb_search("California")
locations <- mobdb_extract_locations(results)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.