-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
count()/add_count() should preserve input classes #4086
Labels
feature
a feature request or enhancement
grouping 👨👩👧👦
helpers 🏋️♂️
helper functions like count() and tally()
vctrs ↗️
Milestone
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
hadley
added
feature
a feature request or enhancement
vctrs ↗️
helpers 🏋️♂️
helper functions like count() and tally()
labels
Dec 11, 2019
hadley
changed the title
add_count()/add_tally() strips classes
count()/add_count() should preserve input classes
Dec 31, 2019
Minimal reprex: library(dplyr, warn.conflicts = FALSE)
x <- data.frame(x = 1:3)
x %>% count() %>% class()
#> [1] "tbl_df" "tbl" "data.frame"
x %>% add_count() %>% class()
#> [1] "tbl_df" "tbl" "data.frame" Created on 2019-12-31 by the reprex package (v0.3.0) ( |
We might want to solve this with a generic mechanism for temporarily grouping, performing some operation, and then restoring groups (some sort of |
Somewhat more comprehensive reprex: df <- structure(data.frame(x = 1:3), class = c("myclass", "data.frame"))
df %>% count() %>% class()
df %>% count(x) %>% class()
df %>% add_count() %>% class()
df %>% add_count(x) %>% class() |
hadley
added a commit
that referenced
this issue
Jan 14, 2020
* Start on df_restore() * count() uses df_restore(); add_count() modifies input * deprecate .drop argument to `add_count()` Fixes #4086
hadley
added a commit
that referenced
this issue
Jan 15, 2020
This PR starts to develop the dplyr "interface", i.e. the set of generics that you need to provide methods for if you want to extend dplyr to work with new data frame subclasses. It also uses those methods (along with a count_regroups()) to ensure that the existing grouped_df implementations are not needlessly regrouping data. Fixes #4086 because count() can now use dplyr_reconstruct() to restore the original class Fixes #4051 because I've carefully documented the return value of the major verbs Fixes #4711 since implementing with_groups() is now easy.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
feature
a feature request or enhancement
grouping 👨👩👧👦
helpers 🏋️♂️
helper functions like count() and tally()
vctrs ↗️
(Originally reported at #4051 (comment).)
x <- as_tibble(iris)
g <- group_by(x, Species)
class(g) <- c("myclass", class(g))
x %>%
add_tally() %>%
class()
#> [1] "tbl_df" "tbl" "data.frame"
x %>%
add_count() %>%
class()
#> [1] "tbl_df" "tbl" "data.frame"
The text was updated successfully, but these errors were encountered: