### zi_census_api_key() example Source: https://pfizer-opensource.github.io/zippeR/reference/zi_census_api_key.html Example usage of zi_census_api_key() with a sample key and install = TRUE. The example is wrapped in if (FALSE) to prevent execution in non-interactive sessions. ```r if (FALSE) { # interactive() zi_census_api_key(key = "111111abc", install = TRUE) } ``` -------------------------------- ### zi_label() examples with UDS, USPS, and custom dictionary Source: https://pfizer-opensource.github.io/zippeR/reference/zi_label.html Complete example block from the documentation. It creates sample data, then shows commented-out calls for UDS and USPS crosswalks, and an active example using a custom dictionary (`mo_label`) with output. ```r # create sample data df <- data.frame( id = c(1:3), zip5 = c("63005", "63139", "63636"), zip3 = c("630", "631", "636") ) if (FALSE) { # interactive() # UDS crosswalk zi_label(df, input_var = zip5, label_source = "UDS", vintage = 2022) # USPS crosswalk zi_label(df, input_var = zip3, label_source = "USPS", type = "zip3", vintage = 202408) } # custom dictionary ## load sample ZIP3 label data to simulate custom dictionary mo_label <- zi_mo_usps ## label zi_label(df, input_var = zip3, label_source = mo_label, source_var = zip3, type = "zip3") #> # A tibble: 3 × 5 #> id zip5 zip3 label_area label_state #> #> 1 1 63005 630 ST LOUIS MO #> 2 2 63139 631 ST LOUIS MO #> 3 3 63636 636 ST LOUIS MO ``` -------------------------------- ### Interactive examples for zi_load_labels with UDS and USPS Source: https://pfizer-opensource.github.io/zippeR/reference/zi_load_labels.html Interactive examples showing how to load zip5 labels from UDS and zip3 labels from USPS. The code is wrapped in if (FALSE) to prevent execution in non-interactive sessions. The USPS example uses vintage 202408 and the UDS example uses vintage 2022. ```r if (FALSE) { # interactive() # zip5 labels via UDS zi_load_labels(source = "UDS", type = "zip5", vintage = 2022) # zip3 labels via USPS zi_load_labels(source = "USPS", type = "zip3", vintage = 202408) } ``` -------------------------------- ### Install development version of zippeR from GitHub Source: https://pfizer-opensource.github.io/zippeR/index.html Installs the development version of zippeR from GitHub using remotes::install_github(). Requires the remotes package, which can be installed first if needed. ```R # install.packages("remotes") remotes::install_github("pfizer-evgen/zippeR") ``` -------------------------------- ### Example: zi_load_labels_list(type = "zip3") Source: https://pfizer-opensource.github.io/zippeR/reference/zi_load_labels_list.html Example usage wrapped in `if (FALSE) { # interactive() }` to prevent execution during package checks. It loads the list of available label data sets for three-digit ZIP Codes. ```r if (FALSE) { # interactive() zi_load_labels_list(type = "zip3") } ``` -------------------------------- ### Install zippeR from CRAN Source: https://pfizer-opensource.github.io/zippeR/index.html Installs the stable version of zippeR from CRAN using install.packages(). ```R install.packages("zippeR") ``` -------------------------------- ### zi_crosswalk examples with UDS, HUD, and custom dictionary Source: https://pfizer-opensource.github.io/zippeR/reference/zi_crosswalk.html Example usage of `zi_crosswalk` with UDS, HUD, and a custom dictionary. The UDS and HUD calls are wrapped in `if (FALSE)` because they require interactive sessions or an API key. The custom dictionary example uses `zi_mo_hud` and `zi_prep_hud` to prepare the crosswalk, then calls `zi_crosswalk` with `zip_source = mo_xwalk`. The output shows the resulting tibble with `source_geoid` appended. ```r # create sample data df <- data.frame(id = c(1:3), zip5 = c("63005", "63139", "63636")) if (FALSE) { # interactive() # UDS crosswalk zi_crosswalk(df, input_var = zip5, zip_source = "UDS", year = 2022) } if (FALSE) { # nzchar(Sys.getenv("hud_key")) # HUD crosswalk zi_crosswalk(df, input_var = zip5, zip_source = "HUD", year = 2023, qtr = 1, target = "COUNTY", query = "MO", by = "residential", return_max = TRUE, key = Sys.getenv("hud_key")) } # custom dictionary ## load sample crosswalk data to simulate custom dictionary mo_xwalk <- zi_mo_hud # prep crosswalk # when a ZIP Code crosses county boundaries, the portion with the largest # number of residential addresses will be returned mo_xwalk <- zi_prep_hud(mo_xwalk, by = "residential", return_max = TRUE) ## crosswalk zi_crosswalk(df, input_var = zip5, zip_source = mo_xwalk, source_var = zip5, source_result = geoid) #> # A tibble: 3 × 3 #> id zip5 source_geoid #> #> 1 1 63005 29189 #> 2 2 63139 29510 #> 3 3 63636 29093 ``` -------------------------------- ### Inspect structure and first rows of zi_mo_zcta3 Source: https://pfizer-opensource.github.io/zippeR/reference/zi_mo_zcta3.html The examples show how to inspect the dataset using `utils::str()` and `utils::head()`, with the output displayed for each. ```R utils::str(zi_mo_zcta3) #> Classes ‘sf’ and 'data.frame': 31 obs. of 2 variables: #> $ ZCTA3 : chr "501" "516" "525" "526" ... #> $ geometry:sfc_MULTIPOLYGON of length 31; first list element: List of 21 #> ..$ :List of 1 #> .. ..$ : num [1:7, 1:2] -92.9 -92.9 -92.9 -92.9 -92.9 ... #> ..$ :List of 1 #> .. ..$ : num [1:38, 1:2] -93.7 -93.7 -93.6 -93.6 -93.6 ... #> ..$ :List of 1 #> .. ..$ : num [1:8, 1:2] -93.7 -93.7 -93.7 -93.7 -93.7 ... #> ..$ :List of 1 #> .. ..$ : num [1:27, 1:2] -93.2 -93.2 -93.2 -93.2 -93.2 ... #> ..$ :List of 2 #> .. ..$ : num [1:51, 1:2] -92.4 -92.4 -92.4 -92.4 -92.4 ... #> .. ..$ : num [1:9, 1:2] -92.3 -92.3 -92.3 -92.3 -92.3 ... #> ..$ :List of 1 #> .. ..$ : num [1:9, 1:2] -95 -95 -95 -95 -95 ... #> ..$ :List of 1 #> .. ..$ : num [1:284, 1:2] -93.4 -93.4 -93.4 -93.4 -93.3 ... #> ..$ :List of 1 #> .. ..$ : num [1:352, 1:2] -94.3 -94.3 -94.3 -94.3 -94.3 ... #> ..$ :List of 1 #> .. ..$ : num [1:17, 1:2] -93.7 -93.7 -93.7 -93.7 -93.6 ... #> ..$ :List of 1 #> .. ..$ : num [1:7, 1:2] -93.4 -93.4 -93.4 -93.4 -93.4 ... #> ..$ :List of 1 #> .. ..$ : num [1:95, 1:2] -93.4 -93.4 -93.4 -93.4 -93.4 ... #> ..$ :List of 1 #> .. ..$ : num [1:144, 1:2] -93.8 -93.8 -93.7 -93.7 -93.7 ... #> ..$ :List of 1 #> .. ..$ : num [1:347, 1:2] -94.7 -94.7 -94.8 -94.8 -94.9 ... #> ..$ :List of 1 #> .. ..$ : num [1:746, 1:2] -93.9 -93.9 -93.9 -93.9 -93.9 ... #> ..$ :List of 1 #> .. ..$ : num [1:206, 1:2] -94.3 -94.3 -94.3 -94.3 -94.3 ... #> ..$ :List of 1 #> .. ..$ : num [1:10, 1:2] -93.3 -93.3 -93.3 -93.3 -93.3 ... #> ..$ :List of 1 #> .. ..$ : num [1:234, 1:2] -93.5 -93.5 -93.5 -93.5 -93.5 ... #> ..$ :List of 3 #> .. ..$ : num [1:579, 1:2] -93.1 -93.1 -93.1 -93.1 -93.1 ... #> .. ..$ : num [1:5, 1:2] -92.9 -92.9 -92.9 -92.9 -92.9 ... #> .. ..$ : num [1:6, 1:2] -92.8 -92.8 -92.8 -92.8 -92.8 ... #> ..$ :List of 2 #> .. ..$ : num [1:1521, 1:2] -93.3 -93.3 -93.2 -93.2 -93.2 ... #> .. ..$ : num [1:10, 1:2] -93.2 -93.2 -93.2 -93.2 -93.2 ... #> ..$ :List of 1 #> .. ..$ : num [1:9, 1:2] -93.1 -93.1 -93.1 -93.1 -93.1 ... #> ..$ :List of 1 #> .. ..$ : num [1:363, 1:2] -93.7 -93.7 -93.6 -93.6 -93.6 ... #> ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg" #> - attr(*, "sf_column")= chr "geometry" #> - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA #> ..- attr(*, "names")= chr "ZCTA3" ``` ```R utils::head(zi_mo_zcta3) #> Simple feature collection with 6 features and 1 field #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -95.88891 ymin: 37.93668 xmax: -88.97182 ymax: 42.69899 #> Geodetic CRS: NAD83 #> ZCTA3 geometry #> 1 501 MULTIPOLYGON (((-92.9414 41... #> 2 516 MULTIPOLYGON (((-95.36826 4... #> 3 525 MULTIPOLYGON (((-91.91263 4... #> 4 526 MULTIPOLYGON (((-91.43297 4... #> 5 620 MULTIPOLYGON (((-90.61378 3... #> 6 630 MULTIPOLYGON (((-90.32484 3... ``` -------------------------------- ### zi_convert examples: adding a new column and overwriting Source: https://pfizer-opensource.github.io/zippeR/reference/zi_convert.html Two examples from the function documentation. The first creates a data frame with a zip5 column and converts it to a new zip3 column, showing the resulting tibble. The second creates a data frame with a zip column and converts it in place, overwriting the original column, also showing the output. ```r # add new column ## create sample data df <- data.frame(id = c(1:3), zip5 = c("63005", "63139", "63636")) ## convert ZIP Codes to ZIP3, creating a new column zi_convert(.data = df, input_var = zip5, output_var = zip3) #> # A tibble: 3 × 3 #> id zip5 zip3 #> #> 1 1 63005 630 #> 2 2 63139 631 #> 3 3 63636 636 # overwrite existing column ## create sample data df <- data.frame(id = c(1:3), zip = c("63005", "63139", "63636")) ## convert ZIP Codes to ZIP3, creating a new column zi_convert(.data = df, input_var = zip) #> # A tibble: 3 × 2 #> id zip #> #> 1 1 630 #> 2 2 631 #> 3 3 636 ``` -------------------------------- ### zi_get_demographics() example Source: https://pfizer-opensource.github.io/zippeR/reference/zi_get_demographics.html Example usage wrapped in if (FALSE) for interactive sessions. Downloads all ZCTAs, then limits output to a subset of ZCTAs in Missouri using the intersects method. ```r if (FALSE) { # interactive() # download all ZCTAs zi_get_demographics(year = 2012, variables = "B01003_001", survey = "acs5") # limit output to subset of ZCTAs ## download all ZCTAs in Missouri, intersects method mo20 <- zi_get_geometry(year = 2020, state = "MO", method = "intersect") ## download demographic data zi_get_demographics(year = 2012, variables = "B01003_001", survey = "acs5", zcta = mo20$GEOID) } ``` -------------------------------- ### Example: Preparing HUD crosswalk data Source: https://pfizer-opensource.github.io/zippeR/reference/zi_prep_hud.html Loads sample HUD crosswalk data for Missouri, then calls `zi_prep_hud()` with `by = "residential"` and `return_max = TRUE`. The output shows a tibble with columns zip5, geoid, state, state_fips, and ratio. The comment notes that the sample data can be replicated with `zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "COUNTY", query = "MO")`. ```r # load sample crosswalk data mo_xwalk <- zi_mo_hud # the above data can be replicated with the following code: # zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, # target = "COUNTY", query = "MO") # prep crosswalk # when a ZIP Code crosses county boundaries, the portion with the largest # number of residential addresses will be returned zi_prep_hud(mo_xwalk, by = "residential", return_max = TRUE) #> # A tibble: 1,127 × 5 #> zip5 geoid state state_fips ratio #> #> 1 72643 05009 MO 29 1 #> 2 63501 29001 MO 29 1 #> 3 63533 29001 MO 29 0.978 #> 4 63540 29001 MO 29 1 #> 5 63546 29001 MO 29 0.630 #> 6 63559 29001 MO 29 0.950 #> 7 64421 29003 MO 29 1 #> 8 64427 29003 MO 29 0.889 #> 9 64436 29003 MO 29 0.980 #> 10 64449 29003 MO 29 1 #> # ℹ 1,117 more rows ``` -------------------------------- ### zi_get_geometry examples for ZCTA downloads Source: https://pfizer-opensource.github.io/zippeR/reference/zi_get_geometry.html These examples show various calls to zi_get_geometry for downloading ZCTA geometry data. They cover downloading all ZCTAs for 2020 with and without territories, selecting states with the intersect method, selecting a single county, and downloading 2018 ZCTAs with territories. The code is wrapped in an if (FALSE) block, indicating it is for interactive use. ```R if (FALSE) { # interactive() # five-digit ZCTAs ## download all ZCTAs for 2020 including territories zi_get_geometry(year = 2020, territory = c("AS", "GU", "MP", "PR", "VI"), shift_geo = TRUE) ## download all ZCTAs for 2020 excluding territories zi_get_geometry(year = 2020, shift_geo = TRUE) ## download all ZCTAs in a selection of states, intersects method zi_get_geometry(year = 2020, state = c("IA", "IL", "MO"), method = "intersect") ## download all ZCTAs in a single county - St. Louis City, MO zi_get_geometry(year = 2020, state = "MO", county = "29510", method = "intersect") # three-digit ZCTAs ## download all ZCTAs for 2018 including territories zi_get_geometry(year = 2018, territory = c("AS", "GU", "MP", "PR", "VI"), shift_geo = TRUE) } ``` -------------------------------- ### zi_aggregate examples Source: https://pfizer-opensource.github.io/zippeR/reference/zi_aggregate.html Example code for aggregating demographic data to three-digit ZCTAs. The example loads sample data, aggregates a single variable, and then aggregates multiple variables with wide output. The code is wrapped in an interactive() check. ```r if (FALSE) { # interactive() # load sample demographic data mo22_demos <- zi_mo_pop # the above data can be replicated with the following code: # zi_get_demographics(year = 2022, variables = c("B01003_001", "B19013_001"), # survey = "acs5") # load sample geometric data mo22_zcta3 <- zi_mo_zcta3 # the above data can be replicated with the following code: # zi_get_geometry(year = 2022, style = "zcta3", state = "MO", # method = "intersect") # aggregate a single variable zi_aggregate(mo22_demos, year = 2020, extensive = "B01003_001", survey = "acs5", zcta = mo22_zcta3$ZCTA3) # aggregate multiple variables, outputting wide data zi_aggregate(mo22_demos, year = 2020, extensive = "B01003_001", intensive = "B19013_001", survey = "acs5", zcta = mo22_zcta3$ZCTA3, output = "wide") } ``` -------------------------------- ### Example Tibble Output Source: https://pfizer-opensource.github.io/zippeR/articles/converting-zips.html A sample tibble showing the structure of ZIP code data with id, ZIP, and source_zcta columns. ```text # A tibble: 3 × 3 id ZIP source_zcta 1 1 63139 63139 2 2 63108 63108 3 3 00501 11742 ``` -------------------------------- ### Example: zi_list_zctas for Missouri with intersect and centroid methods Source: https://pfizer-opensource.github.io/zippeR/reference/zi_list_zctas.html Example usage of zi_list_zctas for Missouri with both methods. The intersect method returns ZCTAs that border the state, while the centroid method returns only ZCTAs whose centroids lie within the state. The code is wrapped in if (FALSE) for interactive use only. ```r if (FALSE) { # interactive() # Missouri ZCTAs, intersect method ## return list mo_zctas <- zi_list_zctas(year = 2021, state = "MO", method = "intersect") ## preview ZCTAs mo_zctas[1:10] # Missouri ZCTAs, centroid method ## return list mo_zctas <- zi_list_zctas(year = 2021, state = "MO", method = "centroid") ## preview ZCTAs mo_zctas[1:10] } ``` -------------------------------- ### zi_validate() examples with successful and failed validation Source: https://pfizer-opensource.github.io/zippeR/reference/zi_validate.html Examples showing successful validation of five-digit ZIPs, validation of a data frame column, and failed validation with verbose output. The verbose output shows a tibble with validation criteria and results. ```r # sample five-digit ZIPs zips <- c("63088", "63108", "63139") # successful validation zi_validate(zips) #> [1] TRUE # sample five-digit ZIPs in data frame zips <- data.frame(id = c(1:3), ZIP = c("63139", "63108", "00501"), stringsAsFactors = FALSE) # successful validation zi_validate(zips$ZIP) #> [1] TRUE # sample five-digit ZIPs with character zips <- c("63088", "63108", "zip") # failed validation zi_validate(zips) #> [1] FALSE zi_validate(zips, verbose = TRUE) #> # A tibble: 4 × 2 #> condition result #> #> 1 Input is a character vector? TRUE #> 2 All input values have 5 characters? FALSE #> 3 No input values are over 5 characters long? TRUE #> 4 All input values are numeric? FALSE ``` -------------------------------- ### zi_census_api_key() usage Source: https://pfizer-opensource.github.io/zippeR/reference/zi_census_api_key.html Shows the function signature with arguments key, overwrite, and install. The key is a character scalar obtained from the Census API signup page. overwrite and install are logical scalars with defaults FALSE. ```r zi_census_api_key(key, overwrite = FALSE, install = FALSE) ``` -------------------------------- ### Load UDS Mapper crosswalks Source: https://pfizer-opensource.github.io/zippeR/reference/zi_load_crosswalk.html Example of loading a UDS Mapper crosswalk file for a specific year. ```R if (FALSE) { # interactive() # former UDS mapper crosswalks zi_load_crosswalk(zip_source = "UDS", year = 2020) } ``` -------------------------------- ### Load HUD crosswalks Source: https://pfizer-opensource.github.io/zippeR/reference/zi_load_crosswalk.html Examples of loading HUD crosswalk files for various targets including CBSA, County, and Tract, requiring a HUD API key. ```R if (FALSE) { # nzchar(Sys.getenv("hud_key")) # HUD crosswalks ## ZIP Code to CBSA crosswalk for all ZIP Codes zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "CBSA", query = "all", key = Sys.getenv("hud_key")) ## ZIP Code to County crosswalk for all ZIP Codes in Missouri zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "COUNTY", query = "MO", key = Sys.getenv("hud_key")) ## ZIP Code to Tract crosswalk for ZIP Code 63139 in St. Louis City zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "TRACT", query = 63139, key = Sys.getenv("hud_key")) } ``` -------------------------------- ### Get Missouri ZCTA geometry with centroid method and includes Source: https://pfizer-opensource.github.io/zippeR/articles/demographic-geometric-zcta-data.html Downloads ZCTA geometry for Missouri using the centroid method and adds specific ZCTAs whose centroids fall outside the state. The `includes` argument is required because those ZCTAs lie in Iowa. ```r geo12 <- zi_get_geometry(year = 2012, state = "MO", method = "centroid", includes = c("51640", "52542", "52573", "52626")) ``` -------------------------------- ### zi_prep_hud(.data, by, return_max = TRUE) Source: https://pfizer-opensource.github.io/zippeR/reference/zi_prep_hud.html Prepares HUD crosswalk data for use in the zi_crosswalk function. It takes the output from zi_load_crosswalk() with HUD data and returns a tibble that has been further prepared for use as a crosswalk. ```APIDOC ## zi_prep_hud(.data, by, return_max = TRUE) ### Description Prepares HUD crosswalk data for use in the zi_crosswalk() function. The output from zi_load_crosswalk() for HUD data requires additional processing to be used in the zi_crosswalk() function. ### Usage zi_prep_hud(.data, by, return_max = TRUE) ### Arguments - **.data** - The output from zi_load_crosswalk() with HUD data. - **by** - Character scalar; the column name to use for identifying the best match for a given ZIP Code. This could be either "residential", "commercial", or "total". - **return_max** - Logical scalar; if TRUE (default), only the county with the highest proportion of the ZIP Code type will be returned. If the ZIP Code straddles two states, two records will be returned. If FALSE, all records for the ZIP Code will be returned. Where a tie exists (i.e. two counties each contain half of all addresses), the county with the lowest GEOID value will be returned. ### Value A tibble that has been further prepared for use as a crosswalk. ### Examples ```r # load sample crosswalk data mo_xwalk <- zi_mo_hud # the above data can be replicated with the following code: # zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, # target = "COUNTY", query = "MO") # prep crosswalk # when a ZIP Code crosses county boundaries, the portion with the largest # number of residential addresses will be returned zi_prep_hud(mo_xwalk, by = "residential", return_max = TRUE) #> # A tibble: 1,127 × 5 #> zip5 geoid state state_fips ratio #> #> 1 72643 05009 MO 29 1 #> 2 63501 29001 MO 29 1 #> 3 63533 29001 MO 29 0.978 #> 4 63540 29001 MO 29 1 #> 5 63546 29001 MO 29 0.630 #> 6 63559 29001 MO 29 0.950 #> 7 64421 29003 MO 29 1 #> 8 64427 29003 MO 29 0.889 #> 9 64436 29003 MO 29 0.980 #> 10 64449 29003 MO 29 1 #> # ℹ 1,117 more rows ``` ``` -------------------------------- ### Usage: zi_prep_hud() Source: https://pfizer-opensource.github.io/zippeR/reference/zi_prep_hud.html Function signature for `zi_prep_hud()`. Arguments: `.data` (output from `zi_load_crosswalk()` with HUD data), `by` (column name for best match: "residential", "commercial", or "total"), and `return_max` (logical, default TRUE). ```r zi_prep_hud(.data, by, return_max = TRUE) ``` -------------------------------- ### Inspecting the zi_mo_hud dataset Source: https://pfizer-opensource.github.io/zippeR/reference/zi_mo_hud.html Use utils::str and utils::head to examine the structure and first few rows of the dataset. ```R utils::str(zi_mo_hud) #> tibble [1,749 × 8] (S3: tbl_df/tbl/data.frame) #> $ ZIP : chr [1:1749] "63103" "63447" "63362" "63134" ... #> $ GEOID : chr [1:1749] "29510" "29111" "29113" "29189" ... #> $ RES_RATIO: num [1:1749] 1 1 1 1 1 1 1 1 1 1 ... #> $ BUS_RATIO: num [1:1749] 1 1 1 1 1 1 1 1 1 1 ... #> $ OTH_RATIO: num [1:1749] 1 1 1 1 1 1 1 1 1 1 ... #> $ TOT_RATIO: num [1:1749] 1 1 1 1 1 1 1 1 1 1 ... #> $ CITY : chr [1:1749] "SAINT LOUIS" "LA BELLE" "MOSCOW MILLS" "SAINT LOUIS" ... #> $ STATE : chr [1:1749] "MO" "MO" "MO" "MO" ... utils::head(zi_mo_hud) #> # A tibble: 6 × 8 #> ZIP GEOID RES_RATIO BUS_RATIO OTH_RATIO TOT_RATIO CITY STATE #> #> 1 63103 29510 1 1 1 1 SAINT LOUIS MO #> 2 63447 29111 1 1 1 1 LA BELLE MO #> 3 63362 29113 1 1 1 1 MOSCOW MILLS MO #> 4 63134 29189 1 1 1 1 SAINT LOUIS MO #> 5 65439 29093 1 1 1 1 BIXBY MO #> 6 65686 29209 1 1 1 1 KIMBERLING CITY MO ``` -------------------------------- ### Get nation-wide ZCTA geometry with shift_geo Source: https://pfizer-opensource.github.io/zippeR/articles/demographic-geometric-zcta-data.html Downloads nation-wide ZCTA geometry for 2010 and shifts Alaska, Hawaii, and Puerto Rico to the lower left-hand corner of the map using the `shift_geo` argument. ```r geo10 <- zi_get_geometry(year = 2010, shift_geo = TRUE) ``` -------------------------------- ### Load HUD Crosswalk Data Source: https://pfizer-opensource.github.io/zippeR/articles/converting-zips.html Demonstrates downloading HUD crosswalk data using zi_load_crosswalk() with specific year, quarter, target, and query parameters. ```r > zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "COUNTY", + query = c("63138", "63139")) ``` -------------------------------- ### Get Gini index for ZCTAs from geometry output Source: https://pfizer-opensource.github.io/zippeR/articles/demographic-geometric-zcta-data.html Downloads Gini index data (table B19083) from the 2012 ACS5 survey, limiting results to the ZCTAs in the `geo12` object from a prior `zi_get_geometry()` call. ```r gini12 <- zi_get_demographics(year = 2012, table = "B19083", survey = "acs5", zcta = geo12$GEOID) ``` -------------------------------- ### Get total population from 2010 Decennial Census Source: https://pfizer-opensource.github.io/zippeR/articles/demographic-geometric-zcta-data.html Downloads total population for all ZCTAs from the 2010 Decennial Census using the `zi_get_demographics()` wrapper. Note that ZCTA data for the 2020 Decennial Census have not been released. ```r pop10 <- zi_get_demographics(year = 2010, variables = "P001001", survey = "sf1") ``` -------------------------------- ### Download demographic data with zi_get_demographics() Source: https://pfizer-opensource.github.io/zippeR/articles/three-digit-zips.html Downloads 2020 ACS5 population estimates for all five-digit ZCTAs. Do not limit the download with the `zcta` argument; all ZCTAs must be included to avoid incorrect values for ZCTAs split across jurisdictions. ```r mo_pop20 <- zi_get_demographics(year = 2020, variables = "B01003_001", survey = "acs5") ``` -------------------------------- ### Repair ZIP codes with zi_repair() Source: https://pfizer-opensource.github.io/zippeR/reference/zi_repair.html Example showing how to repair a vector of ZIP codes that contains a non-numeric value. The zi_repair() function converts the invalid entry to NA and emits a warning "NAs introduced by coercion." After repair, zi_validate() returns TRUE. ```r # sample five-digit ZIPs with character zips <- c("63088", "63108", "zip") # failed validation zi_validate(zips) #> [1] FALSE # repair zips <- zi_repair(zips) #> Warning: NAs introduced by coercion. # successful validation zi_validate(zips) #> [1] TRUE ``` -------------------------------- ### Replicating the zi_mo_hud dataset Source: https://pfizer-opensource.github.io/zippeR/reference/zi_mo_hud.html Use the zi_load_crosswalk function to replicate the data. This requires a HUD API key stored as 'hud_key' in your .Rprofile. ```R zi_load_crosswalk(zip_source = "HUD", year = 2023, qtr = 1, target = "COUNTY", query = "MO") ``` -------------------------------- ### Pipe download and aggregate with multiple variables Source: https://pfizer-opensource.github.io/zippeR/articles/three-digit-zips.html Pipes the download and aggregation workflow, specifying both extensive and intensive variables. The `variables`, `table`, `extensive`, and `intensive` arguments are not validated before being passed to the Census Bureau, so incorrectly formatted names may generate cryptic errors. ```r zi_get_demographics(year = 2020, variables = c("B01003_001", "B19083_001"), survey = "acs5") %>% zi_aggregate(year = 2020, extensive = "B01003_001", intensive = "B19083_001", survey = "acs5") -> demo20 ``` -------------------------------- ### zi_label() function signature Source: https://pfizer-opensource.github.io/zippeR/reference/zi_label.html Shows the usage signature for `zi_label()`, including all arguments and their defaults. ```r zi_label( .data, input_var, label_source = "UDS", source_var, type = "zip5", include_scf = FALSE, vintage = 2022 ) ```