Skip to content
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() retains grouping, but should not #347

Closed
krlmlr opened this issue Aug 13, 2019 · 3 comments
Closed

count() retains grouping, but should not #347

krlmlr opened this issue Aug 13, 2019 · 3 comments
Labels
bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL

Comments

@krlmlr
Copy link
Member

krlmlr commented Aug 13, 2019

I believe the implementation of group_vars.tbl_lazy() needs a tweak.

library(tidyverse)
library(dbplyr)
#> 
#> Attaching package: 'dbplyr'
#> The following objects are masked from 'package:dplyr':
#> 
#>     ident, sql

memdb_frame(a = 1:3, b = 1:3) %>%
  count(a, b) %>%
  group_vars()
#> [1] "a"

tibble(a = 1:3, b = 1:3) %>%
  count(a, b) %>%
  group_vars()
#> character(0)

Created on 2019-08-13 by the reprex package (v0.3.0)

@hadley hadley added bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL labels Dec 13, 2019
@hadley hadley added this to the 2.0.0 milestone Dec 13, 2019
@hadley
Copy link
Member

hadley commented Sep 21, 2020

Hmmm, I think the fix should be to provide a count method as below, but count isn't a generic?

count.tbl_lazy <- function(x, ..., wt = NULL, sort = FALSE, name = NULL) {
  if (!missing(...)) {
    out <- group_by(x, ..., .add = TRUE, .drop = .drop)
  } else {
    out <- x
  }
  out <- dplyr::tally(out, wt = !!enquo(wt), sort = sort, name = name)
  out <- group_by(out, !!!group_vars(x))
  out
}

@krlmlr
Copy link
Member Author

krlmlr commented Sep 22, 2020

Would it be too bad to add the group_by(out, !!!group_vars(x)) to dplyr::count() without introducing a generic?

@hadley
Copy link
Member

hadley commented Sep 22, 2020

@krlmlr we keep patching count() and it keeps breaking in surprising ways.

@hadley hadley removed this from the 2.0.0 milestone Sep 27, 2020
@hadley hadley closed this as completed in 4dbcb44 Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL
Projects
None yet
Development

No branches or pull requests

2 participants