I am using Hadley's testthat-based approach for automated testing of my package.
With this approach, what is the most suitable place to put test data files that is files only used by the test scripts in tests/testthat), but not by any other functions in R/?
My current approach is to put them in tests/testdata
, and then read.table
from there with a relative path rather than with system.file (in order to avoid the need to install the package to run tests).
Is there a standard way to do this?
If at all possible, store the values in plain text files. The reason for this is so that you can put the data into version control along with the tests. Often a CSV file will do nicely, and there are likely plenty of CSV-reader libraries for whatever language you're using to automate tests.
Lifting from Ben Bolker's comments:
I use inst/testdata and then
system.file("testdata",...,package="my_package")
The advantage of this method:
inst
are installed is long-standing canonical R practice; it seems safer that system.file("testdata", "some_file")
will always work than that ../testdata/some_file
will do. I've had bad experiences using relative file paths when doing R CMD check
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With