我正在使用testthat
包与我正在开发的R包一起运行单元测试。我遇到了一个奇怪的情况,我无法弄清楚我做错了什么。我试图加载一些测试数据(存储在数据框中)和一些预先计算的答案(再次存储在数据框中)来测试一些函数并比较结果。我已经将两组数据都保存为.Rdata文件(在tests/testthat /目录中),并且在我运行测试前加载它们。load(file.path('filename.RData'))
在travis的testthat测试中使用load()加载.RData文件中的数据
当我在我的计算机上运行测试时,测试运行良好。但是,当他们在特拉维斯跑,我得到的错误:
> test_check("mocapGrip")
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
Calls: test_check ... force -> source_file -> eval -> eval -> load -> readChar
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
cannot open compressed file 'extractedMarkerData.Rdata', probable reason 'No such file or directory'
我肯定失去了一些东西很简单,但我已经尝试了所有的明显的事情(从目录等开始指定相对路径)有没有人有关于如何让Travis能够加载这些文件的任何想法?
这里是违规的内容testthat文件:
library(mocapGrip)
context("distance calculationss")
load(file.path('extractedMarkerData.Rdata')) # markerDataHead
load(file.path('dist57.RData')) # dist57head
load(file.path('meanData.Rdata')) # meanDataHead
test_that("calculateDistances returns the correct distances", {
expect_equal(mocapGrip:::calculateDistances(markerDataHead, c(5,7)), dist57head)
})
test_that("meanOnAxis returns the correct distances", {
expect_equal(mocapGrip:::meanOnAxis(markerDataHead, c(0, 1, 2, 3, 4), axis ="Y"), meanDataHead)
})
用'getwd()'检查你的工作目录,并确保你正在加载的'.Rdata'文件在目录中(使用'list.files()'来检查)。另外,尝试函数加载为'load(file ='extractedMarkerData.Rdata')' –
我已经尝试添加这些来诊断travis的检查,并且看起来这些文件*在工作目录中是*,但对于某些原因R无法访问它们(再次,当我在我的计算机上运行测试时,这种方式工作正常,但当它们在特拉维斯上运行时不起作用)。这里是[travis日志](https://travis-ci.org/jonkeane/mocapGrip/builds/125995784#L1567-L1580) –