Retrieves, cleans, and validates Spanish annual live-birth counts by province and sex from INE's Tempus3 JSON API, per the SHMD Protocol (Section 12, Step 1: "Birth Count Assembly"). Unlike get_ine_demog() (which returns a Total-sex-only province count), this returns sex-disaggregated counts joined to NUTS-3 codes, suitable as an HMD-format Births input file - see download_ine_data() to write it to disk.

get_ine_births(
  table_id = 6506,
  n_periods = 100,
  use_cache = TRUE,
  force = FALSE,
  cache_dir = NULL
)

Arguments

table_id

INE Tempus3 table ID. Default 6506, confirmed for "Nacimientos por lugar de residencia de la madre y sexo. Total nacional y provincias" (operation MNPN). Pass NULL to auto-discover.

n_periods

Number of most recent years to fetch.

use_cache

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 — this function's live fetch is one of the package's slowest. Set FALSE to always hit the network.

force

Logical (default FALSE). If TRUE, ignore any existing cache and re-fetch from INE, refreshing the cache afterwards.

cache_dir

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

Value

list(data, qc): data is a tibble with columns ine_code, nuts3_code, nuts2_code, province_name, year, female, male, total; qc is the output of validate_births().

Examples

if (FALSE) { # \dontrun{
# Not run: requires live network access to the INE API.
births <- get_ine_births(n_periods = 30)
births$data
births$qc$issues

# Re-fetch even if a cached copy exists:
births <- get_ine_births(n_periods = 30, force = TRUE)
} # }