我有一个返回数据帧的例程。我想检查其值是否合理。使用testthatI have expect_equal,但是我不确定它是否适用于data.frames。我试图这样做,但是没有用
testthat::expect_equal(result$ORs[1,1:3], c(1.114308, 0.5406599, 2.296604), tolerance=1.0e-6)
Run Code Online (Sandbox Code Playgroud)
这是我收到的消息
?????????????????????????????????????????????????
test-xxx.R:19: failure: basic functionality
result$ORs[1, 1:3] not equal to c(1.114308, 0.5406599, 2.296604).
Modes: list, numeric
names for target but not for current
Attributes: < Modes: list, NULL >
Attributes: < Lengths: 2, 0 >
Attributes: < names for target but not for current >
Attributes: < current is not list-like >
?????????????????????????????????????????????????
?? Results ??????????????????????????????????????
Duration: 0.1 s
Run Code Online (Sandbox Code Playgroud)
如果您只是测试特定列的值(例如df[1,1]),那么您可以 unname和unlist该值:
expect_equal(unname(unlist(df[1,1])), "Value")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57 次 |
| 最近记录: |