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

Let complete() behave better when nesting NULL #1258

Closed
psychelzh opened this issue Dec 9, 2021 · 0 comments · Fixed by #1261
Closed

Let complete() behave better when nesting NULL #1258

psychelzh opened this issue Dec 9, 2021 · 0 comments · Fixed by #1261

Comments

@psychelzh
Copy link

When passing NULL to nesting() in calling complete(), it behaves differently than when not passing nesting() to complete(). From user's aspect, it is more intuitive if they should behave similarly.

library(tidyr)
df <- data.frame(x = factor("A", LETTERS[1:2]))
complete(df, x)
#> # A tibble: 2 x 1
#>   x    
#>   <fct>
#> 1 A    
#> 2 B
complete(df, x, nesting(NULL))
#> # A tibble: 1 x 1
#>   x    
#>   <fct>
#> 1 A

Created on 2021-12-09 by the reprex package (v2.0.1)

psychelzh added a commit to psychelzh/preproc.iquizoo that referenced this issue Dec 9, 2021
See more discussion at tidyverse/tidyr#1258

Signed-off-by: Liang Zhang <psychelzh@outlook.com>
DavisVaughan added a commit to DavisVaughan/tidyr that referenced this issue Dec 13, 2021
Because `nesting()` is about computing the "number of combinations" in some way, similar to `crossing()`, `expand_grid()` and `expand()`, which all already return 1 row data frames with no input through `expand_grid()`. The number of combinations you can extract from an empty set is always 1.

This also helps with tidyverse#1258, because a 1 row data frame will recycle nicely against other inputs.
DavisVaughan added a commit that referenced this issue Dec 13, 2021
* Work around `vec_sort()` bug with 0-col data frames

* Return a 1 row data frame from `nesting()` with no inputs

Because `nesting()` is about computing the "number of combinations" in some way, similar to `crossing()`, `expand_grid()` and `expand()`, which all already return 1 row data frames with no input through `expand_grid()`. The number of combinations you can extract from an empty set is always 1.

This also helps with #1258, because a 1 row data frame will recycle nicely against other inputs.

* Add tests for `expand/complete()` with empty `nesting/crossing()`

* NEWS bullet
psychelzh added a commit to psychelzh/preproc.iquizoo that referenced this issue Dec 16, 2021
See tidyverse/tidyr#1258 for more details. So currently, the development version of tidyr is used.

Signed-off-by: Liang Zhang <psychelzh@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant