Exploratory Community

"Error : must be a `Date` object, not a logical vector Call `rlang::last_error()` to see a backtrace" when trying to set NA for a column with case_when

#1

When you try to set a NA with case_when for a date column, you might get below error

case_when(country == “Argentina” ~ today(), TRUE ~ NA)

Error : must be a `Date` object, not a logical vector Call `rlang::last_error()` to see a backtrace

To address the issue, you can try TRUE ~ as.Date(NA) instead of TRUE ~ NA

See How to set NA for Date Column with case_when for details.