| Title: | 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 <http://opendata.1212.mn/en/doc>. 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 v2.0 and get data sets and detailed information from the API. |
| Authors: | Makhgal Ganbold [aut, cre] |
| Maintainer: | Makhgal Ganbold <[email protected]> |
| License: | GPL-3 |
| Version: | 1.5.0 |
| Built: | 2026-06-05 08:10:47 UTC |
| Source: | https://github.com/makhgal-ganbold/nso1212 |
Brief information about all available database tables on the open-data API, which is supported by the National Statistical Office of Mongolia (NSO)
all_tables(try = FALSE, timeout = Inf, na.rm = FALSE)all_tables(try = FALSE, timeout = Inf, na.rm = FALSE)
try |
logical: Should the body of the function be wrapped by the function |
timeout |
positive numeric or |
na.rm |
logical: If |
The NSO server returns "HTTP error 500" frequently. Due to the server error, it needs error handling. If try is TRUE, you must write code with error handling, as shown in the example.
If the function is executed without error, it returns a data frame with brief information about all available database tables. Otherwise, it returns a class "try-error" object containing the error message. The data frame has the following structure:
Row number
Sector number
Table identification number
Table name in Mongolian
Table name in English
Unit code
Unit name in Mongolian
Unit name in English
Start date
Finish date
Time frequency
Last update date
http://opendata.1212.mn/en/doc/Api/GET-api-Itms
get_table, get_table_info, get_sector_info
all.tables <- all_tables(try = TRUE, timeout = 4) if (!inherits(all.tables, "try-error")) { str(all.tables) }all.tables <- all_tables(try = TRUE, timeout = 4) if (!inherits(all.tables, "try-error")) { str(all.tables) }
Detailed information about all main sectors is the primary classification of data on the open-data API supported by the National Statistical Office of Mongolia (NSO)
get_sector_info(try = FALSE, timeout = Inf)get_sector_info(try = FALSE, timeout = Inf)
try |
logical: Should the body of the function be wrapped by the function |
timeout |
positive numeric or |
The NSO server returns "HTTP error 500" frequently. Due to the server error, it needs error handling. If try is TRUE, you must write code with error handling, as shown in the example.
If the function is executed without error, it returns a data frame that includes sector information. Otherwise, it returns a class "try-error" object containing the error message. The data frame has the following structure:
Row number
Sector identification number
Sub sector identification number
Sector name in Mongolian
Sector name in English
Whether or exist sub-sectors
http://opendata.1212.mn/en/doc/Api/GET-api-Sector
all_tables, get_table, get_table_info, get_subsector_info
sector_info <- get_sector_info(try = TRUE, timeout = 4) if (!inherits(sector_info, "try-error")) { print(sector_info) }sector_info <- get_sector_info(try = TRUE, timeout = 4) if (!inherits(sector_info, "try-error")) { print(sector_info) }
Detailed information about a sub-sector, which is the minor classification of data, on the open-data API supported by the National Statistical Office of Mongolia
get_subsector_info(subid, try = FALSE, timeout = Inf)get_subsector_info(subid, try = FALSE, timeout = Inf)
subid |
character string, Sub-sector identification number |
try |
logical: Should the body of the function be wrapped by the function |
timeout |
positive numeric or |
The NSO server returns "HTTP error 500" frequently. Due to the server error, it needs error handling. If try is TRUE, you must write code with error handling, as shown in the example.
If the function is executed without error, it returns a data frame that includes sub-sector information. If it fails, it returns an object of class "try-error" containing the error message. The data frame has the following structure:
Row number
Sector identification number
Sub sector identification number
Sector name in Mongolian
Sector name in English
Whether or exist sub-sectors
http://opendata.1212.mn/en/doc/Api/GET-api-Sector_subid
all_tables, get_table, get_table_info, get_sector_info
subsector_info <- get_subsector_info("976_L05", try = TRUE, timeout = 4) if (!inherits(subsector_info, "try-error")) { print(subsector_info) }subsector_info <- get_subsector_info("976_L05", try = TRUE, timeout = 4) if (!inherits(subsector_info, "try-error")) { print(subsector_info) }
It downloads a database table containing statistical data from the open-data API supported by the National Statistical Office of Mongolia (NSO).
get_table( tbl_id, PERIOD = NULL, CODE = NULL, CODE1 = NULL, CODE2 = NULL, try = FALSE, timeout = Inf ) make_period(start, end = NULL, period = "Y")get_table( tbl_id, PERIOD = NULL, CODE = NULL, CODE1 = NULL, CODE2 = NULL, try = FALSE, timeout = Inf ) make_period(start, end = NULL, period = "Y")
tbl_id |
character string, Table identification number |
PERIOD |
character vector, Time |
CODE, CODE1, CODE2
|
character vector, Classification code (age, gender etc) |
try |
logical: Should the main body of the function be wrapped by the function |
timeout |
positive numeric or |
start, end
|
The starting and stopping moments of a period have the following formats: "YYYY", "YYYYMM", "YYYYMMDD", "YYYYQQ". Notations YYYY, MM, DD, and QQ, respectively, indicate a date's year, month, day, and quarter. If necessary, write it as a number that has a leading zero. |
period |
One of the following letters: "Y" (default), "M", "D", and "Q" respectively represent periods yearly, monthly, daily, and quarterly. There is another value (F) that means no specific time period; you cannot use it for this function. |
The NSO server returns "HTTP error 500" frequently. Due to the server error, it needs error handling. If try is TRUE, you must write code with error handling, as shown in the example.
A data frame if the function is executed without error, but an object of class "try-error" containing the error message if it fails. The data frame has the following structure:
Row number
Time
Classification code
Classification name in Mongolian
Classification name in English
Classification code
Classification name in Mongolian
Classification name in English
Classification code
Classification name in Mongolian
Classification name in English
Datum
A character vector that contains an API compatible period
make_period(): It is used to prepare values for the argument PERIOD of the function get_table.
http://opendata.1212.mn/en/doc/Api/POST-api-Data
all_tables, get_table_info, get_sector_info
nso.data <- get_table( tbl_id = "DT_NSO_2400_015V2", PERIOD = make_period(start = "201711", end = "202103", period = "M"), CODE = c("10", "11"), CODE1 = "11", try = TRUE, # to prevent a server error timeout = 4 ) if (!inherits(nso.data, "try-error")) { print(nso.data) }nso.data <- get_table( tbl_id = "DT_NSO_2400_015V2", PERIOD = make_period(start = "201711", end = "202103", period = "M"), CODE = c("10", "11"), CODE1 = "11", try = TRUE, # to prevent a server error timeout = 4 ) if (!inherits(nso.data, "try-error")) { print(nso.data) }
Detailed information about a database table and its classification on the open-data API supported by the National Statistical Office of Mongolia (NSO)
get_table_info(tbl_id, simplify = FALSE, try = FALSE, timeout = Inf)get_table_info(tbl_id, simplify = FALSE, try = FALSE, timeout = Inf)
tbl_id |
character string, Table identification number |
simplify |
logical: Should the result be simplified to a vector and a data frame? |
try |
logical: Should the body of the function be wrapped by the function |
timeout |
positive numeric or |
The NSO server returns "HTTP error 500" frequently. Due to the server error, it needs error handling. If try is TRUE, you must write code with error handling, as shown in the example.
If the function is executed without error, it returns a list that includes detailed information about the database table and its classification. If it fails, it returns an object of class "try-error" containing the error message. The list has the following structure:
Table identification number
Unit identification number
Unit name in Mongolia
Unit name in English
Table classification:
Variable identification
Variable identification number
Field name
Variable name in Mongolian
Variable identification
Variable classification and code:
Classification number
Sub-classification
Classification name in Mongolian
Classification name in English
if simplify is TRUE, an user-friendly result is returned.
http://opendata.1212.mn/en/doc/Api/GET-api-Itms-id
all_tables, get_table, get_sector_info
# tree shaped result table_info <- get_table_info("DT_NSO_2400_015V2", try = TRUE,, timeout = 4) if (!inherits(table_info, "try-error")) { str(table_info) } # tabular result table_info_simplified <- get_table_info( "DT_NSO_2400_015V2", simplify = TRUE, try = TRUE, timeout = 4) if (!inherits(table_info_simplified, "try-error")) { str(table_info_simplified) }# tree shaped result table_info <- get_table_info("DT_NSO_2400_015V2", try = TRUE,, timeout = 4) if (!inherits(table_info, "try-error")) { str(table_info) } # tabular result table_info_simplified <- get_table_info( "DT_NSO_2400_015V2", simplify = TRUE, try = TRUE, timeout = 4) if (!inherits(table_info_simplified, "try-error")) { str(table_info_simplified) }
The National Statistical Office of Mongolia (NSO) is the national statistical service and an organization of the Mongolian government. NSO provides open access to official data via its open-data API. The package NSO1212 has functions for accessing the API service. The functions are compatible with API v2.0 and get data sets or their detailed information from the API.
Makhgal Ganbold, National University of Mongolia
http://opendata.1212.mn/en/doc
Useful links:
Report bugs at https://github.com/makhgal-ganbold/NSO1212/issues