-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_all_data.R
114 lines (92 loc) · 3.26 KB
/
get_all_data.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#' Pull all covid19india count, test, and vaccine data for states and nation
#' @param keep_nat Keep the national data as well. Default is `FALSE`
#' @param covind19_name_scheme Variable naming scheme used for development of [`covind19.org`](https://umich-biostatistics.shinyapps.io/covid19/) application
#' @param corr_check Check for data corrections of X-times magnitude. Default is `TRUE`
#' @param mohfw mohfw switch to mohfw. Defauly is `FALSE` - will default to `TRUE` in future
#' @param inc_days Number of days from infection to symptoms
#' @return Pulls the district-level time-series case, death, and recovered data directly from [`covid19india.org`](https://www.covid19india.org).
#' @import data.table
#' @importFrom cli cli_alert_warning
#' @importFrom janitor clean_names
#' @importFrom utils head
#' @export
#' @examples
#' \dontrun{
#' get_all_data()
#' }
get_all_data <- function(
keep_nat = TRUE,
covind19_name_scheme = FALSE,
corr_check = TRUE,
mohfw = TRUE,
inc_days = c(7, 5, 3)
) {
if (mohfw == FALSE) {
d <- data.table::merge.data.table(
data.table::rbindlist(list(
get_nat_counts(),
get_state_counts()
), fill = TRUE),
data.table::rbindlist(list(
get_nat_tests(),
get_state_tests()
), fill = TRUE),
by = c("place", "date"),
all.x = TRUE
)
d <- data.table::merge.data.table(
d,
get_r0(dat = d, corr_check = FALSE, inc_days = inc_days)[, .(place, date, r_est = r, r_lower = lower, r_upper = upper)],
by = c("place", "date"),
all.x = TRUE
)
d <- data.table::merge.data.table(
d,
unique(covid19india::pop[, .(place, abbrev)][, utils::head(.SD, 1), by = "place"]),
by = "place",
all.x = TRUE
)
d <- data.table::merge.data.table(
d[, tpr := daily_cases / daily_tests],
base::suppressMessages(get_state_vax()),
by = c("place", "date"),
all.x = TRUE
)
}
if (mohfw == TRUE) {
d <- data.table::rbindlist(list(
get_nat_counts(mohfw = TRUE),
get_state_counts(mohfw = TRUE)
), fill = TRUE)
d <- data.table::merge.data.table(
d,
get_r0(dat = d, corr_check = FALSE, inc_days = inc_days)[, .(place, date, r_est = r, r_lower = lower, r_upper = upper)],
by = c("place", "date"),
all.x = TRUE
)
d <- data.table::merge.data.table(
d,
unique(covid19india::pop[, .(place, abbrev)][, utils::head(.SD, 1), by = "place"]),
by = "place",
all.x = TRUE
)
d <- data.table::merge.data.table(
d,
base::suppressMessages(get_state_vax(mohfw = TRUE)[, !c("source")]),
by = c("place", "date"),
all.x = TRUE
)
}
if (keep_nat == FALSE) {
d <- d[place != "India"]
}
# suppressWarnings({ d <- d[!(place %in% c("Haryana***", "Kerala***"))] })
if (covind19_name_scheme == TRUE) {
cli::cli_alert_warning("{covid19india} variable naming scheme is encouraged (`covind19_naming_scheme == FALSE`)")
setnames(d,
old = c("daily_cases", "daily_recovered", "daily_deaths", "total_doses", "pct_one_doses",
"pct_two_doses", "daily_doses"),
new = c("cases", "recovered", "deaths", "total_vacc", "pct_at_least_one", "pct_second", "daily_vax_dose"))
}
return(d)
}