end_if_fake_scenario() ends a run script after save_results() when the
scenario is not "real". The part of the script after it is for the real
data only, for example the figures.
Details
Call it directly after save_results() in vNN_run.R. It reads the
scenario that the last initialize_project() call set:
For
"real", it does nothing, and the script continues.For a fake scenario in a non-interactive R session, for example under
Rscriptorrun_scenarios(), it quits R with status 0. No line after it runs.For a fake scenario in an interactive R session, it stops with an error of class
pbn_end_if_fake_scenario. The R session stays open.
It stops with an error when no initialize_project() call set a
scenario in this R session.
See also
Other project setup:
initialize_project(),
run_scenarios(),
use_scenario()
Examples
home <- file.path(tempdir(), "pbn_end_example")
dir.create(file.path(home, "v01_functions"), recursive = TRUE)
dir.create(file.path(home, "data"))
writeLines(
"CFG <- list(scenarios = data.frame(scenario = 'real', sims = 1))",
file.path(home, "v01_functions", "_cfg.R")
)
pbn::initialize_project("v01", home, file.path(home, "data"), env = new.env())
#> You are NOT sourcing into .GlobalEnv. All functions will be sourced into an environment that is returned from this function.
#> Sourcing all code inside /tmp/RtmpOG2SVD/pbn_end_example/v01_functions into
pbn::end_if_fake_scenario()
unlink(home, recursive = TRUE)
