I'm trying to use some some ifelse logic within a mutate function to tidy up a column of strings and convert them to dates, depending on the format of the string that is encountered.
I'm finding that lubridate::ymd() seems to be giving me a different output depending on whether it is within an ifelse() statement or not, and I'm confused.
Here's a simplified reprex to demonstrate what I'm seeing:
The reason for this are R's use of coercion on directly incompatible types; R is trying to find a compatabile type between Logical (from grepl) and Date (from ymd); and settling on Numeric as a compromise.
A vector of the same length and attributes (including dimensions and "class") as test and data values from the values of yes or no.
And I agree with you this doesnt seem entirely warranted aside from perhaps a performance perspective, as it acts against expectations ; part of the motivation behind dplyr::if_else is for more consistent and stricter class compatibility