ct_commodity_lookup: UN Comtrade commodities database query

Description Usage Arguments Details Value See Also Examples

Description

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

Usage

1
2
ct_commodity_lookup(search_terms, return_code = FALSE,
  return_char = FALSE, verbose = TRUE, ignore.case = TRUE, ...)

Arguments

search_terms

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

return_code

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.

return_char

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.

verbose

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.

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.

Details

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

Value

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

See Also

grepl

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Look up commodity descriptions related to "halibut"
ct_commodity_lookup("halibut",
                    return_code = FALSE,
                    return_char = FALSE,
                    verbose = TRUE)

# Look up commodity codes related to "shrimp".
ct_commodity_lookup("shrimp",
                    return_code = TRUE,
                    return_char = FALSE,
                    verbose = TRUE)

ropensci/comtradr documentation built on June 12, 2019, 7:35 a.m.