diff --git a/NAMESPACE b/NAMESPACE index f945f5b..f5de229 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index 2fa0e67..a98db20 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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()`. diff --git a/R/rpvnearme.R b/R/rpvnearme.R new file mode 100644 index 0000000..43f207f --- /dev/null +++ b/R/rpvnearme.R @@ -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) +} \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index 94f2b41..815cea0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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) 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. @@ -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. diff --git a/man/get_rpvnearme.Rd b/man/get_rpvnearme.Rd new file mode 100644 index 0000000..f2ca3d3 --- /dev/null +++ b/man/get_rpvnearme.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rpvnearme.R +\name{get_rpvnearme} +\alias{get_rpvnearme} +\title{Get Racially Polarized Voting Dataset from RPV Near Me} +\usage{ +get_rpvnearme(state, version = c(1, 2)) +} +\arguments{ +\item{state}{the state postal code of the state} + +\item{version}{the version of the data to use. \code{1} for the original, \code{2} for the extended.} +} +\value{ +a tibble of precinct-level estimates of votes (party) by race +} +\description{ +Get Racially Polarized Voting Dataset from RPV Near Me +} +\examples{ +get_rpvnearme('DE') +}