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()
)
#> <text>:1:1: warning: [equals_na_linter] Use is.na() instead of x == NA
#> x == NA
#> ^~~~~~~
lint(
text = "x != NA",
linters = equals_na_linter()
)
#> <text>:1:1: warning: [equals_na_linter] Use is.na() instead of x != NA
#> x != NA
#> ^~~~~~~
lint(
text = "x %in% NA",
linters = equals_na_linter()
)
#> <text>:1:1: warning: [equals_na_linter] Use is.na() instead of x %in% NA
#> x %in% NA
#> ^~~~~~~~~
# okay
lint(
text = "is.na(x)",
linters = equals_na_linter()
)
#> ℹ No lints found.
lint(
text = "!is.na(x)",
linters = equals_na_linter()
)
#> ℹ No lints found.