I'm having trouble using testthat's tolerance parameter when I check whether two data_frames are equal. Here's a simple example with two data frames:
library(dplyr)
library(testthat)
d1 = data_frame(a = c(1, 1),
b = c(2, 2))
d2 = data_frame(a = c(1, 1.00001),
b = c(2, 2))
When I check for equality, testthat throws an error, even with a sufficiently high tolerance value:
expect_equal(d1, d2,
tolerance = 0.01)
# Error: d1 not equal to d2
# Rows in y but not x: 2. Rows with difference occurences in x and y: 1
No error is thrown when I compare the individual vectors:
expect_equal(d1$a, d2$a,
tolerance = 0.01)
expect_equal(d1$b, d2$b,
tolerance = 0.01)
Any suggestions? I assume I'm misusing the expect_equal function, but am not sure how to resolve other than running expect_equal on individual columns of the data frame.
Here's the package versions I'm using:
packageVersion("dplyr")
# [1] ‘0.4.3’
packageVersion("testthat")
# [1] ‘0.11.0’
dplyr
(Just usedata.frame
) all tests pass as expected. – Cele