diff --git a/r/R/dplyr-functions.R b/r/R/dplyr-functions.R index 0ccc5734a7f..b1f8a65f93d 100644 --- a/r/R/dplyr-functions.R +++ b/r/R/dplyr-functions.R @@ -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) } diff --git a/r/tests/testthat/test-dplyr-funcs-conditional.R b/r/tests/testthat/test-dplyr-funcs-conditional.R index 4e4346a7592..a5e6ce6ea09 100644 --- a/r/tests/testthat/test-dplyr-funcs-conditional.R +++ b/r/tests/testthat/test-dplyr-funcs-conditional.R @@ -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