| ct_trade | R Documentation |
Download merchandise trade data from the UN Comtrade database. Returns bilateral trade flows between reporter and partner countries, optionally filtered by commodity code and trade flow direction.
ct_trade(
reporter,
partner = "0",
commodity = "TOTAL",
flow = c("X", "M"),
year = NULL,
frequency = "A",
classification = "HS",
cache = TRUE
)
reporter |
Character. Reporter country ISO3 code (e.g., |
partner |
Character. Partner country ISO3 code, or |
commodity |
Character. HS commodity code(s). |
flow |
Character. Trade flow: |
year |
Integer. Year(s) to query (1962-present). Can be a vector. Maximum 12-year span per query on the free tier. Default: most recent available year. |
frequency |
Character. |
classification |
Character. Commodity classification system. Default
|
cache |
Logical. Cache results locally for 24 hours. Default |
A data.frame with columns:
Reporter country code
Reporter country name
Partner country code
Partner country name
Trade flow code (X, M, RX, RM)
Trade flow description
Commodity code
Commodity description
Reference year
Reference period (year or year-month)
Trade value in US dollars
Net weight in kilograms
Quantity in supplementary units
Supplementary quantity unit
op <- options(comtrade.cache_dir = tempdir())
# UK total exports to the world, 2023
ct_trade("GBR", year = 2023, flow = "X")
# US imports of crude petroleum from Saudi Arabia
ct_trade("USA", partner = "SAU", commodity = "2709", flow = "M",
year = 2020:2023)
# Australia's top-level trade with China
ct_trade("AUS", partner = "CHN", year = 2023)
options(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.