-
Notifications
You must be signed in to change notification settings - Fork 422
Closed
Labels
ask
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorgrids #️⃣expanding, nesting, crossing, ...expanding, nesting, crossing, ...
Description
It currently drops them because of the way sorted_unique() works. (This also would affect forcats::fct_unique() since the implementation came from there). We get them back in complete() because that does a full_join() and the NA was in the original data.
library(tidyr)
df <- tibble(a = factor(c("x", NA), levels = c("x", "y")))
# dropped `NA`
expand(df, a)
#> # A tibble: 2 × 1
#> a
#> <fct>
#> 1 x
#> 2 y
# we get it back from the full-join
complete(df, a)
#> # A tibble: 3 × 1
#> a
#> <fct>
#> 1 x
#> 2 y
#> 3 <NA>
tidyr:::sorted_unique
#> function (x)
#> {
#> if (is.factor(x)) {
#> factor(levels(x), levels(x), exclude = NULL, ordered = is.ordered(x))
#> }
#> else if (is_bare_list(x)) {
#> vec_unique(x)
#> }
#> else {
#> vec_sort(vec_unique(x))
#> }
#> }
#> <bytecode: 0x7fa27f1ac8b0>
#> <environment: namespace:tidyr>I am fairly certain we want to keep them, since it keeps NAs with non-factor types?
library(tidyr)
df <- tibble(a = c(NA, 1))
# keeps NA at the end
expand(df, a)
#> # A tibble: 2 × 1
#> a
#> <dbl>
#> 1 1
#> 2 NAMetadata
Metadata
Assignees
Labels
ask
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorgrids #️⃣expanding, nesting, crossing, ...expanding, nesting, crossing, ...