Skip to contents

Given a Knowledge object, return a single string containing the R code (using knowledge(), tier(), %-->%, and %!-->%. that would rebuild that same object.

Usage

deparse_knowledge(kn, df_name = NULL)

Arguments

kn

A Knowledge object.

df_name

Optional name of the data frame you used (used as the first argument to knowledge()). If NULL, knowledge() is called with no data frame.

Value

A single string (with newlines) of R code.

Examples

# turn a Knowledge object back into DSL code
data(tpc_example)

kn <- knowledge(
  tpc_example,
  tier(
    child ~ starts_with("child"),
    youth ~ starts_with("youth"),
    old ~ starts_with("old")
  ),
  child_x1 %-->% youth_x3,
  oldage_x6 %!-->% child_x1
)

code <- deparse_knowledge(kn, df_name = "tpc_example")
cat(code)
#> knowledge(tpc_example,
#>   tier(
#>     child ~ child_x1 + child_x2,
#>     youth ~ youth_x3 + youth_x4,
#>     old ~ oldage_x5 + oldage_x6
#>   ),
#>   child_x1 %-->% youth_x3,
#>   oldage_x6 %!-->% child_x1
#> )

# Explicitly add all forbidden edges implied by tiers
kn <- convert_tiers_to_forbidden(kn)
code <- deparse_knowledge(kn, df_name = "tpc_example")
cat(code)
#> knowledge(tpc_example,
#>   child_x1 %-->% youth_x3,
#>   oldage_x5 %!-->% c(child_x1, child_x2, youth_x3, youth_x4),
#>   oldage_x6 %!-->% c(child_x1, child_x2, youth_x3, youth_x4),
#>   youth_x3 %!-->% c(child_x1, child_x2),
#>   youth_x4 %!-->% c(child_x1, child_x2)
#> )