pm_append: Create Dictionary Object Appendicies

Description Usage Arguments Value See Also Examples

View source: R/dictionary.R

Description

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.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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")

# 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")

chris-prener/postmastr documentation built on Dec. 13, 2020, 3:39 a.m.