Skip to contents

Country names passed to the Comtrade API must have precise spelling/capitalization. This is a helper function for querying the country names/spelling used by Comtrade.. It takes as input a vector of country names, output is any country names that contain any of the input strings, using regex via the base function grepl. For use with the UN Comtrade API, full API docs can be found at


  type = c("reporter", "partner"), = TRUE,



Char vector of country names.


str, the country list to use for the search, valid inputs are "reporter" and "partner".

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


additional args to be passed along to grepl.


A character vector of country names that are complete or partial matches with any of the input country names.


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

See also


# Look up all reporters that contain the terms "korea" and "vietnam"
ct_country_lookup(c("korea", "vietnam"), "reporter")
#> [1] "Dem. People's Rep. of Korea" "Fmr Dem. Rep. of Vietnam"   
#> [3] "Fmr Rep. of Vietnam"         "Rep. of Korea"