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"):
include_world = FALSE (the default) drops them. The is_aggregate
column cannot be used to identify them: this endpoint never populates it.is_reported is a per-cell provenance flag, not a statement that a
country failed to report. Countries that reported in full still carry
FALSE cells, and commodity aggregates inherit the flag from any
estimated component.ct_get_data() now aborts with a pointer to ct_get_trade_matrix() when
called with commodity_classification = "TM", instead of the generic
"must be one of" message.
poorman dependency (scheduled for archival on CRAN) with
dplyr. This does not add any new transitive dependencies, as all of
dplyr's dependencies were already required through other imports.ct_get_bulk() now validates the frequency argument instead of failing
with an obscure object 'date_range' not found error.partner / partner_2 values 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 with argument "message" is missing
when reporting a failed copy.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. With process = FALSE splitting is not possible (a
single response object is returned) and a warning is issued instead.available_variables to ct_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:
ct_get_ref_table("available_variables")ct_perform_request()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
BULK DOWNLOAD ADDED: the function ct_get_bulk has 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
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_data and ct_get_ref_table, including parameter adjustments and usability improvements, mostly checks for all important parameters before the request is send out.
ct_commodity_db_type
ct_country_lookup
country_codes dataset for country codes.ct_search
ct_get_data() as an alternative.ct_update_databases
update parameter in ct_get_data.ct_use_pretty_cols
process argument in main functions.ct_get_reset_time
ct_get_remaining_hourly_queries
ct_register_token
set_primary_comtrade_key() instead.ct_search() to add support for commodity code ag6 (#30)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 arg commod_codes will 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 the SITCrev2 commodity type was returning raw HTML (as opposed to json data). (#27).
In func ct_country_lookup(), remove NA inputs from multi-country lookups (previously NA was being stringified and included in the pipe-separated regex lookup).
methods from Imports.ct_search() to allow for pulling all monthly data for an entire year in a single query (#14)ct_search(), expanded the valid input types for args start_date and end_date (#10).ct_search() now supports all commodity classifications offered by UN Comtrade (#16).ct_update_databases() are now properly preserved between R sessions (#11)."services" to arg type within function ct_search() now uses commodity classification EB02 by default (previously this would throw an error, fixes #6).EB02 within function ct_search(), passing "TOTAL" to arg commod_codes no longer returns zero results (#7).ct_commodity_lookup() no longer returns zero results when passing all caps input to arg search_terms (#9).ct_commodities_table and ct_countries_table.ct_update_databases, ct_use_pretty_cols, ct_commodity_db_type, ct_register_token, ct_get_reset_time, ct_get_remaining_hourly_queries.commodity_lookup is now ct_commodity_lookup, country_lookup is now ct_country_lookup.comtradr functions when necessary. This replaces the need for functions ct_commodities_table and ct_countries_table.ct_search.snake_case is being used throughout the package.ct_search now returns a data frame, as opposed to a list.ct_register_token).Imports changes: remove dplyr, add magrittr and purrr.commodity_lookup have been fixed by importing purrr and using purrr::map in place of sapply. This fixes issue #2 and issue #3.