tradestatistics (version 0.2)

ots_read_from_api: Reads data from the API (internal function)

Description

This function accesses api.tradestatistics.io and performs different API calls to return data.frames by reading JSON data

Usage

ots_read_from_api(year = NULL, reporter = NULL, partner = NULL,
  product_code = "all", product_code_length = 4, table = "yrpc",
  max_attempts = 5)

Arguments

year

Year contained within the years specified in api.tradestatistics.io/year_range (e.g. 1980). Default set to NULL.

reporter

ISO code for reporter country (e.g. "chl"). Default set to NULL.

partner

ISO code for partner country (e.g. "chl"). Default set to NULL.

product_code

HS code (e.g. 0101 or 01) to filter products. Default set to "all".

product_code_length

Integer to indicate the granularity level on products. Default set to 4.

table

Character string to select the table to obtain the data. Default set to yrpc (Year - Reporter - Partner - product).

max_attempts

Number of attempts to retry in case of data retrieving failure. Default set to 5. ots_create_tidy_data.

Examples

Run this code
# NOT RUN {
# The next example can take more than 5 seconds to compute,
# so these are just shown without evaluation according to CRAN rules

# Run `countries` to display the full table of countries

# What does Chile export to China? (1980)
ots_read_from_api(year = 1980, reporter = "chl", partner = "chn")

# What can we say about chilean Horses export? (1980)
ots_read_from_api(year = 1980, product_code = "0101", table = "yc")
ots_read_from_api(year = 1980, reporter = "chl", product_code = "0101", table = "yrc")
ots_read_from_api(year = 1980, reporter = "chl", partner = "arg", product_code = "0101", 
table = "yrpc")
# }

Run the code above in your browser using DataCamp Workspace