Package 'NSO1212'

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

Help Index


Brief Information about All Database Tables

Description

Brief information about all available database tables on the open-data API, which is supported by the National Statistical Office of Mongolia (NSO)

Usage

all_tables(try = FALSE, timeout = Inf, na.rm = FALSE)

Arguments

try

logical: Should the 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. You can not set it to less than 1 ms or 0.001 s.

na.rm

logical: If TRUE, it removes empty rows in a data frame that is the result of this function.

Details

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.

Value

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:

rownum

Row number

list_id

Sector number

tbl_id

Table identification number

tbl_nm

Table name in Mongolian

tbl_eng_nm

Table name in English

unit_id

Unit code

cd_nm

Unit name in Mongolian

cd_eng_nm

Unit name in English

strt_prd

Start date

end_prd

Finish date

prd_se

Time frequency

lst_chn_de

Last update date

References

http://opendata.1212.mn/en/doc/Api/GET-api-Itms

See Also

get_table, get_table_info, get_sector_info

Examples

all.tables <- all_tables(try = TRUE, timeout = 4)
if (!inherits(all.tables, "try-error")) {
  str(all.tables)
}

Detailed Information about All Main Sectors

Description

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)

Usage

get_sector_info(try = FALSE, timeout = Inf)

Arguments

try

logical: Should the 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. You can not set it to less than 1 ms or 0.001 s.

Details

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.

Value

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:

rownum

Row number

list_id

Sector identification number

up_list_id

Sub sector identification number

list_nm

Sector name in Mongolian

list_eng_nm

Sector name in English

isExist

Whether or exist sub-sectors

References

http://opendata.1212.mn/en/doc/Api/GET-api-Sector

See Also

all_tables, get_table, get_table_info, get_subsector_info

Examples

sector_info <- get_sector_info(try = TRUE, timeout = 4)
if (!inherits(sector_info, "try-error")) {
  print(sector_info)
}

Detailed Information about a Sub-Sector

Description

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

Usage

get_subsector_info(subid, try = FALSE, timeout = Inf)

Arguments

subid

character string, Sub-sector identification number

try

logical: Should the 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. You can not set it to less than 1 ms or 0.001 s.

Details

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.

Value

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:

rownum

Row number

list_id

Sector identification number

up_list_id

Sub sector identification number

list_nm

Sector name in Mongolian

list_eng_nm

Sector name in English

isExist

Whether or exist sub-sectors

References

http://opendata.1212.mn/en/doc/Api/GET-api-Sector_subid

See Also

all_tables, get_table, get_table_info, get_sector_info

Examples

subsector_info <- get_subsector_info("976_L05", try = TRUE, timeout = 4)
if (!inherits(subsector_info, "try-error")) {
  print(subsector_info)
}

Download a Database Table

Description

It downloads a database table containing statistical data from the open-data API supported by the 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 try? See details.

timeout

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

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.

Details

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.

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 the 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 that contains an API compatible period

Functions

  • make_period(): It is used to prepare values for the argument PERIOD 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)
}

Detailed Information about a Database Table and Its Classification

Description

Detailed information about a database table and its classification on the open-data API supported by the National Statistical Office of Mongolia (NSO)

Usage

get_table_info(tbl_id, simplify = FALSE, try = FALSE, timeout = Inf)

Arguments

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 try? See details.

timeout

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

Details

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.

Value

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:

tbl_id

Table identification number

unit_id

Unit identification number

unit_nm

Unit name in Mongolia

unit_eng_nm

Unit name in English

obj

Table classification:

obj_var_id

Variable identification

var_ord_sn

Variable identification number

field

Field name

scr_mn

Variable name in Mongolian

scr_eng

Variable identification

itm

Variable classification and code:

itm_id

Classification number

up_itm_id

Sub-classification

scr_mn

Classification name in Mongolian

scr_eng

Classification name in English

if simplify is TRUE, an user-friendly result is returned.

References

http://opendata.1212.mn/en/doc/Api/GET-api-Itms-id

See Also

all_tables, get_table, get_sector_info

Examples

# 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'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 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.

Author(s)

Makhgal Ganbold, National University of Mongolia

References

http://opendata.1212.mn/en/doc

See Also

Useful links: