Require usage of anyDuplicated(x) > 0
over any(duplicated(x))
Source: R/any_duplicated_linter.R
any_duplicated_linter.Rd
anyDuplicated()
exists as a replacement for any(duplicated(.))
, which is
more efficient for simple objects, and is at worst equally efficient.
Therefore, it should be used in all situations instead of the latter.
Details
Also match usage like length(unique(x$col)) == nrow(x)
, which can
be replaced by anyDuplicated(x$col) == 0L
.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "any(duplicated(x), na.rm = TRUE)",
linters = any_duplicated_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[any_duplicated_linter] anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...).
lint(
text = "length(unique(x)) == length(x)",
linters = any_duplicated_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[any_duplicated_linter] anyDuplicated(x) == 0L is better than length(unique(x)) == length(x).
# okay
lint(
text = "anyDuplicated(x)",
linters = any_duplicated_linter()
)
lint(
text = "anyDuplicated(x) == 0L",
linters = any_duplicated_linter()
)