I am fairly proficient within the Tidyverse, but have always used ifelse() instead of dplyr if_else(). I want to switch this behavior and default t
Another important reason for preferring if_else() to ifelse() is checking for consistency in lengths. See this dangerous gotcha:
> tibble(x = 1:3, y = ifelse(TRUE, x, 4:6))
# A tibble: 3 x 2
x y
1 1 1
2 2 1
3 3 1
Compare with
> tibble(x = 1:3, y = if_else(TRUE, x, 4:6))
Error: `true` must be length 1 (length of `condition`), not 3.
The intention in both cases is clearly for column y to equal x or to equal 4:6 acording to the value of a single (scalar) logical variable; ifelse() silently truncates its output to length 1, which is then silently recycled. if_else() catches what is almost certainly an error at source.