'Idiomatic test for file/directory creation
Say I have a function that creates a directory and file:
foo <- function(){
dir.create("bar")
file.create("./bar/myfile.txt")
}
I need to test that the function does its job. I can do this with expect_true from the testthat package, like so:
test_that("File & directory are created",{
foo()
expect_true(file.exists("./bar/myfile.txt"))
})
This seems to work okay, but my question is what is the idiomatic way of testing for file/directory creation using testthat? There are specific functions for other side effects (e.g., expect_output), but I haven't found an equivalent for files/directories.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
