comtradr 1.1.0
New Features
-
Added
ct_get_trade_matrix()to query the UN Comtrade estimated trade matrix endpoint. The returned reporter x partner matrix complements reported figures with UNSD estimates, so it also covers countries whose figures are otherwise absent. Commodities are classified by SITC and the endpoint provides annual goods data only.Two behaviors are worth knowing about, both documented in the new
vignette("trade_matrix"):- The endpoint returns aggregate “World” rows alongside the bilateral flows. Summing the raw response over-counts fourfold, so
include_world = FALSE(the default) drops them. Theis_aggregatecolumn cannot be used to identify them: this endpoint never populates it. -
is_reportedis a per-cell provenance flag, not a statement that a country failed to report. Countries that reported in full still carryFALSEcells, and commodity aggregates inherit the flag from any estimated component.
- The endpoint returns aggregate “World” rows alongside the bilateral flows. Summing the raw response over-counts fourfold, so
ct_get_data()now aborts with a pointer toct_get_trade_matrix()when called withcommodity_classification = "TM", instead of the generic “must be one of” message.
comtradr 1.0.6
CRAN release: 2026-07-30
Minor improvements
- Replaced the
poormandependency (scheduled for archival on CRAN) withdplyr. This does not add any new transitive dependencies, as all ofdplyr’s dependencies were already required through other imports.
Bug fixes
-
ct_get_bulk()now validates thefrequencyargument instead of failing with an obscureobject 'date_range' not founderror. - Invalid
partner/partner_2values now produce a readable error message that lists each invalid code once, instead of repeating the message for every code. -
ct_migrate_cache()no longer fails withargument "message" is missingwhen reporting a failed copy. - Fixed HTTP 414 “URI Too Long” errors when querying long code lists, e.g.
partner = "all_countries"(#103). The Comtrade API rejects URLs longer than about 2000 characters.ct_get_data()now detects this before performing the request, transparently splits the partner and/or reporter codes into multiple requests and combines the results into a single data.frame. Withprocess = FALSEsplitting is not possible (a single response object is returned) and a warning is issued instead.
comtradr 1.0.5
CRAN release: 2025-12-15
New Features
- Added
available_variablestoct_get_ref_table()to query comprehensive metadata about all Comtrade API variables. Returns variable descriptions, original API field names, and tidy column names in a single table. This makes it easy to:- Understand what each column in trade data represents
- Create data dictionaries for documentation
- Map between original and tidy column names Example:
ct_get_ref_table("available_variables")
comtradr 1.0.4
CRAN release: 2025-09-27
- patched ct_get_ref_table to also return reporterCodeIsoAlpha2 and partnerCodeIsoAlpha2, see: https://github.com/ropensci/comtradr/issues/94
- patched an error, where the wrong object was initialised for EB02 for querying services, see: https://github.com/ropensci/comtradr/issues/96
- thanks to luifrancgom and possakorn for pointing and fixing errors
comtradr 1.0.3
CRAN release: 2024-11-15
- this is a patch to fix a bug that was introduced when fixing the bug about tidy cols. Now tidy cols are returned again.
- testing for this error was introduced in the test environment to avoid this in the future.
comtradr 1.0.2
CRAN release: 2024-09-20
- this is a patch to fix two bugs in the package:
- a missing return in the call to tidy_cols did not allow users to set this argument to false, see https://github.com/ropensci/comtradr/issues/88 and commit 6f34592 (thanks @FATelarico)
- a missing parameter in the file size conversion function did not allow the bulk facility to download small files. This has been fixed.
comtradr 1.0.1
CRAN release: 2024-05-24
this is a patch to fix a CRAN policy violation, namely that the cache was written in the wrong directory due to using rappdirs.
If you have used comtradr prior to version 1.0.1 I recommend running
ct_migrate_cache()to copy files to the new cache and remove the old cache
comtradr 1.0.0
CRAN release: 2024-05-14
- with this update comtradr has reached full functionality, including bulk files
New features
BULK DOWNLOAD ADDED: the function
ct_get_bulkhas been added. It enables the use of the bulk download facility from Comtrade.Please see the vignette https://docs.ropensci.org/comtradr/articles/bulk_files.html for details
comtradr 0.4.0.0
CRAN release: 2024-02-06
- comtradr has received a complete overhaul. Please reference the Readme for all new functions and use-cases.
NEW FEATURES
Caching Functionality: Implemented enhanced caching features, and added a dedicated vignette explaining caching concepts. Environment variables allow for configuration of some caching features.
Functionality Updates: Major updates to key functions such as
ct_get_dataandct_get_ref_table, including parameter adjustments and usability improvements, mostly checks for all important parameters before the request is send out.
Deprecated in Version 0.4.0
-
ct_commodity_db_type
- Deprecated with no direct alternative.
-
ct_country_lookup
- Deprecated, use
country_codesdataset for country codes.
- Deprecated, use
-
ct_search
- Deprecated, use
ct_get_data()as an alternative.
- Deprecated, use
-
ct_update_databases
- Deprecated, utilize the
updateparameter inct_get_data.
- Deprecated, utilize the
-
ct_use_pretty_cols
- Deprecated, replaced by the
processargument in main functions.
- Deprecated, replaced by the
-
ct_get_reset_time
- Deprecated, no longer relevant due to daily call limit enforcement.
-
ct_get_remaining_hourly_queries
- Deprecated, as hourly reset time no longer exists.
-
ct_register_token
- Deprecated, use
set_primary_comtrade_key()instead.
- Deprecated, use
comtradr 0.3.0
CRAN release: 2022-04-20
NEW FEATURES
- Modifications to
ct_search()to add support for commodity codeag6(#30)
BUG FIXES
Function
ct_register_token()now checks if the provided token is recognized by the official API and only grants “premium” credentials if it is (#34).Passing an API token string to
ct_register_token()now properly bumps the hourly rate limit up to 10,000 (#21).In func
ct_search(), passing a character vector of long-form commodity descriptions to argcommod_codeswill now throw an error prior to making an API call, which would fail (#24).Update the country package data, to stay up to date with the reporter/partner country table that Comtrade is using. This is an update to the file
inst/extdata/country_table.rda. (#29).In func
ct_search(), improve error messaging when an input country is invalid. (#31).In func
ct_search(), fix bug in which running queries using theSITCrev2commodity type was returning raw HTML (as opposed to json data). (#27).In func
ct_country_lookup(), removeNAinputs from multi-country lookups (previouslyNAwas being stringified and included in the pipe-separated regex lookup).
comtradr 0.2.1
CRAN release: 2018-05-05
NEW FEATURES
- Modifications to
ct_search()to allow for pulling all monthly data for an entire year in a single query (#14) - For function
ct_search(), expanded the valid input types for argsstart_dateandend_date(#10).
BUG FIXES
-
ct_search()now supports all commodity classifications offered by UN Comtrade (#16). - The updates generated by function
ct_update_databases()are now properly preserved between R sessions (#11). - Passing
"services"to argtypewithin functionct_search()now uses commodity classificationEB02by default (previously this would throw an error, fixes #6). - When using commodity classification
EB02within functionct_search(), passing"TOTAL"to argcommod_codesno longer returns zero results (#7). -
ct_commodity_lookup()no longer returns zero results when passing all caps input to argsearch_terms(#9).
comtradr 0.1.0
CRAN release: 2017-10-24
PKG API CHANGES
- Eliminated functions
ct_commodities_tableandct_countries_table. - Added new functions
ct_update_databases,ct_use_pretty_cols,ct_commodity_db_type,ct_register_token,ct_get_reset_time,ct_get_remaining_hourly_queries. - Renamed functions:
commodity_lookupis nowct_commodity_lookup,country_lookupis nowct_country_lookup. - The commodity and country reference tables are now saved as cached package data, and accessed by
comtradrfunctions when necessary. This replaces the need for functionsct_commodities_tableandct_countries_table. - Reorder function arguments within function
ct_search. - Changed some function argument names to ensure
snake_caseis being used throughout the package. -
ct_searchnow returns a data frame, as opposed to a list.
MINOR CHANGES
- Added a vignette directory, with an “Intro to comtradr” vignette.
- API requests are now throttled based on the rate limits imposed by the UN Comtrade.
- Added function for setting a valid API key/token (
ct_register_token). - Appending API metadata to each returned data frame as attributes (url of the API call, date-time of the query, duration of the query in seconds).
- Added package level man page.
- Now using native R errors/warnings, as opposed to nesting API status codes in a returned list.
-
Importschanges: removedplyr, addmagrittrandpurrr. - Expand and improve test coverage via testthat.
BUG FIXES
- The issues related to type-safety in function
commodity_lookuphave been fixed by importingpurrrand usingpurrr::mapin place ofsapply. This fixes issue #2 and issue #3.
comtradr 0.0.2 (2017-07-03)
CRAN release: 2017-07-03
NEW FEATURES
- commodity_lookup(): Expanded function to accept multiple commodities or commodity codes (as either character vector or numeric vector). Also added argument “return_char” that allows the user to specify list output or char vector output, and argument “return_code” that specifies output of commodity descriptions or commodity codes.
MINOR IMPROVEMENTS
- Add unit tests via testthat.
