-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for downloading rpvnearme data
- Loading branch information
1 parent
42bcbd0
commit 0803c3a
Showing
5 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#' Get Racially Polarized Voting Dataset from RPV Near Me | ||
#' | ||
#' @param state the state postal code of the state | ||
#' @param version the version of the data to use. `1` for the original, `2` for the extended. | ||
#' | ||
#' @return a tibble of precinct-level estimates of votes (party) by race | ||
#' @export | ||
#' | ||
#' @examples | ||
#' get_rpvnearme('DE') | ||
get_rpvnearme <- function(state, version = c(1, 2)) { | ||
|
||
cli::cli_inform( | ||
'Data sourced from the RPV Near Me {.url https://www.rpvnearme.org/}.', | ||
.frequency = 'once', | ||
.frequency_id = 'cite_rpvnearme' | ||
) | ||
|
||
vers <- match.arg(as.character(version), as.character(1:2)) | ||
|
||
vers <- ifelse(vers == 1, '', '_b') | ||
|
||
if (missing(state)) { | ||
cli::cli_abort('Please provide a postal code, fips code, or name to state.') | ||
} | ||
|
||
state <- censable::match_abb(state) | ||
base_path <- stringr::str_glue( | ||
'https://raw.githubusercontent.com/electionlawclinic/rpvnearme/main/data/{state}_county_2020_precinct{vers}.csv' | ||
) | ||
|
||
readr::read_csv(base_path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.