Retrieves demographic data from INE via the official ineapir::get_data_table() API wrapper, and tidies it into a data frame with one row per geography x year and one column per indicator.

get_ine_demog(
  indicator,
  geo_level = NULL,
  year = NULL,
  region = NULL,
  sex = "Total",
  geometry = FALSE
)

Arguments

indicator

Character vector of indicator codes (see list_ine_indicators()).

geo_level

Character, the geographic level to fetch. Must match the level at which every requested indicator is actually published (see list_ine_indicators()). If NULL (default), inferred from indicator.

year

Numeric or character, the year of data. Default (NULL) returns the latest available period only.

region

Optional character vector to subset by region name (regular expressions allowed, matched against the geography name).

sex

Character, one of "Total", "Hombres", "Mujeres".

geometry

Logical, join geometries from get_ine_geo() (default FALSE).

Value

A tidy tibble with columns GEOID, NAME, year, and one column per requested indicator; an sf object if geometry = TRUE.

Details

Each indicator is mapped to a real INE table id via the ine_variables registry (see list_ine_indicators()). Different indicators are only available at different geographic granularities in INE's source tables (e.g. population is published by municipality, but births/deaths only down to province) — all requested indicators must share the same geo_level, or request them separately.

Examples

if (FALSE) { # \dontrun{
# Not run: requires live network access to the INE API.
pop_data <- get_ine_demog(indicator = "population_total", year = 2023)
births_deaths <- get_ine_demog(
  indicator = c("births_total", "deaths_total"), year = 2023
)
} # }