Title: | National Statistical Office of Mongolia's Open Data API Handler |
---|---|
Description: | National Statistical Office of Mongolia (NSO) is the national statistical service and an organization of Mongolian government. NSO provides open access to official data via its API <http://opendata.1212.mn/en/doc>. The package NSO1212 has functions for accessing the API service. The functions are compatible with the API v2.0 and get data sets and its detailed informations from the API. |
Authors: | Makhgal Ganbold [aut, cre] |
Maintainer: | Makhgal Ganbold <[email protected]> |
License: | GPL-3 |
Version: | 1.4.0 |
Built: | 2025-02-12 02:39:07 UTC |
Source: | https://github.com/makhgal-ganbold/nso1212 |
Brief information about all available database tables on the open-data API which is supported by 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, error handling is supported. if try
is TRUE
, you have to write code with error handling as shown in the example.
A data frame which has brief information of all available database tables 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 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, which are major classification of data, on the open-data API which is supported by 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, error handling is supported. if try
is TRUE
, you have to write code with error handling as shown in the example.
A data frame which has sector information 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 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 minor classification of data, on the open-data API which is supported by 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, error handling is supported. if try
is TRUE
, you have to write code with error handling as shown in the example.
A data frame which has sub-sector information 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 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, which contains statistical data, from the open-data API which is supported by 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
|
Starting and stopping moments of period which has following formats: "YYYY", "YYYYMM", "YYYYMMDD", "YYYYQQ". Notations YYYY, MM, DD and QQ, respectively, indicate year, month, day and quarter of a date. These are written as a number has a leading zero, if necessary. |
period |
One of single characters "Y" (default), "M", "D" and "Q" which represent periods yearly, monthly, daily and quarterly respectively. There is one more value "F" which is supported by the API. However it can not be used for such function due to there is not a fixed rule for this type of periods. |
The NSO server returns "HTTP error 500" frequently. Due to the server error, error handling is supported. if try
is TRUE
, you have to 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 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 which 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 which is supported by 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, error handling is supported. if try
is TRUE
, you have to write code with error handling as shown in the example.
A list which contains information about database table and its classification if the function is executed without error, but an object of class "try-error" containing the error message, if it fails. The list has 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) }
National Statistical Office of Mongolia (NSO) is the national statistical service and an organization of Mongolian government. NSO provides open access and official data via its open-data API. The package NSO1212 has functions for accessing the API service. The functions are compatible with the API v2.0 and get data-sets or its detailed information from the API.
Makhgal Ganbold, National University of Mongolia
http://opendata.1212.mn/en/doc