You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
761B

  1. get_candidate_listing <- function(years = 2016:2023) {
  2. years |>
  3. map(get_candidate_listing_year) |>
  4. bind_rows() |>
  5. type_convert(
  6. col_types = cols(
  7. election_dt = col_date(format = "%m/%d/%Y"),
  8. candidacy_dt = col_date(format = "%m/%d/%Y")
  9. )
  10. ) |>
  11. mutate(
  12. across(
  13. contains("phone"),
  14. \(.x) sub("(\\d{3})(\\d{3})(\\d{4})", "(\\1) \\2-\\3", .x)
  15. ),
  16. across(street_address, fixup_po_box)
  17. )
  18. }
  19. get_candidate_listing_year <- function(year) {
  20. url <- glue::glue("https://s3.amazonaws.com/dl.ncsbe.gov/Elections/{year}/Candidate%20Filing/Candidate_Listing_{year}.csv")
  21. read_csv(
  22. url,
  23. col_types = cols(.default = col_character()),
  24. locale = locale(encoding = "latin1")
  25. )
  26. }