Hi,
I've recently come across the need of labelling groups generated from group_by(...)
inside adplyr expression using piping. Issue #2160 led me to issue #1185 and then to the merged feature #3490 dating back from May. Yet this does not seem to be implemented as of v0.7.6. Easily replicated using the code chunk below.
# Not working, throws a 'missing ".data" argument'
df <- mtcars %>% group_by(cyl) %>% mutate(g = group_indices())
# Bypass issue with a non-piped mutate call
df <- mtcars %>% group_by(cyl)
df <- mutate(ungroup(df), g = group_indices(df))
Has this been merged but not yet included in the release ? Or is that unintented ?
Cheers
Thomas
I think this is how you actually want to get your result:
mtcars %>% mutate(g = group_indices(., cyl))
Came across this issue because I was having trouble until I figured it out!
Indeed that works! However syntax feels contradictory to what is suggested in the merged PR #3490.
The development version of dplyr has not been released to CRAN yet.
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
Most helpful comment
I think this is how you actually want to get your result:
mtcars %>% mutate(g = group_indices(., cyl))
Came across this issue because I was having trouble until I figured it out!