Skip to content

Commit

Permalink
add support for downloading rpvnearme data
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkenny committed Dec 30, 2023
1 parent 42bcbd0 commit 0803c3a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export(get_alarm)
export(get_dra)
export(get_heda)
export(get_lewis)
export(get_rpvnearme)
export(get_vest)
export(global_gearys)
export(global_morans)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# geomander 2.2.1

* Adds support for downloading Jeffrey B. Lewis's historical congressional districts with `get_lewis()
* Adds support for downloading RPV Near Me datasets with `get_rpvnearme()`
* Corrects normalized global Moran's I calculation (#12), thanks @CoryMcCartan.

# geomander 2.2.0
* Updates dependencies for easier installation.
* Allows for use of `circle` as a method in `geo_match()`.
Expand Down
33 changes: 33 additions & 0 deletions R/rpvnearme.R
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)
}
3 changes: 1 addition & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ knitr::opts_chunk$set(
[![R-CMD-check](https://github.com/christopherkenny/geomander/workflows/R-CMD-check/badge.svg)](https://github.com/christopherkenny/geomander/actions)
[![CRAN status](https://www.r-pkg.org/badges/version/geomander)](https://CRAN.R-project.org/package=geomander)
![CRAN downloads](http://cranlogs.r-pkg.org/badges/grand-total/geomander)
[![r-universe status badge](https://christopherkenny.r-universe.dev/badges/geomander)](https://christopherkenny.r-universe.dev/ui#package:geomander)
<!-- badges: end -->

Focuses on creating data sets and other tools that help make understanding gerrymandering faster and easier. Designed for easy preparation to run simulation analysis with the R package redist, but is aimed at the geographic aspects of redistricting, not partitioning methods. Most of these tools are gathered from seminar papers and do not correspond to a single publication.
Expand All @@ -38,8 +39,6 @@ And the development version from [GitHub](https://github.com/) with:
devtools::install_github("christopherkenny/geomander")
```



## Examples

A very common task is aggregating block data to precincts.
Expand Down
22 changes: 22 additions & 0 deletions man/get_rpvnearme.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0803c3a

Please sign in to comment.