mayer79 · GitHub

The new cur_data() in dplyr is fantastic. However, it does not yet serve as a full replacement of do. Why? According to its docu, it excludes the grouping variables. I suppose this is to ensure that the same variable name does not appear twice in the resulting data.frame.

Would it be possible to add an argument keep_grouping_vars = FALSE to cur_data where this could be overwritten?

Here is an example:

library(dplyr)
iris %>%
  group_by(Species) %>%
  summarize(should_by_five = ncol(cur_data()))
# Output
  Species    should_by_five
  <fct>               <int>
1 setosa                  4
2 versicolor              4
3 virginica               4

This is my suggestion:

iris %>%
  group_by(Species) %>%
  summarize(should_by_five = ncol(cur_data(keep_grouping_vars = TRUE)))

The current workaround:

iris %>%
  group_by(Species) %>%
  summarize(should_by_five = ncol(bind_cols(cur_group(), cur_data())))

Read the original on github.com ↗