R client for the ComexStat API — Brazilian foreign trade statistics from the Ministry of Development, Industry, Trade and Services (MDIC).
Features
- 30 functions covering all 38 API endpoints
- General trade data (1997–present), city-level data, and historical records (1989–1996)
- Auxiliary tables: countries, economic blocs, NCM/NBM/HS product codes, CGCE/SITC/ISIC classifications, states, cities, transport modes, customs units
- Multilingual: Portuguese, English, Spanish
- User-friendly parameter names mapped automatically to API names
Installation
# From GitHub
remotes::install_github("StrategicProjects/comexr")Quick start
library(comexr)
# Top export destinations in January 2024
exports <- comex_export(
start_period = "2024-01",
end_period = "2024-01",
details = "country"
)
exports
#> # A tibble: 219 × 4
#> year country metricFOB metricKG
#> <chr> <chr> <dbl> <dbl>
#> 1 2024 China 7812623070 19868234567
#> 2 2024 United States 3254810234 2547891234
#> ...
# Imports with CIF value
imports <- comex_import(
start_period = "2024-01",
end_period = "2024-01",
details = "country",
metric_cif = TRUE
)
# Filter: exports to China (160), grouped by HS4
soy <- comex_export(
start_period = "2024-01",
end_period = "2024-12",
details = c("country", "hs4"),
filters = list(country = 160),
month_detail = TRUE
)Discover available options
# What grouping fields are available?
comex_details("general")
# What filters can I use?
comex_filters("general")
# Look up country codes
comex_countries(search = "China")
# Economic blocs in Portuguese
comex_blocs(language = "pt")Function overview
Documentation
-
vignette("getting-started")— overview and first steps -
vignette("querying-trade-data")— advanced query patterns -
vignette("auxiliary-tables")— browsing product codes and classifications
API Reference
This package wraps the official ComexStat API documented at https://api-comexstat.mdic.gov.br/docs.