grepInTable | R Documentation |
Search for a specific country name on different columns
of alternative names in all but the first column of
referenceTable
and return the contents of the
first column if found or "No match found for country",
followed by the value of string
for that case.
By default, referenceTable
=
countrySynonyms
[, -1].
NOTE: This code will be offered to the maintainer of the
rworldmap
package. If they like it, it may not stay
in Ecfun
.
grepInTable(pattern, referenceTable =
rworldmap::countrySynonyms[, -1],
ignore.case=TRUE, collapse=', ', ...)
pattern |
Character vector of matches of pattern[i] in
different columns of
|
referenceTable |
if( |
ignore.case |
If |
collapse |
Ignored if only one match is found. Otherwise,
return
|
... |
optional arguments to pass to |
1. if(ignore.case
) Force pattern
and
all columns of
referenceTable
toupper
.
2. grep
for string[i]
in
referenceTable[-1
and return the
corresponding element of
referenceTable[1]
if found and an
appropriate message otherwise.
A character vector of the contents of
referenceTable[1]
for all matches
or not-found messages that include
string[i]
when string[i]
is not found.
Spencer Graves
grep
, toupper
,
countrySynonyms
tstCodes <- grepInTable(
c('Iran', 'Christmas Island', 'eSwatini'))
answer <- c(Iran='IRN', 'Christmas Island' =
paste("Found row 53 of referenceTable with column 1 = ''"),
'eSwatini'="No match found for eSwatini")
all.equal(tstCodes, answer)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.