I am working on an R package, using testthat package to automate tests (à la Hadley).

Part of the tests need to access a set of files, stored into the package under folder inst/testdata (see Where should I put data for automated tests with testthat?).

What is the good practice to do so, as I wish to factor the code and to reuse it from test to test ?

According to https://www.tidyverse.org/articles/2017/12/testthat-2-0-0/, I should create a setup-xyz.R function in the test/testthat folder, where xyz stands for a function name.

If my subset of tests is large (hundreds of tests) this ends up not to be really practiceable. Any proven smart solution suggestion ?

setup( {
lf <- list.files('../../inst/testdata', all.files = TRUE, full.names = TRUE)
}
)

0 Answers