findCountry {Ecfun} | R Documentation |
Find a 3-letter country code in rworldmap::countrySynonyms
Description
Search for a specific country name on 8 different columns
of alternative names in
countrySynonyms
. Return either a
3-character code or a longer character string saying, e.g.,
"No match found for country" followed by the name of the
country not found.
NOTE: This code will be offered to the
maintainer of the rworldmap
package. If they
like it, it may not stay in Ecfun
.
Usage
findCountry(string, referenceTable =
rworldmap::countrySynonyms)
Arguments
string |
Character vector of strings to look for matches in
|
referenceTable |
|
Details
1. Force string
and
rworldmap::countrySynonyms[, 3:10]
toupper
.
2. grep
for string[i]
in
rworldmap::countrySynonyms[, 3:10]
and
return the element of
rworldmap::countrySynonyms$ISO3
that corresponds to anything found if it's
3 characters and an appropriate message
otherwise.
Value
A character of 3-character codes or longer
not-found messages with names = string
.
Author(s)
Spencer Graves
See Also
grep
, toupper
,
countrySynonyms
Examples
tstCodes <- findCountry(
c('Iran', 'Christmas Island', 'eSwatini'))
answer <- c(Iran='IRN',
'Christmas Island'="referenceTable[53, 2] = ''",
'eSwatini'="No match found for country eSwatini")
all.equal(tstCodes, answer)