1

I have 3 rds files I use in my testthat tests. the files are in /tests/testthat/testdata/. When I run the tests with devtools::test(), the files can be found. When I use devtools::check(), the files won't be found. I have seen this issue discussed here and here and many other places but all the suggested solutions won't work for me. I tried adding the Sys.setenv(R_TESTS="") line at the top of my "testthat.R" file; I tried using here::here() from the package "here" instead of the , system.file() function, etc. What can I do?

Here is my test:

test_that("the test_arguments() returns errors as it should", {
  x <- readRDS(system.file("tests", "testthat", "testdata", "objectA.rds", package = "package"))
  y <- readRDS(system.file("tests", "testthat", "testdata", "objectB.rds", package = "package"))
  z <- readRDS(here::here("tests", "testthat", "testdata", "objectC.rds", package = "package"))

  expect_error(test_arguments(z, y), "X has to be an object of class SpatialPolygonsDataFrame")
  expect_error(test_arguments(x, z), "y has to be an object of class RasterLayer")
})

And here is the result of the devtools::check():

-- Error (test_user_input.R:3:3): the arguments are of the right class ---------------------
Error: cannot open the connection
Backtrace:
    x
 1. \-base::readRDS(here::here("tests", "testthat", "testdata", "objectA.rds")) test_user_input.R:3:2
 2.   \-base::gzfile(file, "rb")

[ FAIL 1 | WARN 1 | SKIP 0 | PASS 0 ]
Error: Test failures
Execution halted

1 error x | 1 warning x | 1 note x
  • 1
    It may be worth considering to store the data internally: https://r-pkgs.org/data.html#sec-data-sysdata – GTHB317 May 17 '23 at 11:12

0 Answers0