【发布时间】:2016-10-10 20:03:50
【问题描述】:
当我检查两个数据帧是否相等时,我无法使用 testthat 的容差参数。这是一个包含两个数据框的简单示例:
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))
当我检查相等性时,testthat 会引发错误,即使容差值足够高:
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
比较单个向量时不会引发错误:
expect_equal(d1$a, d2$a,
tolerance = 0.01)
expect_equal(d1$b, d2$b,
tolerance = 0.01)
有什么建议吗?我假设我误用了 expect_equal 函数,但除了在数据框的各个列上运行 expect_equal 之外,我不确定如何解决。
这是我正在使用的软件包版本:
packageVersion("dplyr")
# [1] ‘0.4.3’
packageVersion("testthat")
# [1] ‘0.11.0’
【问题讨论】:
-
我可以重现您的错误。如果没有
dplyr(只需使用data.frame),所有测试都会按预期通过。