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
complete and expand with length zero values #331
Comments
@colearendt I am not an admin on this repo but I tried your PR and it solves the problems I have with empty data frames. There are a few merge conflicts though and I think it also needs a |
Thanks for the feedback! I'll take a look when I have a chance. The merge conflicts are new, so thanks for the heads up! |
@rtaph I have updated my PR to resolve the merge conflicts. Were the problems you encountering related to factors? The examples you gave at the start of this issue have the same output in my PR, so it would look to me like your concerns were not addressed. The other thing - |
Hi @colearendt, I think the PR is great. Yes, my issues were with I don't think that a grouped factor-complete on an empty data frame make sense as a desirable operation (after all, isn't that somewhat the role of # devtools::install_github('colearendt/tidyr@7c83699')
library(tidyr)
library(dplyr, warn.conflicts = FALSE)
d1 <- ToothGrowth[0, ]
d2 <- group_by(d1, dose)
# Case 1: expected output, introduced via PR
complete(d1, supp)
#> # A tibble: 2 x 3
#> supp len dose
#> <fctr> <dbl> <dbl>
#> 1 OJ NA NA
#> 2 VC NA NA
# Case 2: unexpected output
complete(d2, supp)
#> # A tibble: 0 x 3
#> # Groups: dose [0]
#> # ... with 3 variables: dose <dbl>, supp <fctr>, len <dbl> I imagine others could run into this as well, as it is easy to mistakenly pass in a |
Ahh yes, that's a great example. I will take a look - it is a bit strange to me that this does not work the way that would be expected - need to look a bit more into how the |
@rtaph It looks like the "complete" of the factors is happening appropriately inside the function (for each group). The problem is that there is no group actually present here, so
However, even if this single execution (which I have verified is taking place as expected) returns a nonempty Perhaps @hadley can note whether |
Thanks for looking into this, @colearendt.
Let's see what @hadley's thoughts are, because as you say this has more to do with the philosophy of |
|
complete()
raises an error when a value for a column to expand is of length zero. The reason for this is thatexpand()
returns NULL resp. a 0 x 0 tibble for a length zero value.In my opinion it would be better for
expand()
to return a dataframe/tibble with the same column specification as the original one (or raise a more informative error). This would also fix the problem withcomplete()
.The text was updated successfully, but these errors were encountered: