| 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, plus by-elections from 2008 onwards, the 2023 referendum, and the full distribution of preferences. 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.2.0 |
| Built: | 2026-09-19 11:25:52 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 by-election candidates
get_by_election_candidates(division, year = NULL, refresh = FALSE)get_by_election_candidates(division, year = NULL, refresh = FALSE)
division |
Division name (e.g. "Farrer"). |
year |
By-election year. Only needed where a division has had more than one by-election (e.g. Mayo in 2008 and 2018). |
refresh |
If |
A tidy data frame of candidates.
op <- options(readaec.cache_dir = tempdir()) get_by_election_candidates("Farrer") options(op)op <- options(readaec.cache_dir = tempdir()) get_by_election_candidates("Farrer") options(op)
By-election results are published at polling place level. Use
list_by_elections() to see which by-elections are available.
get_by_election_fp(division, year = NULL, refresh = FALSE)get_by_election_fp(division, year = NULL, refresh = FALSE)
division |
Division name (e.g. "Farrer"). |
year |
By-election year. Only needed where a division has had more than one by-election (e.g. Mayo in 2008 and 2018). |
refresh |
If |
A tidy data frame of first preference votes by polling place.
op <- options(readaec.cache_dir = tempdir()) get_by_election_fp("Farrer") options(op)op <- options(readaec.cache_dir = tempdir()) get_by_election_fp("Farrer") options(op)
Get by-election two-candidate preferred votes by polling place
get_by_election_tcp(division, year = NULL, refresh = FALSE)get_by_election_tcp(division, year = NULL, refresh = FALSE)
division |
Division name (e.g. "Farrer"). |
year |
By-election year. Only needed where a division has had more than one by-election (e.g. Mayo in 2008 and 2018). |
refresh |
If |
A tidy data frame of TCP votes by candidate by polling place.
op <- options(readaec.cache_dir = tempdir()) get_by_election_tcp("Farrer") options(op)op <- options(readaec.cache_dir = tempdir()) get_by_election_tcp("Farrer") options(op)
Note that TPP figures are only meaningful where the final two candidates
were ALP and Coalition. In by-elections decided between other candidates
(such as Farrer in 2026), use get_by_election_tcp() instead.
get_by_election_tpp(division, year = NULL, refresh = FALSE)get_by_election_tpp(division, year = NULL, refresh = FALSE)
division |
Division name (e.g. "Farrer"). |
year |
By-election year. Only needed where a division has had more than one by-election (e.g. Mayo in 2008 and 2018). |
refresh |
If |
A tidy data frame of TPP votes by polling place.
op <- options(readaec.cache_dir = tempdir()) get_by_election_tpp("Dunkley") options(op)op <- options(readaec.cache_dir = tempdir()) get_by_election_tpp("Dunkley") options(op)
Get all candidates for an election
get_candidates(year, chamber = "house", refresh = FALSE)get_candidates(year, chamber = "house", refresh = FALSE)
year |
Election year. Use |
chamber |
"house" or "senate". |
refresh |
If |
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)
Returns the count-by-count distribution of preferences for every division: each exclusion round, the candidate excluded, and where their preferences flowed. This is the dataset for analysing seats won from second or third place on preference flows, which division-level TPP and TCP figures cannot show.
get_dop(year, refresh = FALSE)get_dop(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
A tidy data frame with one row per candidate per count per
division, including countnumber, calculationtype
(preference count, transfer count, and percentages), and
calculationvalue.
op <- options(readaec.cache_dir = tempdir()) dop <- get_dop(2025) # Final count in a single seat mel <- subset(dop, division == "Melbourne") subset(mel, countnumber == max(countnumber)) options(op)op <- options(readaec.cache_dir = tempdir()) dop <- get_dop(2025) # Final count in a single seat mel <- subset(dop, division == "Melbourne") subset(mel, countnumber == max(countnumber)) options(op)
Get enrolment by division
get_enrolment(year, refresh = FALSE)get_enrolment(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
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, refresh = FALSE)get_fp(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
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, refresh = FALSE)get_fp_by_booth(year, state = NULL, refresh = FALSE)
year |
Election year. Use |
state |
Filter to a specific state (e.g. "VIC"). NULL returns all states. |
refresh |
If |
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, refresh = FALSE)get_members_elected(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
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, refresh = FALSE)get_polling_places(year, division = NULL, refresh = FALSE)
year |
Election year. Use |
division |
Filter to a specific division name. NULL returns all. |
refresh |
If |
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)
Returns Yes and No votes for every polling place, including formal and informal counts.
get_referendum_by_booth(year = 2023, state = NULL, refresh = FALSE)get_referendum_by_booth(year = 2023, state = NULL, refresh = FALSE)
year |
Referendum year. Use |
state |
Filter to a specific state (e.g. "VIC"). NULL returns all states. |
refresh |
If |
A tidy data frame of Yes/No votes by polling place.
op <- options(readaec.cache_dir = tempdir()) get_referendum_by_booth(2023, state = "TAS") options(op)op <- options(readaec.cache_dir = tempdir()) get_referendum_by_booth(2023, state = "TAS") options(op)
Get referendum turnout
get_referendum_turnout(year = 2023, by = "division", refresh = FALSE)get_referendum_turnout(year = 2023, by = "division", refresh = FALSE)
year |
Referendum year. Use |
by |
Aggregation level: "division" (default) or "state". |
refresh |
If |
A tidy data frame of enrolment and turnout.
op <- options(readaec.cache_dir = tempdir()) get_referendum_turnout(2023) get_referendum_turnout(2023, by = "state") options(op)op <- options(readaec.cache_dir = tempdir()) get_referendum_turnout(2023) get_referendum_turnout(2023, by = "state") options(op)
Get Senate first preference votes by state
get_senate(year, refresh = FALSE)get_senate(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
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)
Returns the senators elected at each election, in the order they were elected within each state or territory.
get_senators_elected(year, refresh = FALSE)get_senators_elected(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
A tidy data frame with one row per senator elected, including
state, given_name, surname, party, party_name, and
elected_order.
op <- options(readaec.cache_dir = tempdir()) get_senators_elected(2025) options(op)op <- options(readaec.cache_dir = tempdir()) get_senators_elected(2025) 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, refresh = FALSE)get_swing(from, to, division = NULL, state = NULL, refresh = FALSE)
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"). |
refresh |
If |
The winner columns report the party that actually won the seat (from the AEC's members elected file), so crossbench seats are identified correctly. The TPP leader columns report which of ALP or the Coalition led the two-party preferred count, which is not the same thing in seats won by independents and minor parties.
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
|
Party that won the seat in each election |
tpp_leader_from, tpp_leader_to
|
Which of ALP/LNP led the TPP count |
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, refresh = FALSE)get_tcp(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
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-candidate preferred votes by polling place
get_tcp_by_booth(year, refresh = FALSE)get_tcp_by_booth(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
A tidy data frame of TCP votes by candidate by polling place.
op <- options(readaec.cache_dir = tempdir()) get_tcp_by_booth(2022) options(op)op <- options(readaec.cache_dir = tempdir()) get_tcp_by_booth(2022) options(op)
Get two-party preferred votes by division
get_tpp(year, refresh = FALSE)get_tpp(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
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, refresh = FALSE)get_tpp_by_booth(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
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, refresh = FALSE)get_turnout(year, refresh = FALSE)
year |
Election year. Use |
refresh |
If |
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)
Lists House of Representatives by-elections with results published on the AEC tally room, from 2005 onwards. The 2014 WA Senate special election is not included as it was not a House by-election.
list_by_elections()list_by_elections()
A data frame with one row per by-election, including columns
division, state, date, year, event_id, and has_downloads.
The has_downloads column is TRUE where AEC CSV downloads are
available (2008 onwards).
list_by_elections()list_by_elections()
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, ]
List available referendums
list_referendums()list_referendums()
A data frame with one row per referendum with results published
on the AEC tally room, including columns year, date, event_id,
and description.
list_referendums()list_referendums()