mobdb_extract_locations: Extract location information from search results

View source: R/utils-helpers.R

mobdb_extract_locationsR Documentation

Extract location information from search results

Description

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.

Usage

mobdb_extract_locations(results, unnest = TRUE)

Arguments

results

A tibble returned by mobdb_search().

unnest

Logical. If TRUE (default), unnest locations so each feed-location combination gets its own row. If FALSE, return a summary of locations per feed.

Value

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.

Examples

# 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)


mobdb documentation built on Aug. 29, 2026, 1:07 a.m.