此问题与Q32328802 - testdata for testthat几乎相同。不同之处在于,我正在寻找与devtools::check
相关的更具体的答案。 特别是,如何获得devtools::check()
来识别并加载测试数据?
[tests/testthat.R
和tests/testthat/setup-testdata.R
的我的包结构在下面进行了描述(github链接在文章的底部)。我尝试了以下方法:
inst/testdata
中。由于此操作无效,因此我也尝试了其他位置(例如tests/
,tests/testthat
)。这些位置均无效。helper-testdata.R
重命名为setup-testdata.R
并获得相同的失败结果。devtools::check()
似乎无法正确识别load(system.file(...))
命令。同样,它无法识别我是否拼写出文件名(即,不要使用system.file()
)。忽略load命令也不起作用。tests/
:testthat.R
library(synthACS)
library(testthat)
test_check("synthACS")
testthat/setup-testdata.R
中包含一行:
load(system.file("testdata", 'dat-acsdata.Rda', package= "synthACS"))
# run interactively, this line of code loads the data accurately.
# within devtools::check() it appears to return an empty string ("") for
# file location
R> devtools::test(synthACS)
══ Results ═════════════════════════
OK: 388
Failed: 0
Warnings: 0
Skipped: 0
R> devtools::check(synthACS)
...
─ checking tests ...
E Running ‘testthat.R’ (1.5s)
── Test failures ─────────────────────
> library(testthat)
>
> load(system.file("testdata", 'acsdata.rda', package= "synthACS"))
> test_check("synthACS")
----------- FAILURE REPORT --------------
... indicates that the data is not loaded ...
任何帮助表示赞赏!
R CMD检查并不关心/ tests目录中的内容,只要有一个文件可以运行以执行您的测试即可(它们通过了)。同样,testthat不在乎/ tests下的其他目录。因此,您可以将文件放在/ tests / resources中的目录中。