| 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] (ORCID: <https://orcid.org/0000-0003-1017-7574>), 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: | 7.1.0 |
| Built: | 2026-07-21 14:54:03 UTC |
| Source: | https://github.com/cran/tradestatistics |
Official country names, ISO-3 codes, continent and EU membership.
ots_countriesots_countries
A data frame with 308 observations on the following 5 variables
countryOfficial name (e.g. United Kingdom)
iso3ISO-3 code (e.g. "GBR")
dynamic_codeDeambiguated ISO-3 code (e.g. "DEU.X" for East Germany)
continentCorresponding continent (e.g., Europe)
colourAssigned colour by continen (e.g., '#d1a1bc')
Derived from USITC
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, importers = "all", exporters = "all", sectors = "all", industries = "all", table = "itpde_imp", max_attempts = 5, use_cache = FALSE, file = NULL )ots_create_tidy_data( years = 2020, importers = "all", exporters = "all", sectors = "all", industries = "all", table = "itpde_imp", max_attempts = 5, use_cache = FALSE, file = NULL )
years |
Year contained within the years specified in
api.tradestatistics.io/year_range (e.g., |
importers |
Importers (e.g. |
exporters |
Exporters (e.g. |
sectors |
Sectors (e.g. |
industries |
Industries (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_sectors` to display the full table of sectors # Agricultural trade (sector) ots_create_tidy_data(years = 2020, sectors = "Agriculture", table = "itpde_sec") # Cereal products trade (industry-importer) ots_create_tidy_data(years = 2020, importers = "chl", industries = "Cereal products", table = "itpde_imp_ind") # Aggregate trade (bilateral) ots_create_tidy_data(years = 2020, importers = "chl", exporters = c("arg", "bra"), table = "itpde_imp_exp") ## 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_sectors` to display the full table of sectors # Agricultural trade (sector) ots_create_tidy_data(years = 2020, sectors = "Agriculture", table = "itpde_sec") # Cereal products trade (industry-importer) ots_create_tidy_data(years = 2020, importers = "chl", industries = "Cereal products", table = "itpde_imp_ind") # Aggregate trade (bilateral) ots_create_tidy_data(years = 2020, importers = "chl", exporters = c("arg", "bra"), table = "itpde_imp_exp") ## End(Not run)
Industry IDs.
ots_industriesots_industries
A data frame with 170 observations on the following 2 variables
industry_descrIndustry name (e.g. 'Wheat')
industry_idIndustry code (e.g. '1')
Derived from USITC
Takes a text string and searches within the package data for all matching industry IDs in the context of valid API industry codes.
ots_industry_code(industry = NULL)ots_industry_code(industry = NULL)
industry |
A text string such as "Wheat", "CEREAL" or "oilseed". |
A data frame with all possible matches (no uppercase distinction) showing the industry name and industry ID.
ots_industry_code("Wheat") ots_industry_code("cereal")ots_industry_code("Wheat") ots_industry_code("cereal")
Takes a text string and searches within the package data for all matching sector IDs in the context of valid API sector codes.
ots_sector_code(sector = NULL)ots_sector_code(sector = NULL)
sector |
A text string such as "Agriculture", "MINING" or "serv". |
A data frame with all possible matches (no uppercase distinction) showing the sector name and sector ID.
ots_sector_code("Agriculture") ots_sector_code("mining")ots_sector_code("Agriculture") ots_sector_code("mining")
Broad sector IDs.
ots_sectorsots_sectors
A data frame with 4 observations on the following 2 variables
broad_sectorSector name (e.g. 'Agriculture')
broad_sector_idSector code (e.g. '1')
colourSector colour (e.g., '#74c0e2')
Derived from USITC
Existing API tables with both description and source.
ots_tablesots_tables
A data frame with 30 rows and 3 variables
tableTable name
descriptionDescription of table contents
sourceSource for the data
Derived from USITC