group_by() works only with functions in the tidyverse (especially those in the dplyr package). dim() is a function built into R. Similarly, other built-in functions like nrow() or ncol() don't pay attention to whether group_by() has been run on the data.
If you want to know the number of observations in each group, try using dplyr's count() instead:
Thank you for the reply. Actually I wrote a quite complex function which takes a tibble (or dataframe) as input and outputs a tibble. I want to apply this function to each group of a tibble defined by a variable. Let's say the function I want to apply is testfunction, the dataframe is testdata, and the grouping variable is label. What I want to do is something like this:
testdata %>% group_by(label) %>% testfunction
But this doesn't work as expected because testfunction contains many R built-in functions in itself. What would be the best solution in this case?