bt_guess_country: Country guesser: guesses country name contained in a string.

View source: R/bt_guess_country.R

bt_guess_countryR Documentation

Country guesser: guesses country name contained in a string.

Description

Not perfect - biased towards more common countries, e.g. may return 'United Kingdom' when string contains 'British Columbia' etc. Set param top.match.only = F to return all guesses The results are in alphabetical order, not the order they appear in the string.

Usage

bt_guess_country(tgt.string, placeholder.result = NA, top.match.only = T)

Arguments

tgt.string

vector of string containing country name(s)

placeholder.result

what to return instead of NA when guess fails

top.match.only

whether you want the first match, or a vector of matches

Details

This function should work on strings or char vectors.

Value

vector of the GTA names of all matches in alphabetical order.

References

www.globaltradealert.org

Examples

tgt.string.vect = c("In Britain, postman delivers fancy dress joy to isolating residents", "UK man turns out to be an idiot", "Something afoot in Japan")
for(tgt.string in tgt.string.vect){
print(bt_guess_country(tgt.string))
}

Usage example:

for (i in 1:nrow(update.table)){
guessed.country = bt_guess_country(update.table$art.description.en[i])
if(length(guessed.country)){
  update.table$art.country[i] = guessed.country
} else {
  update.table$art.country[i] = "Unknown"
}
}


global-trade-alert/gtabastiat documentation built on June 4, 2023, 6:40 a.m.