| Title: | National Statistical Office of Mongolia's Open Data API Handler |
| Version: | 2.0.0 |
| Date: | 2026-11-26 |
| Description: | The National Statistical Office of Mongolia (NSO) is the national statistical service and an organization of the Mongolian government. NSO distributes data sets freely available for open access via its API https://www.1212.mn/en/data-base/open-data. NSO1212 is an R package that contains functions for effortlessly accessing such data through NSO’s API. Importing data with the package has an advantage in filtering and tidying data for further processing and analysis. The functions are compatible with the API v1.0 and get data sets and detailed information from the API. |
| Maintainer: | Makhgal Ganbold <makhgal@num.edu.mn> |
| URL: | https://github.com/makhgal-ganbold/NSO1212 |
| BugReports: | https://github.com/makhgal-ganbold/NSO1212/issues |
| Depends: | R (≥ 4.6.0) |
| Imports: | httr2, jsonlite |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| ByteCompile: | true |
| NeedsCompilation: | no |
| Config/roxygen2/version: | 8.1.1 |
| Packaged: | 2026-11-26 15:38:40 UTC; galaa |
| Author: | Makhgal Ganbold [aut, cre] |
| Repository: | CRAN |
| Date/Publication: | 2026-11-26 16:10:02 UTC |
National Statistical Office of Mongolia's Open Data API Handler
Description
The National Statistical Office of Mongolia (NSO) is the national statistical service and an organization of the Mongolian government. NSO distributes data sets freely available for open access via its API. NSO1212 is an R package that contains functions for effortlessly accessing such data through NSO’s API. Importing data with the package has an advantage in filtering and tidying data for further processing and analysis. The functions are compatible with the API v1.0 and get data sets and detailed information from the API.
Author(s)
Makhgal Ganbold, National University of Mongolia
References
https://www.1212.mn/en/data-base/open-data
See Also
Useful links:
Report bugs at https://github.com/makhgal-ganbold/NSO1212/issues
Retrieve statistical data from the 1212.mn API v1
Description
Performs a filtered data request to the 1212.mn API for a specific table, validates the 'query' structure and filter values against table metadata, sends a POST request, and attaches a 'data.frame' ('df') to the parsed response.
Usage
nso_data(sector_id, subsector_id, table_id, query, language = "mn")
Arguments
sector_id |
Character scalar. The ID of the sector containing the desired table. |
subsector_id |
Character scalar. The ID of the subsector belonging to the given sector. |
table_id |
Character scalar. The ID of the table within the given subsector. |
query |
List. A JSON-stat2 query list containing 'query' selections and 'response = list(format = "json-stat2")'. |
language |
Character scalar. Language of the data ('"mn"' or '"en"'). Any other value defaults to '"mn"'. |
Value
A named list representing the JSON API response with an added element 'df' containing the resulting 'data.frame'.
References
https://www.1212.mn/en/data-base/open-data
See Also
Examples
# download table meta data
tbl_meta <- nso_table(
sector_id = "Population, household",
subsector_id = "1_Population, household",
table_id = "DT_NSO_0300_004V1.px",
language = "en"
)
# table caption
tbl_meta$title
# the number of codes
length(tbl_meta$variables)
# code values
tbl_meta$variables[[1]]
tbl_meta$variables[[2]]
tbl_meta$variables[[3]]
# query
'{
"query": [
{"code": "%s", "selection": {"filter": "item", "values": ["0"]}},
{"code": "%s", "selection": {"filter": "item", "values": ["0"]}},
{"code": "%s", "selection": {"filter": "item", "values": ["0", "1"]}}
],
"response": {"format": "json-stat2"}
}' |>
sprintf( # To bypass the non-ASCII character limitation
tbl_meta$variables[[1]]$code,
tbl_meta$variables[[2]]$code,
tbl_meta$variables[[3]]$code
) ->
query
# download data
data <- nso_data(
sector_id = "Population, household",
subsector_id = "1_Population, household",
table_id = "DT_NSO_0300_004V1.px",
query = query,
language = "en"
)
# print downloaded data
print(data$df)
Retrieve sector IDs and names from the 1212.mn API v1
Description
Fetches top-level sector information from the 1212.mn API v1 and returns it as a 'data.frame'.
Usage
nso_sectors(language = "mn")
Arguments
language |
Character scalar. Language code, '"mn"' or '"en"'. Any other non-empty character value defaults to '"mn"' (default '"mn"'). |
Value
A 'data.frame' containing sector metadata from the API.
References
https://www.1212.mn/en/data-base/open-data
See Also
Examples
sectors <- nso_sectors(language = "en")
print(sectors)
Retrieve subsector IDs and names for a specific sector from the 1212.mn API v1
Description
Validates 'sector_id' against available top-level sectors, fetches subsector information from the 1212.mn API v1, and returns it as a 'data.frame'.
Usage
nso_subsectors(sector_id, language = "mn")
Arguments
sector_id |
Character scalar. Identifier of the parent sector. |
language |
Character scalar. Language code, '"mn"' or '"en"'. Any other non-empty character value defaults to '"mn"' (default '"mn"'). |
Value
A 'data.frame' containing subsector data for the given sector.
References
https://www.1212.mn/en/data-base/open-data
See Also
Examples
subsectors <- nso_subsectors(
sector_id = "Population, household",
language = "en"
)
print(subsectors)
Retrieve metadata for a specific statistical table from the 1212.mn API v1
Description
Validates that 'table_id' belongs to the specified 'subsector_id' and 'sector_id', fetches the table metadata from the 1212.mn API v1, and converts each variable's 'values' and 'valueTexts' into a 'codes' data frame.
Usage
nso_table(sector_id, subsector_id, table_id, language = "mn")
Arguments
sector_id |
Character or numeric scalar. Identifier of the parent sector. |
subsector_id |
Character or numeric scalar. Identifier of the subsector belonging to 'sector_id'. |
table_id |
Character or numeric scalar. Identifier of the table within the given subsector. |
language |
Character scalar. Language code, '"mn"' or '"en"'. Any other non-empty character value defaults to '"mn"' (default '"mn"'). |
Value
A named 'list' containing table metadata with structured 'variables'.
References
https://www.1212.mn/en/data-base/open-data
See Also
Examples
# download table meta data
tbl_meta <- nso_table(
sector_id = "Population, household",
subsector_id = "1_Population, household",
table_id = "DT_NSO_0300_004V1.px",
language = "en"
)
# table caption
tbl_meta$title
# the number of codes
length(tbl_meta$variables)
# code values
tbl_meta$variables[[1]]
Retrieve table IDs, names, and update metadata for a subsector
Description
Validates that 'subsector_id' belongs to 'sector_id', fetches the list of tables from the 1212.mn API v1, and returns it as a 'data.frame'.
Usage
nso_tables(sector_id, subsector_id, language = "mn")
Arguments
sector_id |
Character scalar. Identifier of the parent sector. |
subsector_id |
Character scalar. Identifier of the subsector belonging to 'sector_id'. |
language |
Character scalar. Language code, '"mn"' or '"en"'. Any other non-empty character value defaults to '"mn"' (default '"mn"'). |
Value
A 'data.frame' containing table metadata for the given subsector.
References
https://www.1212.mn/en/data-base/open-data
See Also
Examples
tables <- nso_tables(
sector_id = "Population, household",
subsector_id = "1_Population, household",
language = "en"
)
print(tables)