[英]r devtools test() errors but testthat test_file() works
[英]test_file() works but test() fails with data.table
我的問題類似於r devtools test()錯誤,但testtest_file()有效 ,但是我不確定@hadley的注釋是否也適用於此。
我創建了一個R包的最小工作示例,其中可以使用testthat::test_file
測試單個文件,但不能使用devtools::test
測試該包。
這是我包中唯一的R文件R/aR
:
#' @export
generate_data_table <- function() {
data.table(a = 1:10, b = 11:20)
}
這是我的測試文件inst/tests/test-aR
:
test_that("everything is OK", {
x <- generate_data_table()
expect_equal(x[b == 11]$a, 1)
})
當我運行test_file
,該測試通過了,但是當我運行devtools::test
,出現以下錯誤:
> test()
Testing ttdt
Loading ttdt
1
1. Error: everything is OK -----------------------------------------------------
object 'b' not found
1: expect_equal(x[b == 11]$a, 1) at test-a.R:3
2: expect_that(object, equals(expected, label = expected.label, ...), info = info, label = label)
3: condition(object)
4: compare(expected, actual, ...)
5: compare.default(expected, actual, ...)
6: all.equal(x, y, ...)
7: all.equal.numeric(x, y, ...)
8: attr.all.equal(target, current, tolerance = tolerance, scale = scale, ...)
9: mode(current)
10: x[b == 11]
11: `[.data.table`(x, b == 11)
12: `[.data.frame`(x, i)
這是正確的行為還是應該將其視為data.table
或devtools
的錯誤?
這是我的環境:
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.9.2 testthat_0.8.1 devtools_1.4.1
loaded via a namespace (and not attached):
[1] digest_0.6.4 evaluate_0.5.1 httr_0.2 memoise_0.1 parallel_3.0.2
[6] plyr_1.8.1 Rcpp_0.11.0 RCurl_1.95-4.1 reshape2_1.2.2 stringr_0.6.2
[11] tools_3.0.2 whisker_0.3-2
更新 。 我已經更新了程序包的依賴關系,以正確地依賴於這里的 data.table
,但是問題仍然存在。
如果你
DESCRIPTION
文件中正確設置依賴性 test(fresh = TRUE)
一切都應該工作。
使用fresh = TRUE
將確保測試在新的R會話中運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.