get_county_data: Load raw microdata for a single county

View source: R/data_access.R

get_county_dataR Documentation

Load raw microdata for a single county

Description

Reads a county-level .RData file and returns its contents as a data.frame. The data source is resolved in this order:

  1. The source argument (if not NULL).

  2. getOption("data_dir") (set once with options(data_dir = ...)).

  3. The default OSF repository (online).

Usage

get_county_data(county, source = NULL)

Arguments

county

Character string. County code, e.g. "Lee". Must be a key in county_catalog.

source

Character string or NULL. Either a local directory path (e.g. "~/data/") or the base URL of a remote repository. If NULL, the source is resolved automatically (see Details).

Details

To avoid specifying source in every call, set options(data_dir) once at the start of your session or in your .Rprofile:

options(data_dir = "~/my_data/")   # local files
# or leave unset to use the online OSF repository

Value

A data.frame with one row per voter and columns:

  • COUNTY: county code.

  • PRECINCT: precinct identifier within the county.

  • One column per race on the ballot (see election_catalog for the code-to-office mapping).

See Also

get_election_data(), ei_summary(), list_counties()

Examples


# From the online repository
lee <- get_county_data("Lee")

# From a local directory
lee <- get_county_data("Lee", source = "~/local_data/")



eiballots documentation built on Sept. 26, 2026, 5:06 p.m.