Learn R Programming

tradestatistics (version 1.1)

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,
  product_code = "all",
  group_code = "all",
  section_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".

product_code

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

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.

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
# NOT RUN {
# 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, product_code = "0101", table = "yc")
ots_read_from_api(year = 1980, reporter_iso = "chl", product_code = "0101", table = "yrc")
ots_read_from_api(
  year = 1980, reporter_iso = "chl", partner_iso = "arg", product_code = "0101",
  table = "yrpc"
)
# }

Run the code above in your browser using DataLab