R client for the ComexStat API — Brazilian foreign trade statistics from the Ministry of Development, Industry, Trade and Services (MDIC).
# From GitHub
remotes::install_github("StrategicProjects/comexr")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
)# 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")| Category | Functions |
|---|---|
| Queries | comex_query(), comex_export(),
comex_import(), comex_query_city(),
comex_historical() |
| Metadata | comex_last_update(),
comex_available_years(), comex_filters(),
comex_filter_values(), comex_details(),
comex_metrics() |
| Geography | comex_countries(), comex_country_detail(),
comex_blocs(), comex_states(),
comex_state_detail(), comex_cities(),
comex_city_detail(), comex_transport_modes(),
comex_transport_mode_detail(),
comex_customs_units(),
comex_customs_unit_detail() |
| Products | comex_ncm(), comex_ncm_detail(),
comex_nbm(), comex_nbm_detail(),
comex_hs() |
| Classifications | comex_cgce(), comex_sitc(),
comex_isic() |
vignette("getting-started") — overview and first
stepsvignette("querying-trade-data") — advanced query
patternsvignette("auxiliary-tables") — browsing product codes
and classificationsThis package wraps the official ComexStat API documented at https://api-comexstat.mdic.gov.br/docs.
MIT