MyNixOS website logo
Description

Voter Distance to Polling Locations.

Calculates the distance between each voter in a voter file (given lat/long coordinates or sf point geometries) and multiple polling or vote-by-mail drop box locations. Returns nearest location, k-nearest locations, or all locations within a distance threshold. Core computation uses the Haversine formula implemented in C++ via 'Rcpp'.

Rvoterdistance

Calculates the geographic distance between voters in a voter file and multiple polling or vote-by-mail drop box locations using the Haversine (great-circle) formula. Core computation is implemented in C++ via Rcpp for speed.

Features

  • Nearest location: find the single closest polling place for each voter
  • k-nearest locations: find the k closest locations per voter
  • Distance threshold: find all locations within a specified radius (e.g., all drop boxes within 5 miles)
  • sf integration: pass sf POINT geometries directly with automatic CRS transformation to WGS-84
  • Progress reporting: optional progress output for large voter files
  • Units: results in meters, kilometers, and miles

Installation

# From GitHub:
remotes::install_github("lorenc5/Rvoterdistance")

Quick Start

library(Rvoterdistance)
data(meck_ev)

# Nearest early voting location for each voter
result <- nearest_location(voter_meck, early_meck,
  voter_coords = c("lat", "long"),
  location_coords = c("lat", "long"))
head(result)

# 3 nearest locations per voter
result_k3 <- nearest_location(voter_meck, early_meck,
  voter_coords = c("lat", "long"),
  location_coords = c("lat", "long"),
  k = 3)

# All locations within 5 miles
result_5mi <- nearest_location(voter_meck, early_meck,
  voter_coords = c("lat", "long"),
  location_coords = c("lat", "long"),
  max_dist = 5, units = "miles")

Main Functions

FunctionDescription
nearest_location()Main entry point. Supports k-nearest, distance threshold, sf objects.
dist_km()Minimum distance to nearest location in kilometers.
dist_mile()Minimum distance to nearest location in miles.
haversine()Single-pair great-circle distance with configurable units.

Using sf Objects

library(sf)
voters_sf <- st_as_sf(voter_meck, coords = c("long", "lat"), crs = 4326)
locs_sf   <- st_as_sf(early_meck, coords = c("long", "lat"), crs = 4326)

result <- nearest_location(voters_sf, locs_sf)

If the CRS is not WGS-84 (EPSG:4326), coordinates are automatically transformed.

Included Data

  • king_dbox / king_geo: King County, WA ballot drop box locations and voter sample
  • meck_ev (voter_meck / early_meck): Mecklenburg County, NC early voting locations and voter sample

Citation

Collingwood, Loren. 2026. Rvoterdistance: Voter Distance to Polling Locations. R package version 2.0.0. https://github.com/lorenc5/Rvoterdistance

License

GPL (>= 2)

Metadata

Version

2.0.0

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows