| Title: | National Statistical Office of Mongolia's Open Data API Handler | 
| Version: | 1.4.0 | 
| Date: | 2021-09-29 | 
| 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. | 
| Maintainer: | Makhgal Ganbold <makhgal@seas.num.edu.mn> | 
| URL: | https://github.com/galaamn/NSO1212 | 
| BugReports: | https://github.com/galaamn/NSO1212/issues | 
| Depends: | R (≥ 3.5.0) | 
| Imports: | httr, jsonlite | 
| License: | GPL-3 | 
| Encoding: | UTF-8 | 
| ByteCompile: | true | 
| NeedsCompilation: | no | 
| RoxygenNote: | 7.1.1 | 
| Packaged: | 2021-09-29 05:14:43 UTC; galaa | 
| Author: | Makhgal Ganbold [aut, cre] | 
| Repository: | CRAN | 
| Date/Publication: | 2021-09-29 07:10:20 UTC | 
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 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.
Author(s)
Makhgal Ganbold, National University of Mongolia
References
http://opendata.1212.mn/en/doc
Brief Information about All Database Tables
Description
Brief information about all available database tables on the open-data API which is supported by 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  | 
| timeout | positive numeric or  | 
| na.rm | logical: If  | 
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 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:
- 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, which are major classification of data, on the open-data API which is supported by 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  | 
| timeout | positive numeric or  | 
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 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:
- 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 minor classification of data, on the open-data API which is supported by 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  | 
| timeout | positive numeric or  | 
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 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:
- 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, 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 argumentPERIODof 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 which is supported by 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  | 
| timeout | positive numeric or  | 
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 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:
- 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)
}