Substitute Values that are in a Dictionary with their Keys

use_dictionary(x, dict, method = "full")

Arguments

x

vector of character

dict

list of key = value pairs. Values of this list that are found in x are replaced by the placeholder "<key>" in x.

method

method to be applied, must be one of "full" or "part". If "full", the full values must match, otherwise the values in dict are interpreted as patterns that are matched against the values in x and the matching parts are replaced with the corresponding "<key>" placeholder

Value

x in which values or parts of the values are replaced with their short forms as they are defined in the dictionary dict

Examples

# Define a vector of long values x <- c("What a nice day", "Have a nice day", "Good morning") # Define short forms for full or partial values dict_full <- list(wand = "What a nice day", gm = "Good morning") dict_part <- list(w = "What", nd = "nice day", g = "Good") # Replace long form values with their short forms kwb.pathdict:::use_dictionary(x, dict_full, method = "full")
#> [1] "<wand>" "Have a nice day" "<gm>"
kwb.pathdict:::use_dictionary(x, dict_part, method = "part")
#> [1] "<w> a <nd>" "Have a <nd>" "<g> morning"