| Title: | Access Australian Electoral Commission Data |
|---|---|
| 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. |
| Authors: | Charles Coverdale [aut, cre] |
| Maintainer: | Charles Coverdale <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.3 |
| Built: | 2026-06-02 08:10:02 UTC |
| Source: | https://github.com/charlescoverdale/readaec |
Deletes all files downloaded and cached by readaec. The next function call will re-download fresh data from the AEC.
clear_cache()clear_cache()
Invisibly returns NULL. Called for its side effect of deleting
cached files.
op <- options(readaec.cache_dir = tempdir()) clear_cache() options(op)op <- options(readaec.cache_dir = tempdir()) clear_cache() options(op)
Get all candidates for an election
get_candidates(year, chamber = "house")get_candidates(year, chamber = "house")
year |
Election year. Use |
chamber |
"house" or "senate". |
A tidy data frame of candidates.
op <- options(readaec.cache_dir = tempdir()) get_candidates(2022) get_candidates(2022, chamber = "senate") options(op)op <- options(readaec.cache_dir = tempdir()) get_candidates(2022) get_candidates(2022, chamber = "senate") options(op)
Get enrolment by division
get_enrolment(year)get_enrolment(year)
year |
Election year. Use |
A tidy data frame of enrolment figures by division.
op <- options(readaec.cache_dir = tempdir()) get_enrolment(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_enrolment(2022) options(op)
Get first preference votes by division
get_fp(year)get_fp(year)
year |
Election year. Use |
A tidy data frame of first preference votes by division.
op <- options(readaec.cache_dir = tempdir()) get_fp(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_fp(2022) options(op)
Get first preference votes by polling place
get_fp_by_booth(year, state = NULL)get_fp_by_booth(year, state = NULL)
year |
Election year. Use |
state |
Filter to a specific state (e.g. "VIC"). NULL returns all states. |
A tidy data frame of first preference votes by polling place.
op <- options(readaec.cache_dir = tempdir()) get_fp_by_booth(2022, state = "VIC") options(op)op <- options(readaec.cache_dir = tempdir()) get_fp_by_booth(2022, state = "VIC") options(op)
Get members elected to the House of Representatives
get_members_elected(year)get_members_elected(year)
year |
Election year. Use |
A tidy data frame of elected members.
op <- options(readaec.cache_dir = tempdir()) get_members_elected(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_members_elected(2022) options(op)
Returns all polling place addresses and coordinates for a given election.
get_polling_places(year, division = NULL)get_polling_places(year, division = NULL)
year |
Election year. Use |
division |
Filter to a specific division name. NULL returns all. |
A tidy data frame of polling places with lat/lon coordinates.
op <- options(readaec.cache_dir = tempdir()) get_polling_places(2022) get_polling_places(2022, division = "Kooyong") options(op)op <- options(readaec.cache_dir = tempdir()) get_polling_places(2022) get_polling_places(2022, division = "Kooyong") options(op)
Get Senate first preference votes by state
get_senate(year)get_senate(year)
year |
Election year. Use |
A tidy data frame of Senate first preference votes by state.
op <- options(readaec.cache_dir = tempdir()) get_senate(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_senate(2022) options(op)
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.
get_swing(from, to, division = NULL, state = NULL)get_swing(from, to, division = NULL, state = NULL)
from |
Election year to compare from. Use |
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"). |
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 |
op <- options(readaec.cache_dir = tempdir()) # 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) options(op)op <- options(readaec.cache_dir = tempdir()) # 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) options(op)
Get two-candidate preferred votes by division
get_tcp(year)get_tcp(year)
year |
Election year. Use |
A tidy data frame of TCP votes by division.
op <- options(readaec.cache_dir = tempdir()) get_tcp(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_tcp(2022) options(op)
Get two-party preferred votes by division
get_tpp(year)get_tpp(year)
year |
Election year. Use |
A tidy data frame of TPP votes by division.
op <- options(readaec.cache_dir = tempdir()) get_tpp(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_tpp(2022) options(op)
Get two-party preferred votes by polling place
get_tpp_by_booth(year)get_tpp_by_booth(year)
year |
Election year. Use |
A tidy data frame of TPP votes by polling place.
op <- options(readaec.cache_dir = tempdir()) get_tpp_by_booth(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_tpp_by_booth(2022) options(op)
Get turnout by division
get_turnout(year)get_turnout(year)
year |
Election year. Use |
A tidy data frame of turnout figures by division.
op <- options(readaec.cache_dir = tempdir()) get_turnout(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_turnout(2022) options(op)
List all available federal elections
list_elections()list_elections()
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.
list_elections() # Only years with downloadable data list_elections()[list_elections()$has_downloads, ]list_elections() # Only years with downloadable data list_elections()[list_elections()$has_downloads, ]