This function allows for the creation of dictionary objects that are either optional or required elements of other postmastr functions. These objects are appendicies that can serve either as stand-alone dictionaries or used in a pm_dictionary call as the input for the append parameter.

Once created, dictionary objects should not be modified as the formatting of dictionary elements provides other postmastr functions with predictable inputs. The "state", "directional", and "suffix" dictionaries are based on tables that are also exported so that they can be previewed and tested.

pm_append(type, input, output, locale = "us")

Arguments

type

A string indicating the grammatical address element the dictionary should represent. Current options are "state", "city", "street", "house suffix", "directional", and "suffix".

input

A character scalar or vector containing possible terms existing in the data. This should be the same length as output.

output

A character scalar or vector containing desired output for each input. This should be the same length as input. You may use NA values in the output vector for inputs that already are in the preferred, standardized form. This argument is optional when type is equal to "city".

locale

A string indicating the country these data represent; the only current option is "us" but this is included to facilitate future expansion.

Value

A postmastr dictionary object, which will always include an input column of possible terms for the given grammatical address element. All dictionary objects except for city dictionaries will also contain an output column with the preferred output for each input. For city dictionaries, the output argument is optional.

For American addresses, these outputs should follow United States Postal Service guidelines. These dictionary objects can be used as stand-alone dictionaries or fed into a pm_dictionary call as the input for the append parameter.

See also

pm_dictionary

Examples

# create stand-alone state dictionary mo <- pm_append(type = "state", input = c("Missouri", "MO", "MISSOURI"), output = c("MO", "MO", "MO"), locale = "us") # add custom abbreviation for Massachusetts to state dictionary ## create dictionary appendix ma <- pm_append(type = "state", input = "Mass", output = "MA", locale = "us") ## add dictionary appendix to dictionary pm_dictionary(type = "state", filter = c("CT", "MA", "ME", "NH", "RI", "VT"), append = ma, case = "title", locale = "us")
#> # A tibble: 13 x 2 #> state.output state.input #> <chr> <chr> #> 1 CT CT #> 2 CT Connecticut #> 3 MA MA #> 4 MA Massachusetts #> 5 MA Mass #> 6 ME ME #> 7 ME Maine #> 8 NH NH #> 9 NH New Hampshire #> 10 RI RI #> 11 RI Rhode Island #> 12 VT VT #> 13 VT Vermont
# create stand-alone city dictionary, with spelling correction for some cities cities <- pm_append(type = "city", input = c("Brentwood", "Clayton", "CLAYTON", "Maplewood", "St. Louis", "SAINT LOUIS", "Webster Groves"), output = c(NA, NA, "Clayton", NA, NA, "St. Louis", NA), locale = "us") # create stand-alone street dictionary cities <- pm_append(type = "street", input = c("MLK", "M.L.K."), output = c("Dr. Martin Luther King, Jr.", "Dr. Martin Luther King, Jr."), locale = "us")