Skip to content
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

Use proper tidyselect tidyselections in epi_slide_opt, or don't call tidyselection #435

Open
brookslogan opened this issue Apr 9, 2024 · 0 comments
Assignees

Comments

@brookslogan
Copy link
Contributor

brookslogan commented Apr 9, 2024

We currently use a limited form of tidyselection, so something like this goes awry in a weird way:

library(epiprocess)
#> 
#> Attaching package: 'epiprocess'
#> The following object is masked from 'package:stats':
#> 
#>     filter
jhu_csse_daily_subset %>% group_by(geo_value) %>% epi_slide_mean(before = 6L, where(is.numeric))
#> Error in `.data_group[, col_names_chr]` at epiprocess/R/slide.R:751:7:
#> ! Can't subset columns that don't exist.
#> ✖ Columns `where` and `is.numeric` don't exist.
#> Backtrace:
#>      ▆
#>   1. ├─jhu_csse_daily_subset %>% group_by(geo_value) %>% ...
#>   2. ├─epiprocess::epi_slide_mean(., before = 6L, where(is.numeric))
#>   3. │ └─epiprocess::epi_slide_opt(...) at epiprocess/R/slide.R:863:3
#>   4. │   └─mutate(x, .real = TRUE) %>% ... at epiprocess/R/slide.R:776:3
#>   5. ├─dplyr::group_modify(., slide_one_grp, ..., .keep = FALSE)
#>   6. ├─epiprocess:::group_modify.epi_df(., slide_one_grp, ..., .keep = FALSE) at dplyr/R/group-map.R:156:3
#>   7. │ └─dplyr::dplyr_reconstruct(NextMethod(), .data) at epiprocess/R/methods-epi_df.R:231:3
#>   8. │   └─dplyr:::dplyr_new_data_frame(data) at dplyr/R/generics.R:196:3
#>   9. │     ├─row.names %||% .row_names_info(x, type = 0L) at dplyr/R/utils.R:18:3
#>  10. │     └─base::.row_names_info(x, type = 0L) at dplyr/R/utils.R:18:3
#>  11. ├─base::NextMethod() at epiprocess/R/methods-epi_df.R:231:3
#>  12. ├─dplyr:::group_modify.grouped_df(., slide_one_grp, ..., .keep = FALSE)
#>  13. │ ├─dplyr::group_map(.data, fun, .keep = .keep) at dplyr/R/group-map.R:193:3
#>  14. │ └─dplyr:::group_map.data.frame(.data, fun, .keep = .keep) at dplyr/R/group-map.R:124:3
#>  15. │   └─dplyr:::map2(chunks, group_keys, .f, ...) at dplyr/R/group-map.R:145:5
#>  16. │     └─base::mapply(.f, .x, .y, MoreArgs = list(...), SIMPLIFY = FALSE) at dplyr/R/import-standalone-purrr.R:66:3
#>  17. │       └─dplyr (local) `<fn>`(dots[[1L]][[1L]], dots[[2L]][[1L]])
#>  18. │         └─epiprocess (local) .f(.x, .y, ...) at dplyr/R/group-map.R:180:5
#>  19. │           ├─data.table (local) f(...) at epiprocess/R/slide.R:751:7
#>  20. │           │ └─data.table:::froll(...)
#>  21. │           ├─.data_group[, col_names_chr] at epiprocess/R/slide.R:751:7
#>  22. │           └─tibble:::`[.tbl_df`(.data_group, , col_names_chr) at epiprocess/R/slide.R:751:7
#>  23. │             └─tibble:::vectbl_as_col_location(...)
#>  24. │               ├─tibble:::subclass_col_index_errors(...)
#>  25. │               │ └─base::withCallingHandlers(...)
#>  26. │               └─vctrs::vec_as_location(j, n, names, missing = "error", call = call)
#>  27. └─vctrs (local) `<fn>`() at vctrs/R/subscript-loc.R:80:3
#>  28.   └─vctrs:::stop_subscript_oob(...)
#>  29.     └─vctrs:::stop_subscript(...) at vctrs/R/subscript-loc.R:481:3
#>  30.       └─rlang::abort(...) at vctrs/R/subscript.R:144:3

Created on 2024-04-09 with reprex v2.0.2

We should consider proper {tidyselect}-based tidyselections, probably based on tidyselect::eval_select(<look at docs>, allow_rename = FALSE) unless we want to allow "renaming" to do something, and either

  • use them, update roxygen to follow tidyverse/roxygen's way of marking tidyselection args (example here), [update arg forwarding from epi_slide_mean if needed -- {{ }} might be needed] add a test using tidyselect features --- maybe based on the above failing example; or
  • don't call what we do tidyselection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants