Learn R Programming

tradestatistics (version 3.0.2)

ots_read_from_api: Reads data from the API (internal function)

Description

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_iso = NULL,
  partner_iso = NULL,
  commodity_code = "all",
  table = "yr",
  max_attempts = 5,
  use_localhost = FALSE
)

Arguments

year

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

reporter_iso

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

partner_iso

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

commodity_code

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

table

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

max_attempts

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

use_localhost

Logical to determine if the base URL shall be localhost instead of api.tradestatistics.io. Default set to FALSE.

Examples

Run this code
if (FALSE) {
# The next examples can take more than 5 seconds to compute,
# so these are 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_iso = "chl", partner_iso = "chn")

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

Run the code above in your browser using DataLab