Quickly create a series of two‐sided formulas for use with tier(),
where each formula maps a numeric tier index to a tidyselect specification
that contains the placeholder i. The placeholder i is replaced
by each element of tiers in turn, allowing you to write a single
template rather than many nearly identical formulas.
Arguments
- tiers
An integer vector of tier indices (each >= 1). These will appear as the left‐hand sides of the generated formulas.
- vars
A tidyselect specification (unevaluated) that must contain the special placeholder
i, either as the symbolior inside a string like"…{i}…". For each value ofiintiers, that placeholder will be substituted and the resulting call used as the right‐hand side of a formula.
Value
A list of two‐sided formulas, each of class "tier_bundle".
You can pass this list directly to tier() (which will expand it
automatically).
See also
Other knowledge functions:
+.Knowledge(),
add_exogenous(),
add_tier(),
add_to_tier(),
add_vars(),
as_bnlearn_knowledge(),
as_pcalg_constraints(),
as_tetrad_knowledge(),
convert_tiers_to_forbidden(),
deparse_knowledge(),
forbid_edge(),
get_tiers(),
knowledge(),
knowledge_to_caugi(),
remove_edge(),
remove_tiers(),
remove_vars(),
reorder_tiers(),
reposition_tier(),
require_edge(),
unfreeze()
Examples
# generate a bundle of tier formulas using a pattern with {i}
# here we create: 1 ~ matches("^child_x1$"), 2 ~ matches("^child_x2$")
data(tpc_example)
kn <- knowledge(
tpc_example,
tier(seq_tiers(1:2, matches("^child_x{i}$")))
)
print(kn)
#>
#> ── Knowledge object ────────────────────────────────────────────────────────────
#>
#> ── Tiers ──
#>
#> tier
#> <chr>
#> 1 1
#> 2 2
#> ── Variables ──
#>
#> var tier
#> <chr> <chr>
#> 1 child_x1 1
#> 2 child_x2 2
#> 3 oldage_x5 NA
#> 4 oldage_x6 NA
#> 5 youth_x3 NA
#> 6 youth_x4 NA
