if (FALSE) {
# Old approach
tmp <- tempfile()
setup(writeLines("some test data", tmp))
teardown(unlink(tmp))
}
# Now recommended:
local_test_data <- function(env = parent.frame()) {
tmp <- tempfile()
writeLines("some test data", tmp)
withr::defer(unlink(tmp), env)
tmp
}
# Then call local_test_data() in your tests
Run the code above in your browser using DataLab