Skip to contents

This function allows for the identification of countries in a text.

Usage

code_states(text, code = TRUE, max_count = 1)

Arguments

text

A vector of text to search for country names within.

code

Logical whether the function should return the three-letter abbreviation (an extended version of ISO-3166 alpha-3), or the name of the state. For the complete list of entities and their search terms, run the function without an argument (i.e. code_states()). Updates and suggestions welcome.

max_count

Integer how many countries to search for in each element of the vector. Where more than one country is matched, the countries are returned as a set, i.e. in the format "{AUS,NZL}". By default max_count = 1, which will just return the first match.

Examples

code_states(c("I went to England",
  "I come from Venezuela",
  "Did you know there was a Lunda Empire?",
  "I like both Australia and New Zealand"))
#> [1] "GBR" "VEN" "LUN" "AUS"
code_states(c("I went to England",
  "I come from Venezuela",
  "Did you know there was a Lunda Empire?",
  "I like both Australia and New Zealand"), max_count = 2)
#> [1] "GBR"       "VEN"       "LUN"       "{AUS,NZL}"