tradestatistics (version 0.2)

ots_create_tidy_data: Downloads and processes the data from the API to return a human-readable tibble

Description

This function accesses api.tradestatistics.io and performs different API calls to transform and return tidy data.

Usage

ots_create_tidy_data(years = NULL, reporters = NULL, partners = NULL,
  products = "all", product_code_length = 4, table = "yrpc",
  max_attempts = 5, include_shortnames = FALSE,
  include_communities = FALSE)

Arguments

years

Year contained within the years specified in api.tradestatistics.io/year_range (e.g. c(1980,1985), c(1980:1981) or 1980). Default set to NULL.

reporters

ISO code for reporter country (e.g. "chl", Chile or c("chl", "Peru")). Default set to NULL.

partners

ISO code for partner country (e.g. "chl", Chile or c("chl", "Peru")). Default set to NULL.

products

HS codes (e.g. "0101", "01" or search matches for "apple") to filter products. Default set to "all".

product_code_length

Character string to indicate the granularity level on products Default set to 4 (it can also take the values 6 or all).

table

Character string to select the table to obtain the data. Default set to yrpc (Year - Reporter - Partner - Product Code). Run ots_attributes_tables in case of doubt.

max_attempts

How many times to try to download data in case the API or the internet connection fails when obtaining data. Default set to 5.

include_shortnames

Whether to include or not to include unofficial shortened product names. Default set to FALSE.

include_communities

Whether to include or not to include product communities. Default set to FALSE.

Value

A tibble that describes bilateral trade metrics (imports, exports, trade balance and relevant metrics such as exports growth w/r to last year) between a reporter and partner country.

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 `ots_attributes_countries` to display the full table of countries
# Run `ots_attributes_products` to display the full table of products

# What does Chile export to China? (1980)
ots_create_tidy_data(years = 1980, reporters = "chl", partners = "chn")

# What can we say about Horses export in Chile and the World? (1980)
ots_create_tidy_data(years = 1980, products = "0101", table = "yc")
ots_create_tidy_data(years = 1980, reporters = "chl", products = "0101", table = "yrc")

# What can we say about the different types of apples exported by Chile? (1980)
ots_create_tidy_data(years = 1980, reporters = "chl", products = "apple", table = "yrc")
# }

Run the code above in your browser using DataLab