Skip to content

Commit fefe935

Browse files
authored
Merge pull request #23 from kuriwaki/za
update 2024 data with new daily kos spreadsheet
2 parents 855eed9 + bf51f7a commit fefe935

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Description: This provides data loading, processing, and formatting functions fo
2020
Encoding: UTF-8
2121
LazyData: true
2222
Depends:
23-
R (>= 2.10),
23+
R (>= 3.5)
2424
Imports:
2525
tibble,
2626
magrittr,

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ccesMRPprep 0.1.14
22

3+
* Add 2024 election data to cd_info_2024
34
* Update dataverse paths for cumulative and 2024
45
* Add versions argument for get_cces_dataverse
56

R/datadoc_cces-common-samp.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@
5858
#' "CCES Common Content, 2018", <doi:https://doi.org/10.7910>, Harvard Dataverse V6.
5959
#'
6060
#' @examples
61-
#'
61+
#' \dontrun{
6262
#' # use questionr::lookfor to search the label and labels
63-
#' questionr::lookfor(cc18_samp, "Trump")
63+
#' questionr::lookfor(cc18_samp, "Trump")
64+
#' }
6465
#'
66+
#' library(tibble)
6567
#' # all data
6668
#' cc18_samp
6769
#'

data-raw/create_dist-level-data_2022-2024.R

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
library(tidyverse)
22
library(googlesheets4)
3+
library(janitor)
34

45
# Authenticate with Google Sheets
56
# gs4_auth()
67

78
# URLs for your Google Sheets
89
url_2022 <- "https://docs.google.com/spreadsheets/d/1CKngqOp8fzU22JOlypoxNsxL6KSAH920Whc-rd7ebuM/edit?usp=sharing"
9-
url_2024 <- "https://docs.google.com/spreadsheets/d/1Sg4ZZz5FcX7lz-m2xqmYtndaO2uEMSaL7x99AbQOvv8/edit?usp=sharing"
10-
url_geo_119 <- "https://docs.google.com/spreadsheets/d/12YaBonkqHAjkXhzyKlH2-1t-smZ6J5j76RCBSJEwQHo/edit?usp=sharing"
10+
url_2024 <- "https://docs.google.com/spreadsheets/d/1ng1i_Dm_RMDnEvauH44pgE6JCUsapcuu8F2pCfeLWFo/edit?gid=1491069057#gid=1491069057"
1111
url_geo_118 <- "https://docs.google.com/spreadsheets/d/1weoLFu2U5lmxQNcB8pFItGHj1Lb_M2E9Oi48sI4w1vY/edit?usp=sharing"
12+
url_geo_119 <- "https://docs.google.com/spreadsheets/d/12YaBonkqHAjkXhzyKlH2-1t-smZ6J5j76RCBSJEwQHo/edit?usp=sharing"
1213

1314
# Read data from Google Sheets
1415

@@ -24,30 +25,37 @@ voting_info_2022 <- read_sheet(url_2022, sheet = 2) |>
2425
presvotes_total = Total
2526
)
2627

27-
region_2022 <- read_sheet(url_geo_118, sheet = 1) |>
28+
region_2022 <- read_sheet(url_geo_118, sheet = "Descriptive name") |>
2829
select(cd = CD,
2930
dailykos_name = `Geographic Description`)
3031

31-
largest_place_2022 <- read_sheet(url_geo_118, sheet = 2) |>
32+
largest_place_2022 <- read_sheet(url_geo_118, sheet = "By places") |>
3233
select(cd = CD,
3334
largest_place = `Largest place`)
3435

3536
# 2024
36-
cd_names_2024 <- read_sheet(url_2024, sheet = 1) |>
37-
mutate(year = 2024) |>
38-
select(year, cd = District)
37+
# clean sheet
38+
sheet_2024 <- read_sheet(url_2024, sheet = "Vote totals") |>
39+
select(1:9) |>
40+
row_to_names(row_number = 2, remove_row = TRUE) |>
41+
select(cd = 1, Harris, Trump, Total)
3942

40-
voting_info_2024 <- read_sheet(url_2024, sheet = 2) |>
41-
transmute(cd = District,
42-
pct_trump20 = Trump / (Biden + Trump),
43-
presvotes_DR_20 = Biden + Trump,
44-
presvotes_total_20 = Total)
43+
cd_names_2024 <- sheet_2024 |>
44+
transmute(year = 2024, cd)
45+
46+
voting_info_2024 <- sheet_2024 |>
47+
mutate(across(where(is.list) & !matches("^cd$"),
48+
~ map_dbl(.x, ~ as.numeric(.x[1])))) |>
49+
transmute(cd,
50+
pct_trump = Trump / (Harris + Trump),
51+
presvotes_DR = Harris + Trump,
52+
presvotes_total = Total)
4553

46-
region_2024 <- read_sheet(url_geo_119, sheet = 1) |>
54+
region_2024 <- read_sheet(url_geo_119, sheet = "Descriptive name") |>
4755
select(cd = CD,
4856
dailykos_name = `Geographic Description`)
4957

50-
largest_place_2024 <- read_sheet(url_geo_119, sheet = 2) |>
58+
largest_place_2024 <- read_sheet(url_geo_119, sheet = "By places") |>
5159
select(cd = CD,
5260
largest_place = `Largest place`)
5361

data/cd_info_2022.rda

1 Byte
Binary file not shown.

data/cd_info_2024.rda

-3.16 KB
Binary file not shown.

man/cc18_samp.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)