The lookuper()
function returns a function equivalent to the lookup()
function, except that instead of taking a lookup table as an argument, the
lookup table is embedded in the function itself.
This can be very useful, in particular when using the lookup function as an
argument to other functions that expect a function which maps
character
->character
but do not offer a good way to pass additional
arguments to that function.
Arguments
- lookup_table
A the lookup table that should be used as the underlying lookup table for the returned function.
Value
A function that takes character
vectors as its argument x
, and
returns either the corresponding values from the underlying lookup table,
or the original values from x for those elements that are not found in the
lookup table.
Examples
lookup_fruits <- lookuper(list(a="Apple", b="Banana", c="Cherry"))
lookup_fruits(letters[1:5])
#> [1] "Apple" "Banana" "Cherry" "d" "e"