Open hadley opened 4 years ago
We need to figure out the semantics — I think probably it should using matching not equality. And maybe it should only be vectorised in its first argument? Maybe it should just be this?
na_if <- function(x, na) {
x[vec_in(x, na)] <- NA
x
}
Which makes it a special case of case_in()
: case_in(x, y ~ NA)
Regarding na_if()
being match-like, we document that na_if()
is like SQL NULLIF()
, and that uses equality. And a few people use it that way (after looking at GitHub). So it is probably best to leave it like this and promote some other way to do match-like replacement with NA
s. See my full analysis in: https://github.com/tidyverse/dplyr/pull/6329#issue-1302637632
Needs to be implemented in such a way that you can replace
NaN
values:(from https://github.com/tidyverse/dplyr/issues/4627)