-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Labels
P0high priorityhigh priorityREPLImproved print, errors, etc.Improved print, errors, etc.good first issueGood for newcomersGood for newcomers
Description
When the user inputs ref_time_values
before or after the time_value
s in the epi_df
(even if there'd be data in the window), it gives a hard-to-understand error message:
Error: Can't subset columns that don't exist.
✖ Column `slide_value` doesn't exist.
Run `rlang::last_error()` to see where the error occurred.
We should instead detect this case and output an understandable error message.
Examples:
edf = bind_rows(
tibble(geo_value = "ak", time_value = as.Date("2020-01-01") + 1:200, value=1:200),
tibble(geo_value = "al", time_value=as.Date("2020-01-01") + 1:5, value=-(1:5))
) %>%
as_epi_df()
f = function(x, ...) tibble(value=mean(x$value), count=length(x$value))
## --- These cases generate the error: ---
## `ref_time_values` + `align` that result in no slide data, generate the error:
edf %>% group_by(geo_value) %>% epi_slide(f, n=3L, ref_time_values=as.Date("2020-01-01")) # before the first, no data in the slide windows
edf %>% group_by(geo_value) %>% epi_slide(f, n=3L, ref_time_values=as.Date("2020-01-01")+207L) # beyond the last, no data in window
## `ref_time_values` + `align` that should? have slide data, but generate the error:
edf %>% group_by(geo_value) %>% epi_slide(f, n=3L, ref_time_values=as.Date("2020-01-01"), align="left") # before the first, but we'd expect there to be data in the window
edf %>% group_by(geo_value) %>% epi_slide(f, n=3L, ref_time_values=as.Date("2020-01-01")+201L) # beyond the last, but still with data in window
## --- This case doesn't generate the error: ---
## (this doesn't produce an error; the error appears only if the ref time values are out of the range for every group:)
edf %>% group_by(geo_value) %>% epi_slide(f, n=3L, ref_time_values=as.Date("2020-01-01")+200L)
Metadata
Metadata
Assignees
Labels
P0high priorityhigh priorityREPLImproved print, errors, etc.Improved print, errors, etc.good first issueGood for newcomersGood for newcomers