Tests in my R
package started to fail on attributes. Let’s have a minimal example:
library(testthat)
x <- structure(c("2", "0", "1", "2"), dim = c(2L, 2L), dimnames = list(
c("1", "5"), c("m1", "m4")))
y <- structure(c("2", "0", "1", "2"), dim = c(2L, 2L))
expect_equal(x, y, ignore_attr = TRUE)
# Error: `x` not equal to `y`.
# Attributes: < Length mismatch: comparison on first 1 components >
I only want to test the values at this stage, not the dimnames. This used to be done with expect_equivalent
, but according to the expect_equivalent
help (in version 3.2.1.1), the function has been deprecated and replaced with expect_equal(..., ignore_attr = TRUE)
. This has been the solution my code used in the past with success. Not any more. ignore_attr
is an argument for waldo::compare()
, which the help states is used.
Do I now need to rewrite my tests to always have matching attributes? If not, what is the current stable, recommended way to ignore attributes in tests?