Skip to content

Commit

Permalink
fix to remove stale counties
Browse files Browse the repository at this point in the history
  • Loading branch information
mreece13 committed Jul 23, 2024
1 parent bfb06fb commit fefd74a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions code/build-release/code/02_subset-to-release.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ redact_precinct <- read_csv(path(PATH_parq, "intermediate/precinct_crosswalk/aff
show_col_types = FALSE)


# first, clear out release directory so we get a fresh copy everytime

if (dir_exists(PATH_release)) dir_delete(PATH_release)

# Subset and WRITE ----
ds |>
# limit to release counties
Expand All @@ -46,11 +50,8 @@ ds |>
mutate(precinct_cvr = ifelse(redact == 1 & !is.na(redact), NA, precinct_cvr)) |>
relocate(precinct_medsl, precinct_cvr, .after = precinct) |>
select(-precinct, -matches("revealed_in_"), -matches("redact"), -matches("precs_revel")) |>
# stray writein
mutate(party = ifelse(candidate == "PROGRESSIVE" & state == "NEW JERSEY", NA, party)) |>
write_dataset(
path = PATH_release,
existing_data_behavior = "delete_matching",
partitioning = c("state", "county_name"),
format = "parquet"
)
Expand Down
17 changes: 9 additions & 8 deletions code/build-release/code/fmt_release.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ fmt_for_release <- function(tbl) {
party_detailed = ifelse(candidate == "WRITEIN", "WRITEIN", party_detailed)
) |>
mutate(
party = NA_character_,
party = ifelse(party_detailed == "DEMOCRAT", "DEM", party),
party = ifelse(party_detailed == "REPUBLICAN", "REP", party),
party = ifelse(party_detailed == "LIBERTARIAN", "LBT", party),
party = ifelse(party_detailed == "GREEN", "GRN", party),
party = ifelse(!party %in% c("DEM", "REP", "LBT", "GRN"), "OTH", party),
# revert invalid votes to party = NA
party = ifelse(candidate %in% c("UNDERVOTE", "OVERVOTE", "WRITEIN", "NOT QUALIFIED"), NA, party),
party = case_when(
candidate %in% c("UNDERVOTE", "OVERVOTE", "NOT QUALIFIED") ~ NA_character_,
party_detailed == "WRITEIN" ~ NA_character_,
party_detailed == "DEMOCRAT" ~ "DEM",
party_detailed == "REPUBLICAN" ~ "REP",
party_detailed == "LIBERTARIAN" ~ "LBT",
party_detailed == "GREEN" ~ "GRN",
.default = "OTH"
),
.before = party_detailed
)
}
1 change: 0 additions & 1 deletion status/counties-in-release.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@
|NEVADA |WASHOE |
|NEVADA |WHITE PINE |
|NEW JERSEY |BERGEN |
|NEW JERSEY |CAMDEN |
|NEW JERSEY |CUMBERLAND |
|NEW JERSEY |GLOUCESTER |
|NEW JERSEY |MONMOUTH |
Expand Down

0 comments on commit fefd74a

Please sign in to comment.