Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions r/R/dplyr-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -908,17 +908,6 @@ nse_funcs$if_else <- function(condition, true, false, missing = NULL) {
))
}

# if_else doesn't yet support factors/dictionaries
# TODO: remove this after ARROW-13358 is merged
warn_types <- nse_funcs$is.factor(true) | nse_funcs$is.factor(false)
if (warn_types) {
warning(
"Dictionaries (in R: factors) are currently converted to strings (characters) ",
"in if_else and ifelse",
call. = FALSE
)
}

build_expr("if_else", condition, true, false)
}

Expand Down
14 changes: 8 additions & 6 deletions r/tests/testthat/test-dplyr-funcs-conditional.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,20 @@ test_that("if_else and ifelse", {
tbl
)

# TODO: remove the mutate + warning after ARROW-13358 is merged and Arrow
# supports factors in if(_)else
compare_dplyr_binding(
.input %>%
mutate(
y = if_else(int > 5, fct, factor("a"))
) %>%
collect() %>%
# This is a no-op on the Arrow side, but necessary to make the results equal
mutate(y = as.character(y)),
tbl,
warning = "Dictionaries .* are currently converted to strings .* in if_else and ifelse"
# Arrow if_else() kernel does not preserve unused factor levels,
# so reset the levels of all the factor columns to make the test pass
# (ARROW-14649)
transmute(across(
where(is.factor),
~ factor(.x, levels = c("a", "b", "c", "d", "g", "h", "i", "j"))
)),
tbl
)

# detecting NA and NaN works just fine
Expand Down