Skip to content

crossing() ignores NA values #364

Description

@huftis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions