Title: | Open Trade Statistics API Wrapper and Utility Program |
---|---|
Description: | Access 'Open Trade Statistics' API from R to download international trade data. |
Authors: | Mauricio Vargas [aut, cre, cph] , Joshua Kunst [ctb] (contributed to different parts of the pre-release code), Alexey Kravchenko [ctb] (reviewed 2021 version of the API), Emma Mendelsohn [ctb] (updated the functions to take available years from the API instead of hardcoded values), Daniela de los Santos [ctb] (proposed improvements to default parameters), Emily Riederer [rev] (reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/274), Mark Padgham [rev] (reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/274), Amanda Dobbyn [rev] (reviewed a previous package that evolved into the current package for rOpenSci, see https://github.com/ropensci/onboarding/issues/217), Jorge Cimentada [rev] (reviewed a previous package that evolved into the current package for rOpenSci, see https://github.com/ropensci/onboarding/issues/217), UN Comtrade [dtc], The World Bank [dtc] |
Maintainer: | Mauricio Vargas <[email protected]> |
License: | Apache License (>= 2) |
Version: | 5.0.0 |
Built: | 2024-12-21 04:40:46 UTC |
Source: | https://github.com/ropensci/tradestatistics |
Official commodity names from the Harmonized System rev 2012 (HS12, six digits detail).
ots_commodities
ots_commodities
A data frame with 5,302 observations on the following 4 variables
commodity_code
HS six digits commodity code (e.g. 010110)
commodity_code_short
HS four digits commodity code (e.g. 0101)
commodity_fullname_english
HS six digits commodity name (e.g. 'Horses, asses, mules and hinnies; live, pure-bred breeding animals')
section_code
HS section code (e.g. '01')
Open Trade Statistics
Official commodity names from the Harmonized System rev 2012 (HS12, four digits detail).
ots_commodities_short
ots_commodities_short
A data frame with 1,225 observations on the following 2 variables
commodity_code
HS four digits commodity code (e.g. 0101)
commodity_fullname_english
HS four digits commodity names (e.g. 'Horses, asses, mules and hinnies; live')
Open Trade Statistics
Takes a text string and searches within the package data for all matching commodity codes in the context of valid API commodity codes.
ots_commodity_code(commodity = NULL, section = NULL)
ots_commodity_code(commodity = NULL, section = NULL)
commodity |
A text string such as "Animals", "COPPER" or "fruits". |
section |
A text string such as "meat", "FISH" or "Dairy". |
A tibble with all possible matches (no uppercase distinction) showing the commodity name and commodity code
ots_commodity_code(commodity = "ANIMALS ") ots_commodity_code(section = " fish") ots_commodity_code(commodity = "Milk", section = "Dairy")
ots_commodity_code(commodity = "ANIMALS ") ots_commodity_code(section = " fish") ots_commodity_code(commodity = "Milk", section = "Dairy")
Official country names, ISO-3 codes, continent and EU membership.
ots_countries
ots_countries
A data frame with 275 observations on the following 5 variables
country_iso
ISO-3 code of the country (e.g. "deu" means Germany)
country_name_english
Country name (e.g. Germany)
country_fullname_english
Country name with indications (e.g. Germany as "Germany (former Federal Republic of Germany until 1990)")
continent_name_english
Continent where the country belongs to (e.g., Europe)
continent_id
Numeric id of the continent where the country belongs to (e.g., 5)
Open Trade Statistics
Unofficial colors to ease visualization for countries.
ots_countries_colors
ots_countries_colors
A data frame with 275 rows and 3 variables
country_iso
ISO code of the country (e.g. "chl" means Chile)
continent_id
Numeric id of the continent
country_color
Country hex color (e.g. '#D05555')
Open Trade Statistics
Takes a text string and searches within the package data for a country code in the context of valid API country codes.
ots_country_code(countryname = NULL)
ots_country_code(countryname = NULL)
countryname |
A text string such as "Chile", "CHILE" or "CHL". |
A single character if there is a exact match (e.g.
ots_country_code("Chile")
) or a tibble in case of multiple matches
(e.g. ots_country_code("Germany")
)
ots_country_code("Chile ") ots_country_code("america") ots_country_code("UNITED STATES") ots_country_code(" united_")
ots_country_code("Chile ") ots_country_code("america") ots_country_code("UNITED STATES") ots_country_code(" united_")
Accesses api.tradestatistics.io
and
performs different API calls to transform and return tidy data.
ots_create_tidy_data( years = 2020, reporters = "all", partners = "all", commodities = "all", sections = "all", table = "yr", max_attempts = 5, use_cache = FALSE, file = NULL )
ots_create_tidy_data( years = 2020, reporters = "all", partners = "all", commodities = "all", sections = "all", table = "yr", max_attempts = 5, use_cache = FALSE, file = NULL )
years |
Year contained within the years specified in
api.tradestatistics.io/year_range (e.g. |
reporters |
ISO code for reporter country (e.g. |
partners |
ISO code for partner country (e.g. |
commodities |
HS commodity codes (e.g. |
sections |
HS section codes (e.g. |
table |
Character string to select the table to obtain the data.
Default set to |
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 |
use_cache |
Logical to save and load from cache. If |
file |
Optional character with the full file path to save the data. Default set to |
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.
## Not run: # The next examples can take more than 5 seconds to compute, # so these are just shown without evaluation according to CRAN rules # Run `ots_countries` to display the full table of countries # Run `ots_commodities` to display the full table of commodities # What does Chile export to China? (2002) ots_create_tidy_data(years = 2002, reporters = "chl", partners = "chn") # What can we say about Horses export in Chile and the World? (2002) ots_create_tidy_data(years = 2002, commodities = "010110", table = "yc") ots_create_tidy_data(years = 2002, reporters = "chl", commodities = "010110", table = "yrc") # What can we say about the different types of apples exported by Chile? (2002) ots_create_tidy_data(years = 2002, reporters = "chl", commodities = "apple", table = "yrc") ## End(Not run)
## Not run: # The next examples can take more than 5 seconds to compute, # so these are just shown without evaluation according to CRAN rules # Run `ots_countries` to display the full table of countries # Run `ots_commodities` to display the full table of commodities # What does Chile export to China? (2002) ots_create_tidy_data(years = 2002, reporters = "chl", partners = "chn") # What can we say about Horses export in Chile and the World? (2002) ots_create_tidy_data(years = 2002, commodities = "010110", table = "yc") ots_create_tidy_data(years = 2002, reporters = "chl", commodities = "010110", table = "yrc") # What can we say about the different types of apples exported by Chile? (2002) ots_create_tidy_data(years = 2002, reporters = "chl", commodities = "apple", table = "yrc") ## End(Not run)
Year to year GDP deflator some of the countries in the OTS database. For countries not available in the World Bank database, rows labelled as "wld" are provided, which were computed as the weighted median for each year using the GDP of listed countries for each year expressed as constant dollars of the year 2010.
ots_gdp_deflator
ots_gdp_deflator
A data frame with 8,010 observations on the following 4 variables
year_from
Integer values in the range 1980-2020
year_to
Integer values in the range 1981-2021
country_iso
ISO code of the country (e.g. "chl" means Chile)
gdp_deflator
Numeric value expressed as one plus 1-year deflator
Open Trade Statistics
Uses GDP deflator records from The World Bank to convert trade records and express them in dollars of the same year. The records are internally subsetted to World's values, because country specific levels would largely re-scale observations for reporters that reflect unstable macroeconomic policies.
ots_gdp_deflator_adjustment(trade_data = NULL, reference_year = NULL)
ots_gdp_deflator_adjustment(trade_data = NULL, reference_year = NULL)
trade_data |
A tibble obtained by using ots_create_tidy_data.
Default set to |
reference_year |
Year contained within the years specified in
api.tradestatistics.io/year_range (e.g. |
## Not run: # The next example can take more than 5 seconds to compute, # so this is shown without evaluation according to CRAN rules # Convert dollars of 2010 to dollars of 2000 d <- ots_create_tidy_data(years = 2010, reporters = "chl", partners = "chn") ots_gdp_deflator_adjustment(trade_data = d, reference_year = 2000) ## End(Not run)
## Not run: # The next example can take more than 5 seconds to compute, # so this is shown without evaluation according to CRAN rules # Convert dollars of 2010 to dollars of 2000 d <- ots_create_tidy_data(years = 2010, reporters = "chl", partners = "chn") ots_gdp_deflator_adjustment(trade_data = d, reference_year = 2000) ## End(Not run)
Official section names from the Harmonized System rev 2012 (HS12).
ots_sections
ots_sections
A data frame with 22 rows and 2 variables
section_code
HS section code (e.g. '01')
section_fullname_english
HS section name (e.g. 'Live animals and animal products')
Adapted from UN COMTRADE
Unofficial colors to ease visualization for the sections in the Harmonized System rev 2012 (HS12).
ots_sections_colors
ots_sections_colors
A data frame with 22 rows and 2 variables
section_code
HS section code (e.g. '01')
section_color
HS section color (e.g. '#74c0e2')
Open Trade Statistics
Existing API tables with both description and source.
ots_tables
ots_tables
A data frame with 12 rows and 3 variables
table
Table name
description
Description of table contents
source
Source for the data (OTS tables are processed after UN Comtrade raw data)
Open Trade Statistics