-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils-mp-questions.R
59 lines (40 loc) · 1.35 KB
/
utils-mp-questions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# mp_question multi function ----------------------------------------------
mp_question_multi <- function(mp_id, question_type, start_date,
end_date, extra_args, verbose) {
mp_id_list <- as.list(mp_id)
dat <- vector("list", length(mp_id_list))
seq_list <- seq(from = 1, to = length(mp_id_list), by = 1)
for (i in seq_along(seq_list)) {
dat[[i]] <- hansard::mp_questions(
mp_id = mp_id_list[[i]],
question_type = question_type,
end_date = end_date,
start_date = start_date,
extra_args = extra_args,
verbose = verbose,
tidy = FALSE,
tidy_style = "snake"
)
}
dat <- dat[sapply(dat, function(d) !is.null(d))]
df <- dplyr::bind_rows(dat)
names(df)[names(df) == "_about"] <- "about"
df
}
## MP question tidying
mp_question_tidy <- function(df, tidy_style) {
if (nrow(df) > 0) {
df$dateTabled._value <- as.POSIXct(df$dateTabled._value)
df$AnswerDate._value <- as.POSIXct(df$AnswerDate._value)
df$AnswerDate._datatype <- "POSIXct"
df$dateTabled._datatype <- "POSIXct"
df$tablingMemberPrinted <- unlist(df$tablingMemberPrinted)
df$AnsweringBody <- unlist(df$AnsweringBody)
df$tablingMember._about <- gsub(
"http://data.parliament.uk/members/", "",
df$tablingMember._about
)
}
df <- hansard_tidy(df, tidy_style)
df
}