Dplyr: group_indices() cannot be used inside a dplyr expression

Created on 24 Jul 2018  路  4Comments  路  Source: tidyverse/dplyr

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

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!

All 4 comments

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/

Was this page helpful?
0 / 5 - 0 ratings