A change is tested on small samples before a heavy rerun, and a test must
never overwrite the real outputs. Projects switch a test mode on with an R
option <prefix>.test_mode (e.g. options(cb.test_mode = TRUE)), and
read and write through these helpers:
is_test_mode()tells whether the test mode is on;output_path()sends an output to atest/subfolder in test mode;input_file()reads the test version of an input when it exists in test mode, and the real one otherwise.
Usage
is_test_mode(prefix)
output_path(path, prefix, test_dir = "test")
input_file(path, prefix, test_dir = "test")See also
Other test mode:
cap_items()
Examples
out <- file.path(tempdir(), "matches.csv")
output_path(out, prefix = "project")
#> [1] "/tmp/RtmpKqItGK/matches.csv"
withr::with_options(list(project.test_mode = TRUE), {
print(is_test_mode("project"))
output_path(out, prefix = "project")
})
#> [1] TRUE
#> [1] "/tmp/RtmpKqItGK/test/matches.csv"