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

Implement proper tidyselect for epi_slide_opt #452

Merged
merged 19 commits into from
Jun 7, 2024

Conversation

nmdefries
Copy link
Contributor

@nmdefries nmdefries commented May 30, 2024

Checklist

Please:

  • Make sure this PR is against "dev", not "main" (unless this is a release
    PR).
  • Request a review from one of the current main reviewers:
    brookslogan, nmdefries.
  • Makes sure to bump the version number in DESCRIPTION. Always increment
    the patch version number (the third number), unless you are making a
    release PR from dev to main, in which case increment the minor version
    number (the second number).
  • Describe changes made in NEWS.md, making sure breaking changes
    (backwards-incompatible changes to the documented interface) are noted.
    Collect the changes under the next release number (e.g. if you are on
    1.7.2, then write your changes under the 1.8 heading).
  • See DEVELOPMENT.md for more information on the development
    process.

Change explanations for reviewer

Turn off renaming behavior (see comments about awkward/confusing naming here).

Closes #435

@nmdefries nmdefries requested a review from brookslogan May 30, 2024 15:27
@nmdefries
Copy link
Contributor Author

@brookslogan requesting an initial/broad review of this. Tests are pending.

R/slide.R Outdated Show resolved Hide resolved
R/slide.R Outdated Show resolved Hide resolved
@nmdefries nmdefries marked this pull request as ready for review June 3, 2024 21:38
@nmdefries nmdefries requested a review from brookslogan June 3, 2024 21:38
Copy link
Contributor

@brookslogan brookslogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I have a few notes mostly unrelated to the main changes that cropped up that could be fixed/filed. Plus some wording suggestions.

#' # Remove a nonessential var. to ensure new col is printed
#' dplyr::select(geo_value, time_value, cases, cases_7dav) %>%
#' dplyr::select(geo_value, time_value, cases, cases_7dav = slide_value_cases) %>%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

musing: This also makes me wish for something like new_col_name that actually did what you'd naturally guess here (without requiring names_sep = NULL). Though I vaguely recall we were putting off coming up with a better interface here (especially regarding better prefixes/suffixes for means and sums)? Part of this was due to trying for consistency with what epi_slide() technically does, but currently I'm thinking a bit of technical inconsistency is fine. (And the solution to the inconsistency seems like it'd be removing as_list_col and names_sep globally, supporting multiple tidyeval expressions, and mirroring dplyr support for things like tibble(x = 1) %>% mutate(tibble(y = x + 1, z = x + 2)); that last one seems tricky but might be possible. Then we could make .new_col_name or .new_col_names or actually do what it sounds like since we'd never be automatically unnesting. I don't /think/ this loses out on functionality since the remaining use cast of nesting & unnesting I can think of --- hiding your true number of rows from epi_slide's number-of-row constraints --- you already have to do as_list_col = TRUE and unnest manually.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we fully supported multiple tidyeval expressions, would we need to have a .new_col_name param at all? The renaming functionality in tidyselect is sufficient if we don't do the unnesting step.

For the epi_slide_opt and derived fns, we are currently passing ... as args to the slide computation (frollmean, etc) so multiple tidy expressions might be an issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .new_col_name would still be helpful/convenient for non-tidy-eval (function/formula) epi_slide and for epi_slide_opt.

Regarding ... as args: I don't think we've ever been able to actually use this feature in a useful way, so we could consider removing it if it's a problem. But I'm not sure it is. The major pain I was thinking of at least was detecting whether f is a tidyeval computation or not when we allow unnamed tidyeval computations. This seems potentially possible: in the first/each computation application, evaluate f as if it were tidyeval, check if it actually results in a function or formula, and if so, adjust appropriately; if it results in a tibble, then it's the tidyeval on f and each of ...; if f is missing it's also tidyeval.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to #461

man-roxygen/opt-slide-params.R Outdated Show resolved Hide resolved
tests/testthat/test-epi_slide.R Show resolved Hide resolved
tests/testthat/test-epi_slide.R Outdated Show resolved Hide resolved
@nmdefries nmdefries merged commit 7fd2119 into dev Jun 7, 2024
4 checks passed
@nmdefries nmdefries deleted the ndefries/opt-slide-proper-tidyselect branch June 7, 2024 19:06
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

Successfully merging this pull request may close these issues.

Use proper tidyselect tidyselections in epi_slide_opt, or don't call tidyselection
2 participants