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

Make epi_slide_opt work with !!varname, maybe !!varnames, maybe !!!varnames #562

Open
brookslogan opened this issue Nov 3, 2024 · 0 comments · May be fixed by #564
Open

Make epi_slide_opt work with !!varname, maybe !!varnames, maybe !!!varnames #562

brookslogan opened this issue Nov 3, 2024 · 0 comments · May be fixed by #564
Assignees

Comments

@brookslogan
Copy link
Contributor

brookslogan commented Nov 3, 2024

library(epiprocess)
#> Registered S3 method overwritten by 'tsibble':
#>   method               from 
#>   as_tibble.grouped_df dplyr
#> 
#> Attaching package: 'epiprocess'
#> The following object is masked from 'package:stats':
#> 
#>     filter
varname <- "case_rate"
varnames <- c("case_rate", "death_rate")
covid_case_death_rates_extended %>% epi_slide_sum(!!varname, .window_size=7)
#> Error in !varname: invalid argument type
covid_case_death_rates_extended %>% epi_slide_sum(!!varnames, .window_size=7)
#> Error in !varnames: invalid argument type
covid_case_death_rates_extended %>% epi_slide_sum(!!varnames, .window_size=7)
#> Error in !varnames: invalid argument type

Created on 2024-11-03 with reprex v2.1.1

We probably don't need the if branch here and can probably just use the else branch code in any situation.

  if (inherits(quo_get_expr(enquo(.col_names)), "character")) {
    pos <- eval_select(dplyr::all_of(.col_names), data = .x, allow_rename = FALSE)
  } else {
    pos <- eval_select(enquo(.col_names), data = .x, allow_rename = FALSE)
  }
  • !!varnames probably will work, but I'm not sure if this is intended.
  • !!! may or may not work; it may be more "proper" for it not to work, as it looks like splatting multiple arguments into the function, while our .col_names is just a single arg slot. (If we look at the similar across function, it will balk with a confusing message if we attempt to use !!!, because it is actually splatting multiple fn args. But I don't think we have fn arg splatting here so it might actually work in our case.)

Workaround is to use manually use all_of(varname) or all_of(varnames) instead of something with !! or !!!.

@brookslogan brookslogan changed the title Make epi_slide_opt work with !!varname, !!!varnames Make epi_slide_opt work with !!varname Nov 3, 2024
@brookslogan brookslogan changed the title Make epi_slide_opt work with !!varname Make epi_slide_opt work with !!varname, !!varnames Nov 3, 2024
@brookslogan brookslogan changed the title Make epi_slide_opt work with !!varname, !!varnames Make epi_slide_opt work with !!varname, maybe !!varnames, maybe !!!varnames Nov 3, 2024
@brookslogan brookslogan self-assigned this Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant