-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.R
118 lines (99 loc) · 2.9 KB
/
testing.R
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
address <- tibble(singlelineaddress = c(""))
census_full <-
address %>%
geocode(
address = singlelineaddress,
method = 'census',
full_results = TRUE,
api_options = list(census_return_type = 'geographies')
)
nomatch <- if_else(is.na(census_full$lat),
"No match. Please check your address and try again.",
"ok")
nomatch <- nomatch[1]
if(nomatch == "ok") {
census_full <- census_full %>%
unnest('geographies.2020 Census Blocks') %>%
mutate(GEOID = substr(GEOID, 1, 11))
}
if (nomatch == "ok" & nrow(census_full) > 1) {
insufficient_address <- census_full %>%
mutate(
DifferentStreetName = if_else(length(
unique(addressComponents.streetName)
) > 1,
"Street Name", NULL),
DifferentStreetSuffix = if_else(
length(unique(addressComponents.suffixType)) > 1,
"Street Suffix (for example: Ave, Street, Way)",
NULL
),
DifferentSuffixDirection = if_else(
length(unique(
addressComponents.suffixDirection
)) > 1,
"Street Direction (for example: N, W)",
NULL
),
DifferentSuffixQualifier = if_else(length(
unique(addressComponents.suffixQualifier)
) > 1,
"Suffix Qualifier", NULL),
DifferentCity = if_else(length(unique(
addressComponents.city
)) > 1,
"City", NULL),
DifferentState = if_else(length(
unique(addressComponents.state)
) > 1,
"State", NULL),
DifferentZIP = if_else(length(unique(
addressComponents.zip
)) > 1,
"ZIP Code", NULL),
WhatToCheck = paste(
"Please check your",
na.omit(DifferentStreetName),
na.omit(DifferentStreetSuffix),
na.omit(DifferentSuffixQualifier),
na.omit(DifferentSuffixDirection),
na.omit(DifferentCity),
na.omit(DifferentState),
na.omit(DifferentZIP)
)
) %>%
pull(WhatToCheck) %>%
unique() %>%
str_squish()
print(insufficient_address)} else{
print(nomatch)
}
nrow(
census_full <-
address %>%
geocode(
address = singlelineaddress
)
) == 1 &
!is.na(census_full$lat[1])
tbl <- tribble(~col, ~adress.stname, ~adress.suffix, ~adress.city, ~adress.state, ~adress.zip,
1, "a", "b", "foo", "oh", "3333",
1, "a", "c", "boo", "oh", "3333",
1, "a", "b", "loo", "oh", "3333"
)
tbl
foo_uniq <- function(x) length(unique(x)) > 1
ad_test <-
tbl %>%
select(starts_with("adress")) %>%
map_lgl(foo_uniq)
wrong_item <- names(ad_test)[ad_test == TRUE]
case_when(
wrong_item == "adress.stname" ~ "state",
wrong_item == "adress.suffix" ~ "suffix",
wrong_item == "adress.city" ~ "city",
wrong_item == "adress.zip" ~ "zip") -> wrong_msg
paste("Wrong", paste(wrong_msg, collapse = " & "))
index %>%
filter(GEOID == "390490093942002") %>%
pull(equity_index_quantile)