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

summarise() fails with data.frame output #405

Closed
jmbarbone opened this issue Jan 5, 2023 · 1 comment
Closed

summarise() fails with data.frame output #405

jmbarbone opened this issue Jan 5, 2023 · 1 comment
Labels
feature a feature request or enhancement

Comments

@jmbarbone
Copy link

Using a function inside summarise() that returns a data.frame doesn't seem to be supported:

library(dplyr, warn.conflicts = FALSE)
library(dtplyr)

# example from ?summarise
my_quantile <- function(x, probs) {
  tibble(x = quantile(x, probs), probs = probs)
}

mtcars %>%
  group_by(cyl) %>%
  summarise(my_quantile(disp, c(0.25, 0.75)))
#> `summarise()` has grouped output by 'cyl'. You can override using the `.groups`
#> argument.
#> # A tibble: 6 × 3
#> # Groups:   cyl [3]
#>     cyl     x probs
#>   <dbl> <dbl> <dbl>
#> 1     4  78.8  0.25
#> 2     4 121.   0.75
#> 3     6 160    0.25
#> 4     6 196.   0.75
#> 5     8 302.   0.25
#> 6     8 390    0.75

mtcars %>%
  lazy_dt() |> 
  group_by(cyl) %>%
  summarise(my_quantile(disp, c(0.25, 0.75))) |> 
  collect()
#> Error in `[.data.table`(`_DT1`, , .(`my_quantile(disp, c(0.25, 0.75))` = my_quantile(disp, : All items in j=list(...) should be atomic vectors or lists. If you are trying something like j=list(.SD,newcol=mean(colA)) then use := by group instead (much quicker), or cbind or merge afterwards.

Created on 2023-01-05 with reprex v2.0.2

@markfairbanks markfairbanks added the feature a feature request or enhancement label Jan 6, 2023
@markfairbanks
Copy link
Collaborator

Thanks for reporting! This is being tracked in #342 already. I'm going to close this issue, but you can track there for updates.

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
Projects
None yet
Development

No branches or pull requests

2 participants