← Back to all sparks
C

comtradr

ANALYTICS
Velocity2.5

Interface to the UN Comtrade international trade statistics API for R

comtradr's 1.0 line is a long tail of patches against a brittle UN trade API.

trade dataapi wrapperun comtradeerror handlingr
Current state
comtradr wraps the UN Comtrade API for international trade data in R, handling authentication, reference tables, caching and bulk downloads. The entire visible window is the 1.0 patch series: six releases, most of them repairs. The substantive additions are a variable-metadata reference table and automatic request splitting.
Where it's heading
The work is defensive, shaped by the API's constraints rather than by a roadmap. The 1.0.6 fix is representative: Comtrade rejects URLs longer than about 2000 characters, so the package now detects that before the request and transparently splits and recombines it. Running alongside is steady dependency hygiene, most recently swapping poorman for dplyr ahead of a CRAN archival.
Prediction
The release pattern points to more of the same, with error-message and edge-case repairs as users hit new API limits, rather than new endpoints.

Recent moves

  1. 13d ago

    Long code lists split automatically to avoid HTTP 414 errors

    Detects Comtrade's roughly 2000-character URL limit before sending, splitting partner and reporter codes across requests and recombining the results, which makes queries like partner = 'all_countries' work at last. Also swaps the soon-to-be-archived poorman dependency for dplyr and sharpens several error messages.

    View source ↗
  2. 8mo ago

    available_variables reference table exposes API metadata

    Adds an available_variables reference table mapping original Comtrade field names to the package's tidy column names with descriptions. Addresses the recurring problem of not knowing what a returned column actually means.

    View source ↗
  3. 10mo ago

    ISO alpha-2 codes added to reference tables

    Returns reporterCodeIsoAlpha2 and partnerCodeIsoAlpha2 from the reference tables and fixes a wrongly initialised object for EB02 services queries. Both fixes came from users.

    View source ↗
  4. 1y ago

    Patch restores tidy_cols after a regression

    Repairs a tidy column regression introduced by the previous patch, with tests added to catch it next time. Churn within the 1.0 stabilisation series.

    View source ↗
  5. 1y ago

    Fixes for tidy_cols argument and bulk small-file downloads

    Two contributed fixes: a missing return that made tidy_cols = FALSE impossible, and a file-size conversion bug that blocked bulk downloads of small files.

    View source ↗
  6. 2y ago

    Cache relocated to comply with CRAN policy

    Moves the cache out of the wrong directory to settle a CRAN policy violation, with ct_migrate_cache() offered to move existing files. Housekeeping, though it requires action from earlier users.

    View source ↗