MyNixOS website logo
Description

Wrangle Campaign Finance Data.

Explore and normalize American campaign finance data. Created by the Investigative Reporting Workshop to facilitate work on The Accountability Project, an effort to collect public data into a central, standard database that is more easily searched: <https://publicaccountability.org/>.

campfin

Lifecycle:maturing CRANstatus Downloads Codecov testcoverage R buildstatus

The campfin package was created to facilitate the work being done on the The Accountability Project, a tool created by The Investigative Reporting Workshop in Washington, DC. The Accountability Project curates, cleans, and indexes public data to give journalists, researchers and others a simple way to search across otherwise siloed records.

The data focuses on people, organizations and locations. This package was created specifically to help with state-level campaign finance data, although the tools included are useful in general database exploration and normalization.

Installation

You can install the released version of campfin from CRAN with:

install.packages("campfin")

The development version can be installed from GitHub with:

# install.packages("remotes")
remotes::install_github("irworkshop/campfin")

Normalize

The package was originally built to normalize geographic data using the normal_*() functions, which take the messy self-reported geographic data of a contributor, vendor, candidate, or committee and return normalized text that is more searchable. They are largely wrappers around the stringr package, and can call other sub-functions to streamline normalization.

  • normal_address() takes a street address and reduces inconsistencies.
  • normal_zip() takes ZIP Codes and aims to return a valid 5-digit code.
  • normal_state() takes US states and returns a 2 digit abbreviation.
  • normal_city() takes cities and reduces inconsistencies.
  • normal_phone() consistently formats US telephone numbers.

Please see the vignette on normalization for an example of how these functions are used to fix a wide variety of string inconsistencies and make campaign finance data more consistent.

Data

library(campfin)
library(tidyverse)

The campfin package contains a number of built in data frames and strings used to help wrangle campaign finance data.

The /data-raw directory contains the code used to create the objects.

zipcodes

The zipcodes (plural) table is a new version of the zipcode (singular) table from the archived zipcode R package.

This database was composed using ZIP code gazetteers from the US Census Bureau from 1999 and 2000, augmented with additional ZIP code information The database is believed to contain over 98% of the ZIP Codes in current use in the United States. The remaining ZIP Codes absent from this database are entirely PO Box or Firm ZIP codes added in the last five years, which are no longer published by the Census Bureau, but in any event serve a very small minority of the population (probably on the order of .1% or less). Although every attempt has been made to filter them out, this data set may contain up to .5% false positives, that is, ZIP codes that do not exist or are no longer in use but are included due to erroneous data sources.

The included valid_city and valid_zip vectors are sorted, unique columns from the zipcodes data frame.

sample_frac(zipcodes)
#> # A tibble: 44,336 × 3
#>    city       state zip  
#>    <chr>      <chr> <chr>
#>  1 SAN JUAN   PR    00914
#>  2 BRANCHDALE PA    17923
#>  3 ATHENS     IL    62613
#>  4 ALBANY     GA    31706
#>  5 HULL       IA    51239
#>  6 CHICAGO    IL    60640
#>  7 WASHINGTON DC    20380
#>  8 LA HONDA   CA    94020
#>  9 POMONA     CA    91767
#> 10 OSHKOSH    NE    69190
#> # … with 44,326 more rows

usps_* and valid_*

The usps_* data frames were scraped from the official United States Postal Service (USPS) Postal Addressing Standards. These data frames are designed to work with the abbreviation functionality of normal_address() and normal_city() to replace common abbreviations with their full equivalent.

usps_city is a curated subset of usps_state, whose full version appear at least once in the valid_city vector from zipcodes. The valid_state and valid_name vectors contain the columns from usps_state and include territories not found in R’s build in state.abb and state.name vectors.

sample_n(usps_street, 3)
#> # A tibble: 3 × 2
#>   full   abb  
#>   <chr>  <chr>
#> 1 PLAIN  PLN  
#> 2 COVE   CV   
#> 3 ARCADE ARC
sample_n(usps_state, 3)
#> # A tibble: 3 × 2
#>   full      abb  
#>   <chr>     <chr>
#> 1 UTAH      UT   
#> 2 ALABAMA   AL   
#> 3 WISCONSIN WI
setdiff(valid_state, state.abb)
#>  [1] "AS" "AA" "AE" "AP" "DC" "FM" "GU" "MH" "MP" "PW" "PR" "VI"

The campfin project is released with a Contributor Code of Conduct. By contributing, you agree to abide by its terms.

Metadata

Version

1.0.11

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • 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-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
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • 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-windows