Skip to content

Improve epi_slide error messaging on bad ref_time_values #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brookslogan opened this issue Apr 5, 2022 · 0 comments · Fixed by #85
Closed

Improve epi_slide error messaging on bad ref_time_values #65

brookslogan opened this issue Apr 5, 2022 · 0 comments · Fixed by #85
Assignees
Labels
good first issue Good for newcomers P0 high priority REPL Improved print, errors, etc.

Comments

@brookslogan
Copy link
Contributor

When the user inputs ref_time_values before or after the time_values 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)
@brookslogan brookslogan added the good first issue Good for newcomers label Apr 13, 2022
rachlobay pushed a commit to dajmcdon/epiprocess that referenced this issue May 12, 2022
Merge branch 'main' into epi_slide-error_message

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
@brookslogan brookslogan added REPL Improved print, errors, etc. P0 high priority labels May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers P0 high priority REPL Improved print, errors, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants