get_table {NSO1212} | R Documentation |
Download a Database Table
Description
It downloads a database table, which contains statistical data, from the open-data API which is supported by National Statistical Office of Mongolia (NSO).
Usage
get_table(
tbl_id,
PERIOD = NULL,
CODE = NULL,
CODE1 = NULL,
CODE2 = NULL,
try = FALSE,
timeout = Inf
)
make_period(start, end = NULL, period = "Y")
Arguments
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. |
Details
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.
Value
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:
- TBL_ID
Row number
- Period
Time
- CODE
Classification code
- SCR_MN
Classification name in Mongolian
- SCR_ENG
Classification name in English
- CODE1
Classification code
- SCR_MN1
Classification name in Mongolian
- SCR_ENG1
Classification name in English
- CODE2
Classification code
- SCR_MN2
Classification name in Mongolian
- SCR_ENG2
Classification name in English
- DTVAL_CO
Datum
a character vector which contains an API compatible period.
Functions
-
make_period
: It is used to prepare values for the argumentPERIOD
of the function get_table.
References
http://opendata.1212.mn/en/doc/Api/POST-api-Data
See Also
all_tables, get_table_info, get_sector_info
Examples
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)
}