Skip to contents

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).




The linter allows expect_equal() in three circumstances:

  1. A named argument is set (e.g. ignore_attr or tolerance)

  2. Comparison is made to an explicit decimal, e.g. expect_equal(x, 1.0) (implicitly setting tolerance)

  3. ... is passed (wrapper functions whcih might set arguments such as ignore_attr or tolerance)

See also

linters for a complete list of linters available in lintr.