-
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
rbind on grouped data produces a "nested data frame" #2138
Comments
Similarly, rbind between a data.frame and a grouped tbl_df data.frame does not return expected result. df1 <- data.frame ("a" = sample(10), "b" = sample(10)) rbind(df1, df2) Could someone let us know if that wanted or not ? Not like this in 0.4 and very weird result according to me |
It does work as expected with bind_rows(), though. @hadley: Do you think there's a good way to make rbind() do the right thing for grouped df-s? |
I think we can probably make it do better, either by defining a |
That would have to be S4, right? Could you please tag this as appropriate (bug/feature)? |
I'm not sure on the S3/S4 issue - I'd need to look into the dispatch issues in more detail. Somewhat related to r-spatial/sf#49 |
Could do the same what data.table is doing: see #606 (comment), also tidyverse/tibble#34 (comment) for the related tibble issue. CC @billdenney. |
We had to revert this due to #2667 — it caused more problems than it fixed. |
@hadley looks like we should also remove the grouped_df method? it's probably better to lose group information than getting a matrix when combining a grouped_df with a tbl_df or data.frame. |
Could an option be added to rbind(as.data.frame(df1), as.data.frame(df2)) |
@billdenney we're not in control of the cbind and rbind generics. |
@billdenney Just use |
@hadley (I haven't fully followed the parts about why it's infeasible, but I like warnings as reminders. And, the warning will hopefully help prevent future bug reports like this one. If it's already there-- no worries; I can't easily test the development version in my current environment.) |
it is not possible to reliably issue a warning because of the way cbind's and rbind's dispatch mechanism works. |
Well, we could hack into cbind() and rbind() the way data.table does: #606 (comment), tidyverse/tibble#34 (comment). I have suggested this before, so there may be a reason we're not following this path. |
it doesn't look ideal to have both dplyr and data.table hack the base functions. We'll probably get unpredictable results as a function of which objects are supplied and which package was first loaded. Though we could load data.table if it is installed before applying our hack to work around that. |
Digging around possible causes for this strange behaviour led me to
bind_rows
, but it would still be great if the following bug could be resolved or a warning to usebind_rows
could be printed. Code that worked fine suddenly failed when I changed the grouping variable, leading to an output ofrbind
like:Example:
The text was updated successfully, but these errors were encountered: