We talked about making na_if() work in a match-like way, like na_if(x, c("bad", "NA")), but I no longer think we should do that. While that might be more useful, I think:
-
It would break existing code where people are currently supplying vector
yvalues and expect==to be used, which does seem to come up on a quick GitHub scan -
It would no longer match
NULLIF()from SQL, which it is advertised as mimicking. The Microsoft SQL docs state thatNULLIF(e1, e2)should be treated as a "searched CASE expression", meaning that the following should be exactly equivalentNULLIF(e1, e2) CASE WHEN e1 = e2 THEN NULL ELSE e1 END
If people want a match-like na_if(), we could add replace_match(x, c("bad", "NA") ~ NA) as part of #6328
Other notes on what changes from this update:
- Now casts
yto the type ofx, with the intention of making it very clear that this is type stable onx - Now uses
vec_equal()for comparison - Now uses
vec_assign()for assignment
"9c7db457-e0e3-4d62-8d92-1a8af03dae11"