Skip to content

Commit bf5951b

Browse files
committed
fix some missing stuff
1 parent 7c2ce25 commit bf5951b

File tree

8 files changed

+69
-27
lines changed

8 files changed

+69
-27
lines changed

CRAN-RELEASE

Lines changed: 0 additions & 2 deletions
This file was deleted.

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: parlitools
22
Type: Package
33
Title: Tools for Analysing UK Politics
4-
Version: 0.4.0
4+
Version: 0.4.1
55
Authors@R: person(
66
"Evan Odell", email="evanodell91@gmail.com",
77
role=c("aut", "cre"), comment = c(ORCID = '0000-0003-1845-808X'))

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# parlitools 0.4.1
2+
3+
* Fixed some missing 2017 results from `bes_2019` data, spotted by Antony Unwin.
4+
15
# parlitools 0.4.0
26

37
* Added 2019 UK General Election Results

cran-comments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Resubmission
44

5-
This is a resubmission of the `parlitools` package, with new data on the 2019
6-
UK General Election as well as some minor vignette improvements.
5+
This is a resubmission of the `parlitools` package, which fixes missing data
6+
spotted in the previous version after it was submitted to CRAN.
77

88
## Test environments
99

data-raw/bes-data-prep.R

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ usethis::use_data(bes_2017, overwrite = TRUE)
105105

106106
library(stringr)
107107
library(stringi)
108+
library(readr)
109+
library(dplyr)
110+
library(tidyr)
108111

109112
#https://candidates.democracyclub.org.uk/api/docs/csv/#past
110113
candidates <- read_csv("data-raw/candidates-parl.2019-12-12.csv") %>%
@@ -177,7 +180,7 @@ names(candidates2) <- str_replace_all(names(candidates2),
177180
# results
178181

179182
# from: https://researchbriefings.parliament.uk/ResearchBriefing/Summary/CBP-8749
180-
bes_2019 <- read_csv("./data-raw/HoC-GE2019-results-by-constituency.csv") %>%
183+
bes_2019_full <- read_csv("./data-raw/HoC-GE2019-results-by-constituency.csv") %>%
181184
select(-declaration_time, -mp_firstname, -mp_gender, -mp_surname,
182185
-second_party) %>%
183186
rename("ons_const_id" = ons_id,
@@ -207,18 +210,18 @@ bes_2019 <- read_csv("./data-raw/HoC-GE2019-results-by-constituency.csv") %>%
207210
"Alliance" = "Alliance",
208211
"UUP" = "Ulster Unionist Party"))
209212

210-
bes_2019 <- bes_2019 %>%
213+
bes_2019_full <- bes_2019_full %>%
211214
rename_at(vars(con:speaker), ~paste0(., "_vote_19"))
212215

213-
bes_2019 <- bes_2019 %>%
216+
bes_2019_full <- bes_2019_full %>%
214217
mutate_at(list(perc = ~./total_vote_19),
215218
.vars = vars(con_vote_19:speaker_vote_19)) %>%
216219
mutate_at(vars(con_vote_19_perc:speaker_vote_19_perc), ~.*100)
217220

218-
names(bes_2019) <- str_replace_all(names(bes_2019),
221+
names(bes_2019_full) <- str_replace_all(names(bes_2019_full),
219222
"(.*)_vote_19_perc", "\\1_19")
220223

221-
bes_2019 <- bes_2019 %>%
224+
bes_2019_full <- bes_2019_full %>%
222225
mutate(seat_change_1719 = ifelse(
223226
substr(seat_change_1719, nchar(seat_change_1719)-4,
224227
nchar(seat_change_1719)) == " hold",
@@ -232,28 +235,60 @@ bes_2019 <- bes_2019 %>%
232235
"Democratic Unionist Party"),
233236
vectorize_all = FALSE ))
234237

238+
bes_2017 <- parlitools::bes_2017 %>%
239+
select(pano:ons_const_id, winner_17:electorate_17,
240+
leave_hanretty, remain_hanretty)
241+
242+
bes_2019_gb <- bes_2019_full %>% filter(region != "Northern Ireland")
243+
244+
bes_2019_gb <- inner_join(bes_2019_gb,
245+
bes_2017)
246+
247+
248+
249+
250+
ni_ge_2017 <- parlitools::ni_ge_2017
251+
252+
ni_ge_2017 <- ni_ge_2017 %>% select(pano, ons_const_id, electorate_17:con_17)
253+
254+
leave_votes_west <- parlitools::leave_votes_west %>%
255+
mutate(leave_hanretty = figure_to_use*100) %>%
256+
select(ons_const_id, leave_hanretty)
257+
258+
ni_ge_2017 <- ni_ge_2017 %>%
259+
inner_join(leave_votes_west) %>%
260+
mutate(remain_hanretty = 100-leave_hanretty) %>%
261+
rename(total_vote_17 = total_votes_17)
262+
263+
x4 <- bes_2019_full %>%
264+
inner_join(ni_ge_2017)
235265

236-
bes_2019 <- left_join(bes_2019,
237-
bes_2017 %>% select(pano:electorate_17,
238-
leave_hanretty, remain_hanretty))
266+
bes_2019 <- bind_rows(bes_2019_gb, x4)
239267

240268
bes_2019 <- bes_2019 %>%
241269
mutate(con_1719 = con_19 - con_17,
242270
lab_1719 = lab_19 - lab_17,
243271
ld_1719 = ld_19 - ld_17 ,
244272
green_1719 = green_19 - green_17 ,
245273
snp_1719 = snp_19 - snp_17,
246-
pc_1719 = pc_19 - pc_17)
274+
pc_1719 = pc_19 - pc_17,
275+
uup_1719 = uup_19 - uup_17,
276+
dup_1719 = dup_19 - dup_17,
277+
alliance_1719 = alliance_19 - alliance_17,
278+
sf_1719 = sf_19 - sf_17,
279+
sdlp_1719 = sdlp_19 - sdlp_17
280+
)
247281

248282

249283
glimpse(bes_2019)
250284

251-
bes_2019 <- bes_2019 %>% select(pano, ons_const_id:speaker_19, con_1719:pc_1719,
252-
winner_17:electorate_17, leave_hanretty,
253-
remain_hanretty)
285+
# bes_2019 <- bes_2019 %>% select(pano, ons_const_id:speaker_19, con_1719:pc_1719,
286+
# winner_17:electorate_17, leave_hanretty,
287+
# remain_hanretty)
254288

255289
bes_2019 <- bes_2019 %>% left_join(candidates2)
256290

291+
bes_2019[bes_2019==0] <- NA
257292

258293
usethis::use_data(bes_2019, overwrite = TRUE)
259294

data-raw/ni-data-prep.R

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ ge_2017 <- ge_2017 %>% filter(str_detect(ons_code, "N")) %>%
5555
select(ons_code, pano, constituency, party_identifer, valid_votes) %>%
5656
spread(party_identifer, valid_votes) %>%
5757
mutate(total_votes_17 = select(., Alliance:WP) %>% rowSums(na.rm = TRUE),
58-
other_vote_17 = select(., `CIST Alliance`, Conservative, Independent,
58+
other_vote_17 = select(., `CIST Alliance`, Independent,
5959
`Independent (Lady Hermon)`, `PBP Alliance`,
6060
TUV, WP) %>% rowSums(na.rm = TRUE)) %>%
6161
rename(alliance_vote_17 = Alliance,
6262
dup_vote_17 = DUP,
6363
green_vote_17 = `Green Party`,
6464
sf_vote_17 = `Sinn Féin`,
6565
sdlp_vote_17 = `SDLP`,
66-
uup_vote_17 = `UUP`) %>%
67-
select(-`CIST Alliance`, -Conservative, -Independent,
66+
uup_vote_17 = `UUP`,
67+
con_vote_17 = `Conservative`) %>%
68+
select(-`CIST Alliance`, -Independent,
6869
-`Independent (Lady Hermon)`, -`PBP Alliance`,
6970
-TUV, -WP)
7071

@@ -85,6 +86,7 @@ ge_2017 <- ge_2017 %>%
8586
sf_17 = (sf_vote_17/total_votes_17)*100,
8687
sdlp_17 = (sdlp_vote_17/total_votes_17)*100,
8788
uup_17 = (uup_vote_17/total_votes_17)*100,
89+
con_17 = (con_vote_17/total_votes_17)*100,
8890
other_17 = (other_vote_17/total_votes_17)*100,
8991
ukip_17 = NA,
9092
turnout_17 = (total_votes_17/electorate_17)*100)
@@ -148,7 +150,7 @@ results_15 <- results_15 %>% filter(str_detect(ons_code, "N")) %>%
148150
spread(party_identifier, valid_votes) %>%
149151
mutate(total_votes_15 = select(., Alliance:`Workers Party`) %>% rowSums(na.rm = TRUE),
150152
other_vote_15 = select(., `Cannabis is Safer than Alcohol Party`,
151-
Conservative, Independent,
153+
Independent,
152154
`People Before Profit Alliance`,
153155
`Traditional Unionist Voice`,
154156
`Workers Party`) %>% rowSums(na.rm = TRUE)) %>%
@@ -158,8 +160,9 @@ results_15 <- results_15 %>% filter(str_detect(ons_code, "N")) %>%
158160
sf_vote_15 = `Sinn Fein`,
159161
sdlp_vote_15 = `Social Democratic and Labour Party`,
160162
uup_vote_15 = `Ulster Unionist Party`,
161-
ukip_vote_15 = `UK Independence Party`) %>%
162-
select(-`Cannabis is Safer than Alcohol Party`, -Conservative,
163+
ukip_vote_15 = `UK Independence Party`,
164+
con_vote_15 = `Conservative`) %>%
165+
select(-`Cannabis is Safer than Alcohol Party`,
163166
-`People Before Profit Alliance`, -`Traditional Unionist Voice`,
164167
-Independent, -`Workers Party`)
165168

@@ -173,6 +176,7 @@ results_15 <- results_15 %>%
173176
sf_15 = (sf_vote_15/total_votes_15)*100,
174177
sdlp_15 = (sdlp_vote_15/total_votes_15)*100,
175178
uup_15 = (uup_vote_15/total_votes_15)*100,
179+
con_15 = (con_vote_15/total_votes_15)*100,
176180
turnout_15 = (total_votes_15/electorate_15)*100)
177181

178182
glimpse(results_15)
@@ -189,6 +193,7 @@ ni_results <- ni_results %>%
189193
sf_1517 = sf_17 - sf_15,
190194
sdlp_1517 = sdlp_17 - sdlp_15,
191195
uup_1517 = uup_17 - uup_15,
196+
con_1517 = con_17 - con_15,
192197
winner_17 = recode(
193198
winner_17,
194199
"Democratic Unionist Party - D.U.P." = "Democratic Unionist Party",
@@ -218,12 +223,12 @@ ni_results <- ni_results %>% select(ons_code, pano, constituency,
218223
majority_15, majority_vote_15,
219224
"alliance_vote_15", "dup_vote_15",
220225
"green_vote_15", sf_vote_15, "sdlp_vote_15",
221-
"ukip_vote_15", "uup_vote_15",
226+
"ukip_vote_15", "uup_vote_15", con_vote_15,
222227
"other_vote_15", "alliance_15", "dup_15",
223228
"green_15", "sf_15", "sdlp_15", "uup_15",
224-
electorate_17, total_votes_17, turnout_17,
225-
winner_17, majority_17, majority_vote_17,
226-
everything()) %>%
229+
con_15, electorate_17, total_votes_17,
230+
turnout_17, winner_17, majority_17,
231+
majority_vote_17, everything()) %>%
227232
rename(ons_const_id = ons_code,
228233
constituency_name = constituency)
229234

data/bes_2019.rda

9.54 KB
Binary file not shown.

data/ni_ge_2017.rda

163 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)