-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey.R
58 lines (48 loc) · 1.36 KB
/
key.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
options(box.path = box::file())
box::use(
polars[pl],
tibble[tribble],
purrr[pmap_vec],
cli[cli_alert_success],
proc/officer,
proc/uid,
proc/validate
)
#' Helpers
join_and_write <- function(db, on) {
uid$join(db, on)$collect()$write_parquet(db)
cli_alert_success("Joined key to {.file {db}}")
}
join_asof_and_write <- function(db, by) {
uid$join_asof(db, by = by)$collect()$write_parquet(db)
cli_alert_success("Joined key to {.file {db}}")
}
#' Generate officers
if (file.exists("private/officer.parquet")) {
warning("Officer data exists. Run all joins to ensure veracity.")
}
officer$
generate_key()$
collect()$
write_parquet("private/officer.parquet")
#' Join specifications
spec <-
tribble(
~db, ~on,
"db/arrest.parquet", officer$key(),
"db/assignment.parquet", officer$key(),
"db/military.parquet", officer$key(),
"db/stop.parquet", officer$key(),
"db/warrant.parquet", gsub("appointed", "appointed_year", officer$key())
)
spec_asof <-
tribble(
~db, ~by,
"db/contact.parquet", c("last_name", "first_name"),
"db/force.parquet", c("last_name", "first_name", "appointed")
)
#' Join UID to imported data
pmap_vec(spec, join_and_write)
pmap_vec(spec_asof, join_asof_and_write)
#' Check proportion missing
sapply(c(spec$db, spec_asof$db), validate$null_count)