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

crossing() ignores NA values #364

Closed
huftis opened this issue Sep 22, 2017 · 2 comments
Closed

crossing() ignores NA values #364

huftis opened this issue Sep 22, 2017 · 2 comments
Labels
bug

Comments

@huftis
Copy link

@huftis huftis commented Sep 22, 2017

crossing() seems to ignore NA values. This is inconvenient and not consistent with expand.grid(). Reprex:

library(tidyr)
crossing(num = 1:2, char = c("A", "B", NA))
#> # A tibble: 4 x 2
#>     num  char
#>   <int> <chr>
#> 1     1     A
#> 2     1     B
#> 3     2     A
#> 4     2     B

expand.grid(num = 1:2, char = c("A", "B", NA))
#>   num char
#> 1   1    A
#> 2   2    A
#> 3   1    B
#> 4   2    B
#> 5   1 <NA>
#> 6   2 <NA>

Other ‘special’ values work fine:

crossing(num = 1:2, char = c("A", "B", NaN))
#> # A tibble: 6 x 2
#>     num  char
#>   <int> <chr>
#> 1     1     A
#> 2     1     B
#> 3     1   NaN
#> 4     2     A
#> 5     2     B
#> 6     2   NaN
crossing(num = 1:2, char = c("A", "B", Inf))
#> # A tibble: 6 x 2
#>     num  char
#>   <int> <chr>
#> 1     1     A
#> 2     1     B
#> 3     1   Inf
#> 4     2     A
#> 5     2     B
#> 6     2   Inf
@hadley hadley added the bug label Nov 15, 2017
@hadley
Copy link
Member

@hadley hadley commented Nov 16, 2017

Root cause is:

ulevels(c("A", "B", NA))
#> [1] "A" "B"
@hadley
Copy link
Member

@hadley hadley commented Nov 16, 2017

Root cause of that is

sort(c("A", "B", NA))
#> [1] "A" "B"
@hadley hadley closed this in 1dc4066 Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants