简体   繁体   中英

Using load() to load data from an .RData file during a testthat test on travis

I'm using the testthat package to run unit tests with an R package I'm developing. I've run into a weird situation that I can't quite figure out what I'm doing wrong.

I'm trying to load some test data (stored in dataframes) and some precomputed answers (again, stored in dataframes) to test some functions and compare the results. I've saved both sets of data as .Rdata files (in the tests/testthat/ directory), and I'm loading them in before I run the tests with load(file.path('filename.RData'))

When I run the tests on my computer, the tests run fine. But when they run on travis, I get the error:

> 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'

I'm surely missing something very simple, but I've tried all of the obvious things (specifying relative paths from the start of the directory, etc.) Does anyone have any ideas on how to get travis to be able to load these files?

Here's the contents of the offending testthat file:

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)
})

And it was indeed something simple: Case insensitive OS X was silently ignoring I had the wrong case (.Rdata vs. .RData) and the ubuntu system that travis is running is case sensitive so when searching for extractedMarkerData.RData, finding extractedMarkerData.Rdata did not work (as it shouldn't work, given that ubuntu is case sensitive). Fixed, and all is good now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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