Retrieves, cleans, and validates Spanish January-1st provincial population estimates by single-year age and sex from INE's Padron Municipal Continuo, per the SHMD Protocol (Section 12, Step 3: "Population Estimates"). Covers 1996-present; pre-1996 years require the intercensal survival method applied to the 1981/1991 censuses, which is out of scope here.
get_ine_population(
table_id = 56945,
n_periods = 30,
use_cache = TRUE,
force = FALSE,
cache_dir = NULL
)INE table ID. Default 56945 ("Poblacion residente por
fecha, sexo y edad (desde 1971)", provincial variant, operation ECP).
Pass NULL to auto-discover.
Number of most recent years to fetch.
Logical (default TRUE). If a previous call already
cached a result for this table_id/n_periods combination, return
it directly instead of re-fetching from INE, since this function's live
fetch (often via the slower CSV bulk-export fallback) is one of the
package's slowest. Set FALSE to always hit the network.
Logical (default FALSE). If TRUE, ignore any existing
cache and re-fetch from INE, refreshing the cache afterwards.
Directory for cached data. The default NULL caches
in a per-session directory under tempdir(): repeated calls in the same
session reuse the first download, but nothing persists afterwards. Pass a
directory, e.g. tools::R_user_dir("inedemogR", "cache"), for a cache
that persists across sessions. A cache stores the parsed result as
.rds; refresh it with force = TRUE. Results carry a provenance
attribute (request, retrieval time in UTC, API, package version).
list(data, qc): data is a tibble with columns ine_code,
nuts3_code, nuts2_code, province_name, year, age, female,
male, total; qc is the output of validate_population().
Some province x age x sex population tables are too large for INE's JSON API and are rejected outright; this function automatically falls back to INE's full CSV bulk export in that case (a larger download, but with no series-count limit).
if (FALSE) { # \dontrun{
# Not run: requires live network access to the INE API.
pop <- get_ine_population(n_periods = 10)
pop$data
# Re-fetch even if a cached copy exists:
pop <- get_ine_population(n_periods = 10, force = TRUE)
} # }