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
pivot_wider
handles NAs inconsistently with tidyr
#1238
Comments
this stems from the keys_cond in with your example, the pivot expressions are: pivot_exprs
$A
max(ifelse(y == "A", x, NULL), na.rm = TRUE)
$`NA`
max(ifelse(y == NA_character_, x, NULL), na.rm = TRUE)
$B
max(ifelse(y == "B", x, NULL), na.rm = TRUE) I think the issue is Updating build_pivot_wider_exprs <- function(row_id, spec, values_fill, values_fn, data, call) {
values_col <- spec[[".value"]][row_id]
fill_value <- values_fill[[values_col]]
keys <- vctrs::vec_slice(spec[, -(1:2)], row_id)
keys_cond <- purrr::imap(
keys,
function(value, name) {
- expr(!!sym(name) == !!value)
+ expr(!!sym(name) == !!value || is.na(!!sym(name)) && is.na(!!value))
}
) %>%
purrr::reduce(~ expr(!!.x & !!.y))
case_expr <- expr(ifelse(!!keys_cond, !!sym(values_col), !!fill_value))
agg_fn <- values_fn[[values_col]]
resolve_fun(agg_fn, case_expr, data = data, call = call)
} x2 %>%
pivot_wider(names_from = y, values_from = x) %>%
pull(`NA`)
# [1] 2 I can test it some more and open up a PR soon |
* pivot_wider test for na column name handling * handle `NA` column names in pivot_wider * update news for #1238
When there are NA's in the
names_from
variabledbplyr
translatespivot_wider
inconsistently.The text was updated successfully, but these errors were encountered: