Learn R Programming

comtradr (version 0.2.1)

ct_country_lookup: UN Comtrade country database query

Description

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 https://comtrade.un.org/data/doc/api/

Usage

ct_country_lookup(search_terms, type = c("reporter", "partner"),
  ignore.case = TRUE, ...)

Arguments

search_terms

Char vector of country names.

type

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

ignore.case

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

...

additional args to be passed along to grepl.

Value

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

Details

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 this great tutorial by Gloria Li and Jenny Bryan http://stat545.com/block022_regular-expression.html

See Also

grepl

Examples

Run this code
# NOT RUN {
# Look up all reporters that contain the terms "korea" and "vietnam"
ct_country_lookup(c("korea", "vietnam"), "reporter")
# }

Run the code above in your browser using DataLab