Require usage of expect_identical(x, y) where appropriate
Source:R/expect_identical_linter.R
expect_identical_linter.Rd
At Google, testthat::expect_identical()
should be the default/go-to function for
comparing an output to an expected value. expect_true(identical(x, y))
is an equivalent but unadvised method of the same test. Further,
testthat::expect_equal()
should only be used when expect_identical()
is inappropriate, i.e., when x
and y
need only be numerically
equivalent instead of fully identical (in which case, provide the
tolerance=
argument to expect_equal()
explicitly). This also applies
when it's inconvenient to check full equality (e.g., names can be ignored,
in which case ignore_attr = "names"
should be supplied to
expect_equal()
(or, for 2nd edition, check.attributes = FALSE
).
Exceptions
The linter allows expect_equal()
in three circumstances:
A named argument is set (e.g.
ignore_attr
ortolerance
)Comparison is made to an explicit decimal, e.g.
expect_equal(x, 1.0)
(implicitly settingtolerance
)...
is passed (wrapper functions whcih might set arguments such asignore_attr
ortolerance
)
See also
linters for a complete list of linters available in lintr.