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

do.grouped_dt drops grouping columns #735

Closed
kismsu opened this issue Oct 30, 2014 · 1 comment
Closed

do.grouped_dt drops grouping columns #735

kismsu opened this issue Oct 30, 2014 · 1 comment
Assignees
Labels
Milestone

Comments

@kismsu
Copy link

@kismsu kismsu commented Oct 30, 2014

Hi, I've noticed that do on grouped data.table doesn't send all columns into function.

library(nycflights13)
library(dplyr)

g <- function(x) {
    browser()
}

flights %>%
    data.table() %>%
    select(origin, flight, distance, dep_delay, hour, minute) %>%
    group_by(flight, distance, dep_delay) %>%
    do(
        data.frame(g(.))
    )

Inside g() you'll see

Source: local data table [1 x 3]
Groups: flight, distance, dep_delay

  origin hour minute
1    EWR   14      0

As I believe the goal is to have unified results for all sources, hence function should receive all columns.
The solutions might be (based on http://stackoverflow.com/questions/26636402/how-i-can-get-the-value-of-grouping-column-inside-user-define-function-in-data-t/26641743#26641743) replace in do.grouped_dt

call <- substitute(dt[, cols, by = vars], list(cols = cols)) 

by

call <- substitute(dt[, cols, by = vars, .SDcols = names(dt)], list(cols = cols)) 

or add names to dt_env.

@hadley hadley added the bug label Oct 30, 2014
@hadley hadley added this to the 0.3.1 milestone Oct 30, 2014
@hadley hadley self-assigned this Oct 30, 2014
@hadley
Copy link
Member

@hadley hadley commented Nov 19, 2014

Slightly simpler test case:

mtcars %>% 
  tbl_dt() %>%
  select(mpg, cyl) %>%
  group_by(cyl) %>%
  do(n = names(.)) %>%
  str()

Loading

@hadley hadley closed this in dc48da4 Nov 19, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants