comexr 0.4.0
Breaking Changes
- Query results (
comex_query(),comex_export(),comex_import(),comex_query_city(),comex_historical()) are now typed:metric*columns are numeric andyear/monthNumberare integer. The API returns every value as a string, so previously all columns were character. Code that calledas.numeric()on metrics keeps working. - SSL verification is no longer disabled automatically. Previously any error mentioning “SSL”, “certificate” or “peer” (which also matched plain network errors such as “Connection reset by peer”) made the package retry without verification and silently set a global option for the rest of the session. SSL failures now raise an error explaining how to opt out with
options(comexr.ssl_verifypeer = FALSE). The old option namecomex.ssl_verifypeeris still honoured.
Bug Fixes
-
comex_historical()was failing with HTTP 403: the endpoint URL had a trailing slash (/historical-data/), which the API’s Cloudflare front now blocks. It now calls/historical-data. -
comex_historical()returned whole years even when the period asked for specific months (the API ignores months). Results are now trimmed to the requested months whenmonth_detail = TRUE, and a warning is issued whenmonth_detail = FALSEand the period is not whole years. - Fixed
could not find function "%||%"on R < 4.4.0 whenever the API returned an HTTP error (e.g. the 429 rate limit). -
filtersmust now be a named list; unnamed entries used to be dropped silently, returning unfiltered data. - Conversion errors in API responses are no longer swallowed into an empty data frame.
- Column names from the API are kept verbatim (no
make.names()mangling). -
validate_period()rejects invalid months (e.g."2023-13") and non-scalar input. - Documented the correct default for
month_detail(TRUE) incomex_query(),comex_export()andcomex_import().
Improvements
- Response parsing builds columns directly instead of binding one data frame per row: about 17x faster on 20,000 rows, and the gap widens with larger results.
-
typeincomex_last_update(),comex_available_years(),comex_filters(),comex_filter_values(),comex_details()andcomex_metrics()is validated withmatch.arg(). - Added an offline test suite (no network access required).
comexr 0.3.1
New Features
- Request timeout, number of retries, and retry backoff are now configurable through the options
comexr.timeout,comexr.max_triesandcomexr.retry_time. The default retry backoff was increased from 2 to 10 seconds to match the wait time the ComexStat API requests on HTTP 429 rate-limit errors. Thanks to Matt Bhagat-Conway- for the contribution (#1).
comexr 0.3.0
CRAN release: 2026-05-21
Breaking Changes
- Many user-friendly detail/filter aliases now map to the correct API names. Previous releases sent names that the ComexStat API rejects with HTTP 400 “Invalid detail item”. Behaviour now matches the live API as verified against
/general/detailsand/general/filters:-
"transport_mode"→via(wastransportMode) -
"hs6"/"sh6"→subHeading(wassh6) -
"hs4"/"sh4"→heading(wassh4) -
"hs2"/"sh2"→chapter(wassh2) -
"cgce_n1"/"cgce_n2"/"cgce_n3"→BECLevel1/2/3 -
"sitc_*"/"cuci_*"→SITCSection/SITCDivision/SITCGroup/SITCSubGroup/SITCBasicHeading -
"isic_*"→ISICSection/ISICDivision/ISICGroup/ISICClass
-
-
comex_query_city(): removedmetric_statisticparameter. The city endpoint only supportsmetricFOBandmetricKG. -
comex_isic(): rewritten to query/general/filters/ISIC*(the only place the API exposes ISIC values). Now takes alevelargument ("section","division","group","class") and no longer duplicatescomex_sitc()output.
Bug Fixes
- Removed
"company_size"from documented details — the API does not support a company-size detail/filter.
Documentation
-
comex_query(): detail list rewritten to show the user-friendly alias and the underlying API name for every option. -
comex_query_city(): corrected — HS6 (subheading) is not available for the city endpoint; product detail goes only down to HS4 (heading). Addedbloc/economic_blockto documented details. -
comex_historical(): documented the available filter names (country,bloc,state,nbm). -
comex_filter_values(): clarified that thefilterargument is case-sensitive and must matchcomex_filters()output verbatim (e.g."BECLevel1","SITCSection","ISICSection"). - New vignette
city-profile: reproduces the panels of the public ComexStat municipality page (comexstat.mdic.gov.br/{lang}/municipio/) — totals, top countries, top blocs, top HS4 products, monthly time series, year-over-year — usingcomex_query_city(). - New vignette
state-trade-profile: full state-level extract (Pernambuco example) combining the “By Municipality” panel filters — exports + imports, monthly detail, state filter, details by state / city / HS4 / section / HS2 / country — and showing how to derive trade balance, top municipalities, top products, top partners and year-over-year comparisons from the result.
comexr 0.2.0
CRAN release: 2026-03-10
Breaking Changes
-
comex_historical()no longer acceptsmetric_statistic,metric_freight,metric_insurance, ormetric_cifparameters. The historical API endpoint only supports FOB and KG metrics. -
month_detaildefault changed fromFALSEtoTRUEin all query functions.
Bug Fixes
- Fixed
blocdetail mapping: now correctly maps toeconomicBlock(API name). - Added missing detail mappings:
heading,chapter(city endpoint),nbm(historical endpoint),economic_block(alias). - Fixed
comex_metrics("general")returning 0 rows when thedependsfield contained NULL values. - Fixed
comex_ncm_detail(),comex_nbm_detail(), and other detail functions returning empty lists instead of named lists. - Fixed
comex_historical()endpoint path (added required trailing slash). - Fixed
response_to_tibble()failing on responses containing NULL or nested list values in row fields.
New Features
- SSL auto-fallback: the package now detects SSL certificate failures (common with the ICP-Brasil chain) and automatically retries without verification, issuing a one-time warning. Set
options(comex.ssl_verifypeer = FALSE)to suppress.
Documentation
- Corrected
comex_query_city()documentation: city endpoint usesheading,chapter,section— noths4,hs2,hs6. - Corrected
comex_historical()documentation: onlycountry,state, andnbmdetails are available (notncmorsection). - Updated
comex_filter_values()documentation with the actual filters that have value endpoints (6 for general, 7 for city, 2 for historical). - Renamed package from
comextocomexr.
comexr 0.1.0
Initial Release
- 30 exported functions covering all ComexStat API endpoints.
- General trade queries:
comex_query(),comex_export(),comex_import(). - City-level queries:
comex_query_city(). - Historical queries (1989-1996):
comex_historical(). - Metadata:
comex_last_update(),comex_available_years(),comex_filters(),comex_filter_values(),comex_details(),comex_metrics(). - Auxiliary tables for geography, products, and classifications.