Fetch statistical data for a table (PXWeb)
Arguments
- tbl_id
Table identifier (e.g., "DT_NSO_0300_001V2").
- selections
Named list mapping variable labels (e.g., Year, Sex) to desired codes or labels.
- labels
Label handling: "none" (codes only), "en", "mn", or "both". "code" is accepted as an alias for "none" (matching
nso_fetch()).- value_name
Name of the numeric value column in the result (default: "value").
- include_raw
If TRUE, attach the raw PX payload as attribute
px_raw(a list of payloads when the request was split, see below). Source provenance and observation status are retained separately in every result; inspect them withnso_provenance()andnso_value_status().
Time dimensions
NSO codes periods by position: in every table, code "0" is the latest
period, so a period's code changes whenever a new one is published. The
time dimension (years, quarters, months or dates) is therefore always
returned by its label, such as "2024" or "2024-03", whatever labels
is; nso_period_date() converts these labels to dates. Other dimensions
are returned as codes unless labels asks for labels.
Select periods by label (Year = "2024"), with nso_period_seq()
(Month = nso_period_seq("202401", "202412", by = "M")), or with
nso_latest_periods(). Periods match whatever format the table uses, so
"202403", "2024-03" and "2024M3" select the same month.
Large requests
Larger selections are split into requests under the configured cell limit.
nso_api_config() discovers server limits; cached limits and
mongolstats.max_cells are respected. The package coordinates NSO request
attempts on the same computer, including workers, at a conservative rate.
Examples
if (FALSE) { # identical(Sys.getenv("NOT_CRAN"), "true") && curl::has_internet()
# Population of Mongolia by sex in the two latest years
pop <- nso_data(
tbl_id = "DT_NSO_0300_001V2",
selections = list(
Sex = c("Male", "Female"),
Age = "Total",
Year = nso_latest_periods("DT_NSO_0300_001V2", n = 2)
),
labels = "en"
)
pop
}