use_dictionary: Substitute Values that are in a Dictionary with their Keys

Description Usage Arguments Value Examples

View source: R/use_dictionary.R

Description

Substitute Values that are in a Dictionary with their Keys

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# 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")
kwb.pathdict:::use_dictionary(x, dict_part, method = "part")

KWB-R/kwb.pathdict documentation built on Jan. 13, 2020, 2:24 a.m.