findCountry | R Documentation |
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
.
findCountry(string, referenceTable =
rworldmap::countrySynonyms)
string |
Character vector of strings to look for matches in
|
referenceTable |
|
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.
A character of 3-character codes or longer
not-found messages with names = string
.
Spencer Graves
grep
, toupper
,
countrySynonyms
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.