简体   繁体   English

R 测试结果与使用 Rscript 运行测试文件不同

[英]R testthat results differ from running test file with Rscript

I am new to programming in R and have come across a baffling issue with testthat and Rscript.我是 R 编程的新手,遇到了 testthat 和 Rscript 的一个令人困惑的问题。

I have a test file, call it test.R , that contains a bunch of testthat::test_that("test_name", {testthat::expect ...}) statements.我有一个测试文件,称为test.R ,其中包含一堆testthat::test_that("test_name", {testthat::expect ...})语句。 If I run Rscript test.R , or if I just paste the statements from the test into the R console and manually check that the expect would pass, everything works as expected and my tests seem to succeed.如果我运行Rscript test.R ,或者如果我只是将测试中的语句粘贴到 R 控制台中并手动检查expect是否通过,一切都按预期进行,我的测试似乎成功了。

However, if I use library(devtools); devtools::test()但是,如果我使用library(devtools); devtools::test() library(devtools); devtools::test() , there is a failing test with a subscript out of bounds error. library(devtools); devtools::test() ,有一个带有下标越界错误的失败测试。

I haven't included any specific code because I'm not looking to try to debug the particular error, but rather hope to understand how this is possible.我没有包含任何特定的代码,因为我不想尝试调试特定的错误,而是希望了解这是如何可能的。 Would testthat be running a different version? testthat会运行不同的版本吗? Is there differing behaviour between Rscript and the R console compared to what testthat would run under?是否有不同的之间的行为Rscript和R控制台相比有什么testthat会下运行?

FWIW, I experienced the same problem. FWIW,我遇到了同样的问题。

In my case, the objects created in the script were not exactly the same as those created in a test helper file, so the tests were receiving slightly different information to the script, and hence were returning different results.就我而言,脚本创建的对象测试helper文件中创建的对象并不完全相同,因此测试接收到的信息与脚本略有不同,因此返回不同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM