pm_dictionary: Create Dictionary Objects

Description Usage Arguments Details 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. 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.

Usage

1
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.

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.

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.

See Also

pm_append, dic_us_dir, dic_us_states, dic_us_suffix

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
25
26
27
28
29
30
# build state dictionary, title case only
pm_dictionary(type = "state", filter = "MO", case = "title", locale = "us")

# build state dictionary, title and upper case
pm_dictionary(type = "state", filter = "MO", case = c("title", "upper"), locale = "us")

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

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

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

## End(Not run)

# build directional dictionary
pm_dictionary(type = "directional", filter = c("N", "S", "E", "W"), locale = "us")

# build suffix dictionary
pm_dictionary(type = "suffix", filter = c("Ave", "Rd"), locale = "us")

slu-openGIS/postmastr documentation built on Dec. 9, 2020, 3:32 a.m.