Skip to content

Commit 4c09e99

Browse files
committed
fix: target_param_grids bug
1 parent a3b16ef commit 4c09e99

File tree

5 files changed

+35
-52
lines changed

5 files changed

+35
-52
lines changed

R/targets_utils.R

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @export
77
#' @importFrom rlang syms
88
make_target_param_grid <- function(param_grid) {
9-
param_grid %>%
9+
param_grid %<>%
1010
select(-any_of("parent_id")) %>%
1111
mutate(forecaster = syms(forecaster)) %>%
1212
mutate(trainer = syms(trainer))
@@ -25,7 +25,7 @@ make_target_param_grid <- function(param_grid) {
2525
lists_of_real_values <- function(param_grid) {
2626
full_lists <- transpose(param_grid %>% select(-forecaster, -id))
2727
filter_nonvalues <- function(x) {
28-
Filter(Negate(function(a) is.null(a) || is.na(a)), x)
28+
Filter(function(a) !all(is.null(a)) && !all(is.na(a)), x)
2929
}
3030
map(full_lists, filter_nonvalues)
3131
}
@@ -35,11 +35,6 @@ lists_of_real_values <- function(param_grid) {
3535
#' Relies on the following globals:
3636
#' - `hhs_signal`
3737
#' - `chng_signal`
38-
#' - `geo_type`
39-
#' - `time_type`
40-
#' - `geo_values`
41-
#' - `time_values`
42-
#' - `issues`
4338
#' - `fetch_args`
4439
#'
4540
#' @export
@@ -51,10 +46,10 @@ make_data_targets <- function() {
5146
epidatr::pub_covidcast(
5247
source = "hhs",
5348
signals = hhs_signal,
54-
geo_type = geo_type,
55-
time_type = time_type,
56-
geo_values = geo_values,
57-
time_values = time_values,
49+
geo_type = "state",
50+
time_type = "day",
51+
geo_values = "*",
52+
time_values = epirange(from = "2020-01-01", to = "2024-01-01"),
5853
fetch_args = fetch_args
5954
)
6055
}
@@ -65,10 +60,10 @@ make_data_targets <- function() {
6560
epidatr::pub_covidcast(
6661
source = "chng",
6762
signals = chng_signal,
68-
geo_type = geo_type,
69-
time_type = time_type,
70-
geo_values = geo_values,
71-
time_values = time_values,
63+
geo_type = "state",
64+
time_type = "day",
65+
geo_values = "*",
66+
time_values = epirange(from = "2020-01-01", to = "2024-01-01"),
7267
fetch_args = fetch_args
7368
)
7469
}
@@ -86,15 +81,13 @@ make_data_targets <- function() {
8681
tar_target(
8782
name = hhs_latest_data_2022,
8883
command = {
89-
hhs_latest_data %>%
90-
filter(time_value >= "2022-01-01")
84+
hhs_latest_data # %>% filter(time_value >= "2022-01-01", time_value < "2022-04-01")
9185
}
9286
),
9387
tar_target(
9488
name = chng_latest_data_2022,
9589
command = {
96-
chng_latest_data %>%
97-
filter(time_value >= "2022-01-01")
90+
chng_latest_data # %>% filter(time_value >= "2022-01-01", time_value < "2022-04-01")
9891
}
9992
),
10093
tar_target(
@@ -103,11 +96,11 @@ make_data_targets <- function() {
10396
epidatr::pub_covidcast(
10497
source = "hhs",
10598
signals = hhs_signal,
106-
geo_type = geo_type,
107-
time_type = time_type,
108-
geo_values = geo_values,
109-
time_values = time_values,
110-
issues = issues,
99+
geo_type = "state",
100+
time_type = "day",
101+
geo_values = "*",
102+
time_values = epirange(from = "20220101", to = "20220401"),
103+
issues = "*",
111104
fetch_args = fetch_args
112105
)
113106
}
@@ -118,11 +111,11 @@ make_data_targets <- function() {
118111
epidatr::pub_covidcast(
119112
source = "chng",
120113
signals = chng_signal,
121-
geo_type = geo_type,
122-
time_type = time_type,
123-
geo_values = geo_values,
124-
time_values = time_values,
125-
issues = issues,
114+
geo_type = "state",
115+
time_type = "day",
116+
geo_values = "*",
117+
time_values = epirange(from = "20220101", to = "20220401"),
118+
issues = "*",
126119
fetch_args = fetch_args
127120
)
128121
}
@@ -135,17 +128,17 @@ make_data_targets <- function() {
135128
rename("hhs" := value) %>%
136129
rename(version = issue) %>%
137130
as_epi_archive(
138-
geo_type = geo_type,
139-
time_type = time_type,
131+
geo_type = "state",
132+
time_type = "day",
140133
compactify = TRUE
141134
)
142135
chng_archive_data_2022 %<>%
143136
select(geo_value, time_value, value, issue) %>%
144137
rename("chng" := value) %>%
145138
rename(version = issue) %>%
146139
as_epi_archive(
147-
geo_type = geo_type,
148-
time_type = time_type,
140+
geo_type = "state",
141+
time_type = "day",
149142
compactify = TRUE
150143
)
151144
epix_merge(hhs_archive_data_2022, chng_archive_data_2022, sync = "locf")$DT %>%

covid_hosp_explore.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ forecaster_params_grid_target <- list(
5555
# during the actual targets run, since the commands are frozen as expressions).
5656
hhs_signal <- "confirmed_admissions_covid_1d"
5757
chng_signal <- "smoothed_adj_outpatient_covid"
58-
geo_type <- "state"
59-
time_type <- "day"
60-
geo_values <- "*"
61-
time_values <- epidatr::epirange(from = "2020-01-01", to = "2024-01-01")
62-
issues <- "*"
6358
fetch_args <- epidatr::fetch_args_list(return_empty = TRUE, timeout_seconds = 200)
6459
data_targets <- make_data_targets()
6560

flu_hosp_explore.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ forecaster_params_grid_target <- list(
4040
# during the actual targets run, since the commands are frozen as expressions).
4141
hhs_signal <- "confirmed_admissions_influenza_1d_prop_7dav"
4242
chng_signal <- "smoothed_adj_outpatient_flu"
43-
geo_type <- "state"
44-
time_type <- "day"
45-
geo_values <- "*"
46-
time_values <- epidatr::epirange(from = "2022-01-01", to = "2024-01-01")
47-
issues <- "*"
48-
fetch_args <- epidatr::fetch_args_list(return_empty = TRUE, timeout_seconds = 200)
43+
fetch_args <- epidatr::fetch_args_list(return_empty = TRUE, timeout_seconds = 300)
4944
data_targets <- make_data_targets()
5045

5146

run.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Input: ")
5656
stop("selection `", project_selection, "` is invalid")
5757
)
5858
} else {
59-
cat("Using project ", tar_project, "\n")
59+
cat("Using project: ", tar_project, "\n")
6060
}
6161
Sys.setenv(TAR_PROJECT = tar_project)
6262

tests/testthat/test-target-utils.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
test_that("target param generation works", {
22
ex_frame <- tribble(
3-
~forecaster, ~id, ~someNAs, ~someNULLs,
4-
"scaled_pop", "linreg", TRUE, 35,
5-
"scaled_pop", "linreg", NA, 35,
6-
"scaled_pop", "linreg", FALSE, NULL,
3+
~forecaster, ~id, ~someNAs, ~someNULLs, ~someList, ~someYoDog,
4+
"scaled_pop", "linreg", TRUE, 35, c(1, 3, 5), list(c(1, 2), c(3, 4)),
5+
"scaled_pop", "linreg", NA, 35, c(1, 3, 5), list(c(1, 2), c(3, 4)),
6+
"scaled_pop", "linreg", FALSE, NULL, c(1, 3, 5), list(c(1, 2), c(3, 4))
77
)
88
list_version <- list(
9-
list(someNAs = TRUE, someNULLs = 35),
10-
list(someNULLs = 35),
11-
list(someNAs = FALSE)
9+
list(someNAs = TRUE, someNULLs = 35, someList = c(1, 3, 5), someYoDog = list(c(1, 2), c(3, 4))),
10+
list(someNULLs = 35, someList = c(1, 3, 5), someYoDog = list(c(1, 2), c(3, 4))),
11+
list(someNAs = FALSE, someList = c(1, 3, 5), someYoDog = list(c(1, 2), c(3, 4)))
1212
)
1313
expect_equal(lists_of_real_values(ex_frame), list_version)
1414
})

0 commit comments

Comments
 (0)