get_election_data: Load raw microdata for one or more races

View source: R/data_access.R

get_election_dataR Documentation

Load raw microdata for one or more races

Description

Determines which county files are needed for the requested races, loads them (downloading if necessary), and returns a combined data.frame with only the relevant columns.

Usage

get_election_data(elections, source = NULL)

Arguments

elections

Character vector of race codes, e.g. c("PRE", "USS"). All codes must be keys in election_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

The counties to load are determined automatically from election_catalog. For races spanning all counties (counties = "all"), every county in county_catalog is loaded. For district-level races, only the relevant counties are loaded.

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 columns COUNTY, PRECINCT, and one column per requested race. Rows from all relevant counties are combined via rbind. Voters not eligible for a given race have NA in that column.

See Also

get_county_data(), ei_summary()

Examples


# Presidential and Senate races (all counties)
df <- get_election_data(c("PRE", "USS"))

# Including a district-level race (only counties with that race)
df <- get_election_data(c("PRE", "HOS3"))



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