Check for x == NA
, x != NA
and x %in% NA
. Such usage is almost surely incorrect --
checks for missing values should be done with is.na()
.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "x == NA",
linters = equals_na_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or != or %in%)
lint(
text = "x != NA",
linters = equals_na_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or != or %in%)
lint(
text = "x %in% NA",
linters = equals_na_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[equals_na_linter] Use is.na for comparisons to NA (not == or != or %in%)
# okay
lint(
text = "is.na(x)",
linters = equals_na_linter()
)
lint(
text = "!is.na(x)",
linters = equals_na_linter()
)