Skip to contents

The Comtrade API requires that searches for specific commodities be done using commodity codes. This is a helper function for querying the Comtrade commodity database. It takes as input a vector of commodities or commodity codes. Output is a list or vector of commodity descriptions or codes associated with the input search_terms. For use with the UN Comtrade API, full API docs can be found at


  return_code = FALSE,
  commodity_classification = "HS",
  type = "goods",
  return_char = FALSE,
  verbose = TRUE, = TRUE,
  update = FALSE,



Commodity names or commodity codes, as a char or numeric vector.


Logical, if set to FALSE, the function will return a set of commodity descriptions along with commodity codes (as a single string for each match found), if set to TRUE it will return only the commodity codes. Default value is FALSE.


The trade classification scheme. Possible values for goods: c('HS','S1','S2','S3','S4','SS','B4','B5'); for services: c('EB02','EB10','EB10S','EB'). Default: 'HS'.


The type of returned trade data. Possible values: 'goods' for trade in goods, 'services' for trade in services. Default: 'goods'.


Logical, if set to FALSE, the function will return the matches as a named list, if set to TRUE it will return them as a character vector. Default value is FALSE.


Logical, if set to TRUE, a warning message will print to console if any of the elements of input "search_terms" returned no matches (message will indicate which elements returned no data). Default is TRUE.

logical, to be passed along to arg within grepl. Default value is TRUE.


If TRUE, downloads possibly updated reference tables from the UN. Default: FALSE.


additional args to be passed along to grepl.


A list or character vector of commodity descriptions and/or commodity codes that are matches with the elements of "search_terms".


This function uses regular expressions (regex) to find matches within the commodity DB. This means it will treat as a match any commodity description that contains the input search term. For more on using regex within R, see

See also


if (FALSE) { # interactive()