Skip to contents

Cleans the value columns of a scenario's interpolated parameters: values whose magnitude is below tol become exactly 0, and digits, when given, rounds the rest.

Usage

round_scenario(
  x,
  digits = NULL,
  tol = .tiny_value_tol(),
  verbose = isVerbose()
)

# S4 method for class 'scenario'
round(x, digits = 0)

Arguments

x

a scenario (interpolated).

digits

integer, decimal places for the value columns; NULL (default) leaves precision alone.

tol

numeric, values with 0 < |value| < tol become 0. Defaults to the energyRt.tiny_value_tol option (1e-12); NULL or 0 strips nothing.

verbose

reporting level; see isVerbose().

...

unused, for the generic.

Value

the scenario, with its parameters cleaned.

Details

A tiny non-zero value is harder for a solver than the zero it stands for: an exact zero bound lets presolve fix a variable, 1e-20 does not. The case this exists for is a constraint built by an older energyRt with newConstraint(replace_zerros = 1e-20), whose zero right-hand sides – and whose written parameter default – carry that value. interpolate_model() reports such values through validate_scenario_parameters()'s tiny_value check; this acts on them, on a scenario already built, with no rebuild.

Rounding is not free: it changes the model. Both arguments are therefore explicit, and what changed is reported and recorded in @misc$rounded.

Examples

if (FALSE) { # \dontrun{
scen <- interpolate_model(mod, name = "BASE")
scen <- round(scen)                    # strip values below 1e-12
scen <- round(scen, digits = 6)        # ... and round the rest
} # }