Renders a digraph view of a theory without leaving R. Where tf_diagram()
returns the deterministic Graphviz DOT string, tf_render_diagram() passes
that string to the DiagrammeR engine and returns either an interactive
widget, which displays in the RStudio viewer and in R Markdown documents, or
a standalone SVG string, ready to embed in a page or save to a file.
Usage
tf_render_diagram(x, type = "nomological_net", as = c("widget", "svg"))Arguments
- x
A theory object (named list), or a diagram IR string from
tf_diagram()ortf_lit_diagram(), so literature diagrams render the same way.- type
The diagram type, as in
tf_diagram(). Ignored whenxis already an IR string.- as
Either
"widget"(default), an htmlwidget for the viewer and for R Markdown, or"svg", a standalone SVG string.
Details
The three chart views (venn, rigour and severity) are already SVG, so
they are returned as-is under as = "svg" and wrapped for display under
as = "widget". The causal_dag view emits dagitty syntax rather than DOT,
so it is not rendered here; paste it into a dagitty tool or the dagitty R
package instead.
See also
tf_diagram() for the intermediate representation itself, which
needs no optional packages and stays byte-identical across the R and
Python implementations.
Examples
theory <- tf_theory("demo-1", "A demonstration theory") |>
tf_add_construct("c_arousal", "Arousal", "Bodily activation.") |>
tf_add_construct("c_threat", "Perceived threat", "Appraised danger.") |>
tf_add_proposition("p1", "c_arousal", "c_threat", "causes")
tf_render_diagram(theory, "nomological_net")