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
)Character vector of indicator codes (see
list_ine_indicators()).
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.
Numeric or character, the year of data. Default (NULL)
returns the latest available period only.
Optional character vector to subset by region name (regular expressions allowed, matched against the geography name).
Character, one of "Total", "Hombres", "Mujeres".
Logical, join geometries from get_ine_geo() (default
FALSE).
A tidy tibble with columns GEOID, NAME, year, and one column
per requested indicator; an sf object if geometry = TRUE.
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.
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
)
} # }