I am using Hadley's testthat-based approach for automated testing of my package.
Within this approach, what is the most suited place to put test data files? I mean 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).
Have any best practices crystallized so far?
The Data chapter of the same R-Pkgs book says "it’s ok to put small files directly in your test directory". That's what I've done in the past. And it sounds like that's what you're already doing, plus the
testdata
directory.Lifting from Ben Bolker's comments:
The advantage of this method:
inst
are installed is long-standing canonical R practice; it seems safer thatsystem.file("testdata", "some_file")
will always work than that../testdata/some_file
will do. I've had bad experiences using relative file paths when doingR CMD check
.Package Directory and File Structure:
testthat.R
helper_myfunc1.R contains data for testing myfunc1 function
helper_myfunc2.R contains data for testing myfunc2 function
test_pkg_name.R contains tests for functions and other objects in the package
Conduct unit testing