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

Don't error when grouping zero-row data frames. Fixes #486 #487

Closed
wants to merge 2 commits into from

Conversation

wch
Copy link
Member

@wch wch commented Jul 8, 2014

Fixes the error that previously occurred with:

dplyr:::grouped_df_impl(data.frame(a = numeric(0), g = character(0)), list(quote(g)), drop = TRUE)

I'm new to the C++ part of this codebase so please feel free to change, critique, etc.

@hadley
Copy link
Member

hadley commented Jul 28, 2014

This seems reasonable (cc @romainfrancois), but did you check what happens when you try to filter, summarise etc a data frame with 0-length index?

@romainfrancois
Copy link
Member

+1. Looks correct, but needs some dedicated test cases

@hadley
Copy link
Member

hadley commented Jul 28, 2014

@wch could you please add a few test cases?

@wch
Copy link
Member Author

wch commented Jul 28, 2014

Writing tests, but I'm not sure that all results are correct:

dfg <- group_by(data.frame(a = numeric(0), g = character(0)), g)
group_size(dfg)
# integer(0)

Should that be 0 instead of integer(0)?

@hadley
Copy link
Member

hadley commented Jul 28, 2014

No, because group_size() should have the same length as the number of groups.

@wch
Copy link
Member Author

wch commented Jul 28, 2014

So it shouldn't group on g? Because it does that with this patch:

dfg
# Source: local data frame [0 x 2]
# Groups: g

groups(dfg)
# [[1]]
# g

@wch
Copy link
Member Author

wch commented Jul 28, 2014

It looks like I misunderstood what group_size is supposed to return. The test results are correct, and I've added the tests.

@wch
Copy link
Member Author

wch commented Jul 28, 2014

I just added some more tests.

@romainfrancois the call to mutate fails, with this error:

> x <- mutate(dfg, c = b + 1)
Error: not compatible with requested type 
4 stop(structure(list(message = "not compatible with requested type", 
    call = NULL, cppstack = NULL), .Names = c("message", "call", 
"cppstack"), class = c("Rcpp::not_compatible", "C++Error", "error", 
"condition"))) 
3 mutate_impl(.data, named_dots(...), environment()) 
2 mutate.tbl_df(dfg, c = b + 1) at manip.r#81
1 mutate(dfg, c = b + 1) 

@romainfrancois
Copy link
Member

Thanks @wch; I'll pick it up.

@hadley hadley added the bug label Aug 1, 2014
@hadley hadley added this to the 0.3.1 milestone Aug 1, 2014
@hadley hadley assigned hadley and romainfrancois and unassigned hadley Aug 1, 2014
@romainfrancois
Copy link
Member

I only slightly modified two test cases. I think the rest was fixed as part of dealing with #486

@lock
Copy link

lock bot commented Jan 19, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants