Skip to content

Commit e849605

Browse files
coderabbit suggestions
1 parent 4e54cae commit e849605

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ Imports:
4646
future,
4747
future.callr,
4848
patchwork,
49-
purrr
49+
purrr,
50+
ggh4x,
51+
gridExtra)
5052
Suggests:
5153
bookdown,
5254
targets,

R/plot_figures.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,16 @@ plot_multilocation_comparison <- function(
8686
output_path,
8787
forecast_dates,
8888
locations = NULL,
89-
hosp_data_long,
9089
forecast_horizon_to_plot = 28,
9190
historical_data_to_plot = 90,
9291
scale_selected = "natural",
9392
save_path = NULL,
9493
show_multiple_dates = TRUE) {
94+
# Validate inputs
95+
if (length(forecast_dates) == 0) {
96+
stop("forecast_dates must not be empty")
97+
}
98+
9599
# If show_multiple_dates is FALSE, randomly select one forecast date
96100
if (!show_multiple_dates) {
97101
# Filter to 2024 dates if available

targets/multilocation_plot_targets.R

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,46 @@ multilocation_plot_targets <- list(
1313
# (e.g., first, middle, and last forecast date)
1414
# Only select dates that actually have complete forecast data
1515
tar_target(
16-
name = selected_forecast_dates_multiloc,
17-
command = {
18-
dates <- unique(scores$forecast_date)
19-
dates <- sort(dates)
20-
21-
# Filter to only dates with complete data
22-
valid_dates <- c()
23-
test_loc <- available_locations_multiloc[1]
24-
for (test_date in dates) {
25-
date_str <- as.character(as.Date(test_date, origin = "1970-01-01"))
26-
test_path <- file.path(
27-
output_path_multiloc,
28-
"individual_forecasts_all_runs",
29-
date_str,
30-
test_loc,
31-
"data",
32-
"hosp_quantiles_ww_TRUE.csv"
33-
)
34-
if (file.exists(test_path)) {
35-
valid_dates <- c(valid_dates, date_str)
36-
}
16+
name = selected_forecast_dates_multiloc,
17+
command = {
18+
+ test_loc <- available_locations_multiloc[1]
19+
dates <- unique(scores$forecast_date)
20+
dates <- sort(dates)
21+
22+
# Filter to only dates with complete data
23+
valid_dates <- c()
24+
test_loc <- available_locations_multiloc[1]
25+
for (test_date in dates) {
26+
date_str <- as.character(as.Date(test_date, origin = "1970-01-01"))
27+
test_path <- file.path(
28+
output_path_multiloc,
29+
"individual_forecasts_all_runs",
30+
date_str,
31+
test_loc,
32+
"data",
33+
"hosp_quantiles_ww_TRUE.csv"
34+
)
35+
if (file.exists(test_path)) {
36+
valid_dates <- c(valid_dates, date_str)
37+
}
38+
}
39+
date_strs <- as.character(as.Date(dates, origin = "1970-01-01"))
40+
valid_dates <- date_strs[vapply(date_strs, function(date_str) {
41+
test_path <- file.path(
42+
output_path_multiloc,
43+
"individual_forecasts_all_runs",
44+
date_str,
45+
test_loc,
46+
"data",
47+
"hosp_quantiles_ww_TRUE.csv"
48+
)
49+
file.exists(test_path)
50+
}, logical(1))]
51+
52+
# Return every other valid date for clarity
53+
valid_dates[seq(1, length(valid_dates), by = 2)]
3754
}
38-
39-
# Return every other valid date for clarity
40-
valid_dates[seq(1, length(valid_dates), by = 2)]
41-
}
42-
),
55+
),
4356
# Get available locations from scores
4457
tar_target(
4558
name = available_locations_multiloc,

0 commit comments

Comments
 (0)