Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is my stab to fix #3501.
It is still WIP because we might exchange thoughts on the name of the stat, and/or how it is used, expand documentation and tests. Initially I'd welcome any feedback on the direction of the PR.
To recap #3501, we generally want a more flexible summary stat that does not (necessarily) group by
x
. This isstat_summarise()
in this PR (name is up for discussion).The 'twist' I've given this PR is that the default summary function is a bit dandy, which we'll go over as I narrate the examples.
By default, the stat does nothing to the input data and renders points.
In #3501, it was suggested that we can pass any function to the stat that returns a data.frame.
This is indeed how this stat works.
However, the 'trick' in this PR is that the default summary function is an NSE function that evaluates expressions passed to
fun.args
. Hence, instead of being bothered to construct a separate function for every task, we can dynamically pass NSE expressions this way.Like some other tidyverse functions, the expressions are evaluated sequentially, meaning that later expressions can use results of prior expressions. This allows us to, for example, compute a convex hull in a reasonably straightforward manner.
The thing that works differently relative to similarly flavoured functions (e.g. summarise, reframe, mutate in {dplyr}) is that not every evaluated expression needs to result in column-compatible data right away. This allows us to declare temporary variables, as long as they're explicity removed.
Created on 2024-08-28 with reprex v2.1.1