tibble::tibble( foo = "bar", meh = NA_character ) %>% dplyr::group_by(foo) %>% dplyr::mutate( min_val = dplyr::if_else( all(is.na(meh)), min(meh), min(meh, na.rm = TRUE) ) )
In the code above I expect
min(meh) to run, which will become
min(NA) and thus result in
Instead, I'm always seeing a warning
Warning message: Problem with `mutate()` column `min_val`. ℹ `min_val = dplyr::if_else(all(is.na(meh)), min(meh), min(meh, na.rm = TRUE))`. ℹ no non-missing arguments, returning NA ℹ The warning occurred in group 1: foo = "bar".
this warning should only occur when the
else branch is run too with this data because
min(meh, na.rm = TRUE) will become
min(NULL) which triggers that warning.
What is going on and can I ignore the warning?
base works fine, but drops types so it's not as useful in my real-world application.