get_table: Download a Database Table

Description Usage Arguments Details Value Functions References See Also Examples

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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 try? See details.

timeout

positive numeric or Inf: The number of seconds to wait for a response from the NSO server. Can not be less than 1 ms or 0.001 s.

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

References

http://opendata.1212.mn/en/doc/Api/POST-api-Data

See Also

all_tables, get_table_info, get_sector_info

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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)
}

galaamn/NSO1212 documentation built on Oct. 2, 2021, 12:06 p.m.