
Point a saved scenario at another model in the model store
Source:R/save-scenario.R
relink_scenario.RdA scenario saved by reference records the name, hash and path of a sealed
model version instead of a copy of the model (see save_scenario()).
relink_scenario() rewrites that reference in the saved scenario, without
reading its parameters or its solution: the repair for a reference that no
longer resolves (the model was renamed, moved or deleted), and the way to
adopt another version of the model.
The saved scenario is first compared with the target model, as far as its
stored description goes: the regions, milestone years, timeframes and
timeslices the scenario uses have to exist in the model, and the names of
its commodities and processes are compared with the model's objects (a
derived name – a vintage, a cluster, a tier – counts as the object it
starts with). Parameter values are not compared. The differences are
listed in one warning, or in an error with strict = TRUE. A target that
is the recorded version itself, by name and hash, is not compared.
Usage
relink_scenario(
scenario,
model,
strict = FALSE,
dry_run = FALSE,
verbose = isVerbose()
)Arguments
- scenario
the saved scenario: its registered name, the path of its folder, or the scenario object – the forms
load_scenario()andseal_scenario()take.- model
the model to reference: the name of a model in the model store (
"name"for its current version,"name@hash8"for one of its versions), a model store directory, or a model object whose exact content is in the store.- strict
logical;
TRUEmakes differences between the scenario and the model an error, and nothing is rewritten.- dry_run
logical;
TRUEreports what would change and writes nothing.- verbose
logical.
Value
invisibly, a list: scenario (name) and path, the old and the
new reference (each name, hash, source, path), differences
(character, empty when none were found), written (the files rewritten,
or that would be with dry_run) and dry_run.
Details
Rewritten: the model: entry of scenario.yml, the model reference and
the recorded model identity inside the scenario file, the list of
dependents of the two model versions (the scenario leaves the old one and
joins the new one, see list_dependents()), and the scenario's registry
row. Nothing else in the scenario folder is touched.
Refused: a scenario whose inputs are sealed (unseal_scenario() first); a
scenario that embeds its model, which has no reference to rewrite
(load_scenario(model = ) opens it with another model); a model that is
not in the model store, or is there but not as a sealed version –
save_model() and seal_model() it first.
See also
check_scenario_models() lists the references that need repair;
load_scenario(model = ) opens a scenario with a chosen model and
changes nothing on disk.
Examples
if (FALSE) { # \dontrun{
open_project(tempdir())
repo <- newRepository("repo",
newCommodity("ELC", timeframe = "ANNUAL"),
newSupply("SUP", commodity = "ELC", supply = data.frame(cost = 1)),
newDemand("DEM", commodity = "ELC", demand = data.frame(demand = 1)))
mod <- newModel("MOD_A", region = "R1", horizon = newHorizon(2030),
repo = repo)
save_model(mod)
seal_model("MOD_A")
scen <- interpolate_model(mod, name = "BASE")
scen <- save_scenario(scen) # references MOD_A
# the same model, stored under another name
mod@name <- "MOD_B"
save_model(mod)
seal_model("MOD_B")
relink_scenario("BASE", "MOD_B", dry_run = TRUE) # what would change
relink_scenario("BASE", "MOD_B")
list_dependents("MOD_B", type = "model")
} # }