Learn R Programming

comtradr (version 0.0.2)

country_lookup: UN Comtrade reporter/partner lookup table query

Description

Country names passed to the Comtrade API must have precise spelling/capitalization. This is a helper function for querying the country code lookup table that's created by function ct_countries_table. 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 (search is case insensitive). For use with the UN Comtrade API, full API docs can be found at https://comtrade.un.org/data/doc/api/

Usage

country_lookup(loc, type = c("reporter", "partner"), lookuptable)

Arguments

loc

Char vector of country names.

type

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

lookuptable

Dataframe of country names and codes (intended input is the dataframe created by function ct_countries_table).

Value

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

Examples

Run this code
# NOT RUN {
# Look up all reporters that contain the terms "korea" and "vietnam"
countrydf <- ct_countries_table()
country_lookup(c("korea", "vietnam"), "reporter", countrydf)
[1] "Dem. People's Rep. of Korea"   "Fmr Dem. Rep. of Vietnam"
[3] "Fmr Rep. of Vietnam"           "Rep. of Korea"
# }

Run the code above in your browser using DataLab