get_data: Get Data from UN COMMTRADE API

Description Usage Arguments Value See Also

View source: R/get_data.R

Description

This function takes user input and creates a single query to the UN COMMTRADE API for the requested trade data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
get_data(
  type = "C",
  trade_flow = "1,2",
  frequency = "A",
  time_period = "now",
  classification = "HS",
  codes = "TOTAL",
  reporter = "all",
  partner = "0",
  max_records = "100000",
  header = "H",
  format = "json"
)

Arguments

type

Refers to type of trade and takes a character string. Takes values of "C" (commodities), "S"(Services) or "any" (all trade). Default Value is "C"

trade_flow

Refers to the specific trade flow (imports or exports) and takes a character string. Can be "1", "2", "3", or "4" for Imports, Exports Re-Exports, or Re-Imports respectively as well as "all" (all trade flows). Can pass in multiple elements as a single comma separated character string. Default value is "1,2" for imports and exports.

frequency

Refers to the frequency of reporting and takes a character string. Takes values of "A" (annual trade), "M" (monthly trade) or "all" (any trade). Default is "A"

time_period

Refers to the time periods desired and takes a character string. Takes values of the format "YYYY" for years or "YYYYMM" for specific months or "now" for the most recent month/year with data. Can take a maximum of 5 entries of specific dates entered as a single comma separated character string. Default is "now"

classification

Refers to the classification scheme used to define traded products and takes a character string. For commodities trade can be it "HS" (harmonized trade or HS classification), "ST" (standard international trade classification or SITC classification), or"BEC" (Broad economic catagories). Can also enter specific revision numbers (ie "S1" for SITC1 or "H1" for HS1) For service trade it can be "EB02" (Extended Balance of Payments Services Classification). It can also be "all" for all classifications. Default is "HS"

codes

Refers to the level of detail in the product classification and takes a character string. Refers to the desired level of detail and varies by classification. Generally can be "ALL" (all codes in a classification), "TOTAL" (total trade between countries with no detail breakdown). Specific levels of aggregation ie can enter (AG1 AG2 AG3 AG4 AG5 AG6) are available depending on classification choice. It is also possible to enter commodity codes directly, up to a maximum of 20 (see classification scheme documents for codes). Default is "TOTAL"

reporter

Character string. takes on the UN numeric country code for a country or the code "all" (all countries). see (https://comtrade.un.org/Data/cache/reporterAreas.json) Can take a maximum of 5 specific country codes entered as a single comma separated character string. Default is "all".

partner

character string. takes on the UN numeric country code for a country or the code "all" (all countries). see (https://comtrade.un.org/Data/cache/reporterAreas.json) Can take a maximum of 5 specific country codes entered as a single comma separated character string. Default is "0" which is the numeric code for World.

max_records

Character string. Parameter from the API determining the size of download. Default is set to 10000 which is max for public use of API without registration.

header

Character string. Parameter regarding variable names. Default is H which is more human readable. Can be M which is easier for computer parsing.

format

Character string. File format download. Default is json can be CSV. Do not change this.

Value

If query successful: A named list containing information about the query as well as an element named "dataset" containing a dataframe of the returned data. If connection error: returns a number representing the HTTP status/error code.

See Also

Documents for UN COMMTRADE API. Available at https://comtrade.un.org/Data/Doc/API


jlesniak12/UNcommtradeAPI documentation built on Jan. 10, 2021, 12:07 a.m.