Suppose I have test like this:
require(testthat)
context("toy test")
test_that("toy", {
df = my.read.file("test.txt", header=TRUE)
expect_true(myfunc(df) == 3.14)
})
and this test relies on a external file test.txt, where should I put this file then?
You put these in the testthat
folder (inside tests
). There, you include any "external" file that you might use for your tests (or that provides some additional explanation that the user might find informative, such as in a ".txt") file. You also have your .r
testfiles here.
Alternatively (or, in addition): you can also load your file from another location, by including the path to the file (e.g., to your data
folder--use a relative path). However, this can result in a fragile infrastructure, since you might not be able to rely on that external location to be available at all times, in which case testthat
will raise an error when it can not find the file.
An example of linking to a file outside of tests
, see here. Beware when you do this, though.
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