This function allows for the creation of dictionary objects that are either optional or required elements of other postmastr functions. 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.

Street dictionaries cannot be created using pm_dictionary. Users who wish to standardize street names in their data should create a dictionary appendix with pm_append and use that as the primary dictionary for functions that accept street dictionaries. The same is true for house suffix dictionaries.

pm_dictionary(type, append, filter, case = c("title", "lower", "upper"), locale = "us")

Arguments

type

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

append

An optional dictionary appendix object created with pm_append

filter

An optional character scalar or vector with output elements that should be retained. Filter inputs are based on the expected output: states should be specified with their two-letter abbrevation (i.e. "MO"), cities should be specified in title case (i.e. "St. Louis"), directionals should use one- or two-letter abbreivations (i.e. "N"), and street suffixes should use the suf.output for the desired suffix (i.e. "Ave" or "Rd").

case

An optional character scalar or vector containing one or more of three valid options - "title" (e.g. "Missouri"), "lower" (e.g. "missouri), or "upper" (e.g. "MISSOURI"). These are used to create a more robust dictionary of input terms.

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 American addresses, these outputs follow United States Postal Service guidelines.

Details

The city dictionary functionality is powered by the get_acs function from the tidycensus package. This requires a Census Bureau API key, which can be obtained at http://api.census.gov/data/key_signup.html. Once you have a key, the census_api_key function from tidycensus should be used to set-up the key before proceeding with the creation of any dictionary objects for cities.

See also

Examples

# build state dictionary, title case only pm_dictionary(type = "state", filter = "MO", case = "title", locale = "us")
#> # A tibble: 2 x 2 #> state.output state.input #> <chr> <chr> #> 1 MO MO #> 2 MO Missouri
# build state dictionary, title and upper case pm_dictionary(type = "state", filter = "MO", case = c("title", "upper"), locale = "us")
#> # A tibble: 3 x 2 #> state.output state.input #> <chr> <chr> #> 1 MO MO #> 2 MO Missouri #> 3 MO MISSOURI
# build New England state dictionary, all cases pm_dictionary(type = "state", filter = c("CT", "MA", "ME", "NH", "RI", "VT"), case = c("title", "upper", "lower"), locale = "us")
#> # A tibble: 30 x 2 #> state.output state.input #> <chr> <chr> #> 1 CT CT #> 2 CT Connecticut #> 3 CT ct #> 4 CT connecticut #> 5 CT CONNECTICUT #> 6 MA MA #> 7 MA Massachusetts #> 8 MA ma #> 9 MA massachusetts #> 10 MA MASSACHUSETTS #> # … with 20 more rows
# add custom abbreviation for Massachusetts ## 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
# build Missouri city dictionary
# NOT RUN { # tidycensus::census_api_key("YOUR API KEY GOES HERE") pm_dictionary(type = "city", filter = "MO", case = "upper", locale = "us") # }
# build directional dictionary pm_dictionary(type = "directional", filter = c("N", "S", "E", "W"), locale = "us")
#> # A tibble: 20 x 2 #> dir.output dir.input #> <chr> <chr> #> 1 E E #> 2 E East #> 3 E e #> 4 E east #> 5 E EAST #> 6 N N #> 7 N North #> 8 N n #> 9 N north #> 10 N NORTH #> 11 S S #> 12 S South #> 13 S s #> 14 S south #> 15 S SOUTH #> 16 W W #> 17 W West #> 18 W w #> 19 W west #> 20 W WEST
# build suffix dictionary pm_dictionary(type = "suffix", filter = c("Ave", "Rd"), locale = "us")
#> # A tibble: 27 x 3 #> suf.type suf.input suf.output #> <chr> <chr> <chr> #> 1 Avenue Av Ave #> 2 Avenue Ave Ave #> 3 Avenue Aven Ave #> 4 Avenue Avenu Ave #> 5 Avenue Avenue Ave #> 6 Avenue Avn Ave #> 7 Avenue Avnue Ave #> 8 Avenue av Ave #> 9 Avenue ave Ave #> 10 Avenue aven Ave #> # … with 17 more rows