Title: Access Australian Electoral Commission Data
Version: 0.1.1
Description: Provides clean, tidy access to Australian Electoral Commission (AEC) federal election data. Includes results for the House of Representatives and Senate from 2007 onwards, at both division and polling place level. Data is downloaded directly from the AEC https://results.aec.gov.au on first use and cached locally for subsequent calls.
License: MIT + file LICENSE
Encoding: UTF-8
Language: en-AU
RoxygenNote: 7.3.3
Imports: httr2, readr, dplyr, cli, rappdirs, glue
Suggests: ggplot2, purrr, tidyr, sf, knitr, rmarkdown, testthat (≥ 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
URL: https://github.com/charlescoverdale/readaec
BugReports: https://github.com/charlescoverdale/readaec/issues
NeedsCompilation: no
Packaged: 2026-03-05 20:30:32 UTC; charlescoverdale
Author: Charles Coverdale [aut, cre]
Maintainer: Charles Coverdale <charlesfcoverdale@gmail.com>
Repository: CRAN
Date/Publication: 2026-03-10 11:40:02 UTC

Clear the local AEC data cache

Description

Deletes all files downloaded and cached by readaec. The next function call will re-download fresh data from the AEC.

Usage

clear_cache()

Value

Invisibly returns NULL. Called for its side effect of deleting cached files.

Examples


clear_cache()


Get all candidates for an election

Description

Get all candidates for an election

Usage

get_candidates(year, chamber = "house")

Arguments

year

Election year. Use list_elections() to see available years.

chamber

"house" or "senate".

Value

A tidy data frame of candidates.

Examples


get_candidates(2022)
get_candidates(2022, chamber = "senate")


Get enrolment by division

Description

Get enrolment by division

Usage

get_enrolment(year)

Arguments

year

Election year. Use list_elections() to see available years.

Value

A tidy data frame of enrolment figures by division.

Examples


get_enrolment(2022)


Get first preference votes by division

Description

Get first preference votes by division

Usage

get_fp(year)

Arguments

year

Election year. Use list_elections() to see available years.

Value

A tidy data frame of first preference votes by division.

Examples


get_fp(2022)


Get first preference votes by polling place

Description

Get first preference votes by polling place

Usage

get_fp_by_booth(year, state = NULL)

Arguments

year

Election year. Use list_elections() to see available years.

state

Filter to a specific state (e.g. "VIC"). NULL returns all states.

Value

A tidy data frame of first preference votes by polling place.

Examples


get_fp_by_booth(2022, state = "VIC")


Get members elected to the House of Representatives

Description

Get members elected to the House of Representatives

Usage

get_members_elected(year)

Arguments

year

Election year. Use list_elections() to see available years.

Value

A tidy data frame of elected members.

Examples


get_members_elected(2022)


Get polling place locations

Description

Returns all polling place addresses and coordinates for a given election.

Usage

get_polling_places(year, division = NULL)

Arguments

year

Election year. Use list_elections() to see available years.

division

Filter to a specific division name. NULL returns all.

Value

A tidy data frame of polling places with lat/lon coordinates.

Examples


get_polling_places(2022)
get_polling_places(2022, division = "Kooyong")


Get Senate first preference votes by state

Description

Get Senate first preference votes by state

Usage

get_senate(year)

Arguments

year

Election year. Use list_elections() to see available years.

Value

A tidy data frame of Senate first preference votes by state.

Examples


get_senate(2022)


Compare TPP results between two elections

Description

Calculates the change in two-party preferred vote share between any two federal elections. Joins on division ID (not name) to handle renamed divisions correctly. Divisions that don't appear in both elections are flagged rather than silently dropped.

Usage

get_swing(from, to, division = NULL, state = NULL)

Arguments

from

Election year to compare from. Use list_elections() to see available years.

to

Election year to compare to.

division

Optionally filter to one or more division names.

state

Optionally filter to a state abbreviation (e.g. "VIC").

Value

A data frame with one row per division containing:

division

Division name (from the later election)

division_id

AEC division ID

state

State abbreviation

alp_pct_from, alp_pct_to

ALP TPP percentage in each election

lnp_pct_from, lnp_pct_to

LNP TPP percentage in each election

alp_swing

Change in ALP TPP (positive = swing to ALP)

lnp_swing

Change in LNP TPP (positive = swing to LNP)

winner_from, winner_to

Winning party in each election

seat_changed

TRUE if the seat changed hands

redistribution_flag

TRUE if the division only appears in one election

Examples


# National swing 2019 to 2022
get_swing(2019, 2022)

# Teal seats in Victoria
get_swing(2019, 2022, state = "VIC")

# A single seat
get_swing(2019, 2022, division = "Kooyong")

# Long-run comparison
get_swing(2013, 2025)


Get two-candidate preferred votes by division

Description

Get two-candidate preferred votes by division

Usage

get_tcp(year)

Arguments

year

Election year. Use list_elections() to see available years.

Value

A tidy data frame of TCP votes by division.

Examples


get_tcp(2022)


Get two-party preferred votes by division

Description

Get two-party preferred votes by division

Usage

get_tpp(year)

Arguments

year

Election year. Use list_elections() to see available years.

Value

A tidy data frame of TPP votes by division.

Examples


get_tpp(2022)


Get two-party preferred votes by polling place

Description

Get two-party preferred votes by polling place

Usage

get_tpp_by_booth(year)

Arguments

year

Election year. Use list_elections() to see available years.

Value

A tidy data frame of TPP votes by polling place.

Examples


get_tpp_by_booth(2022)


Get turnout by division

Description

Get turnout by division

Usage

get_turnout(year)

Arguments

year

Election year. Use list_elections() to see available years.

Value

A tidy data frame of turnout figures by division.

Examples


get_turnout(2022)


List all available federal elections

Description

List all available federal elections

Usage

list_elections()

Value

A data frame with one row per election, including columns year, date, event_id, type, and has_downloads. The has_downloads column is TRUE for years where AEC CSV downloads are available (2007 onwards). The 2001 and 2004 elections are listed for reference but their data cannot be fetched.

Examples

list_elections()

# Only years with downloadable data
list_elections()[list_elections()$has_downloads, ]