Open Bisaloo opened 2 years ago
Note that unique()
is an S3 generic so we can't guarantee it does what we think it does.
unique.data.frame()
comes to mind.
Also note the only truly equivalent call is identical(sort(unique(x)), sort(unique(y)))
, e.g. identical(unique(x), unique(rev(x)))
is false if x
contains more than one unique value.
As discussed in #951, I believe (assume?) that in many cases where people use identical(sort(x), sort(y))
, they actually want setequal()
but you are right they are not strictly equivalent.
Two questions:
identical(sort(unique(x)), sort(unique(y)))
and identical(unique(sort(x)), unique(sort(y)))
could still be useful? Documentation of this pattern in CRAN packagesidentical(sort(x), sort(y))
as well if disabled by default? For example, using an argument which would default to linting just the strictly equivalentNB sort()
silently removes NAs.
This aims at encouraging the use of
setequal()
in place of some less clear patterns I've occasionally seen:or any similar combination.
This linter could also use the same logic to encourage the use of
testthat::expect_setequal()
. Possibly also recommend usingtestthat::expect_setequal()
overtestthat::expect_true(setequal())
?If you agree this would be a good addition, I can work on a PR. Do you see any potential pitfalls I should be looking out for?