View source: R/schema_helpers.R
| set_schema | R Documentation |
Constructs a validated fluxCore schema from a hybrid vars specification.
Each element of vars may be either a type-name string (e.g. "count") or
a fully-specified list (e.g. list(type = "positive_numeric", max = 20)).
Optionally merges onto an existing schema, with explicit overwrite and
remove controls.
set_schema(
vars = NULL,
schema = NULL,
remove = NULL,
overwrite = FALSE,
time_spec = NULL,
decision_points = NULL,
decision_groups = NULL
)
vars |
Named list (or character vector) of variable specs. Each element
is either a single type-name string or a list containing |
schema |
Optional existing schema to extend. If |
remove |
Optional character vector of variable names to remove from
|
overwrite |
Logical scalar. If |
time_spec |
Optional |
decision_points |
Optional list of |
decision_groups |
Optional list of |
When time_spec, decision_points, or decision_groups is supplied,
set_schema() returns a full schema list (with $variables,
$time_spec, $decision_points, and $decision_groups) suitable for direct
use with load_model(). When none is supplied, it returns just the validated
variables spec (backward-compatible with prior usage and with
Entity$new(schema = ...)).
A validated fluxCore variables spec (named list), or — when
time_spec, decision_points, or decision_groups is supplied — a full
schema list with $variables, $time_spec, $decision_points, and
$decision_groups.
# Variables only (backward-compatible):
vars <- set_schema(vars = list(
route_zone = list(type = "categorical",
levels = c("urban", "suburban", "rural")),
battery_pct = "percent",
payload_kg = list(type = "positive_numeric", max = 20),
deliveries = "count",
prob_rain = "probability"
))
# Full schema for load_model():
dp <- DecisionPoint(id = "dp1", trigger = "event_A",
allowed_actions = c("accept", "decline"))
schema <- set_schema(
vars = list(battery_pct = "percent"),
time_spec = time_spec(unit = "hours"),
decision_points = list(dp),
decision_groups = NULL
)
# Full schemas also contain schema$decision_groups (NULL here).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.