Learn R Programming

caugi (version 1.0.0)

to_mermaid: Export caugi Graph to Mermaid Format

Description

Converts a caugi graph to the Mermaid flowchart format as a string. Mermaid diagrams can be rendered in Quarto, R Markdown, GitHub, and many other platforms.

Usage

to_mermaid(x, direction = "TD")

Value

A caugi_mermaid object containing the Mermaid representation.

Arguments

x

A caugi object.

direction

Graph direction: "TB" (top-bottom), "TD" (top-down), "BT" (bottom-top), "LR" (left-right), or "RL" (right-left). Default is "TD".

Details

The function handles different edge types:

  • Directed edges (-->) use --> in Mermaid

  • Undirected edges (---) use --- in Mermaid

  • Bidirected edges (<->) use <--> in Mermaid

  • Partial edges (o->) use o--> in Mermaid (circle end)

Node names are automatically escaped if they contain special characters.

See Also

Other export: caugi_deserialize(), caugi_dot(), caugi_export(), caugi_graphml(), caugi_mermaid(), caugi_serialize(), export-classes, format-caugi, format-dot, format-graphml, format-mermaid, knit_print.caugi_export, read_caugi(), read_graphml(), to_dot(), to_graphml(), write_caugi(), write_dot(), write_graphml(), write_mermaid()

Examples

Run this code
cg <- caugi(
  A %-->% B + C,
  B %-->% D,
  C %-->% D,
  class = "DAG"
)

# Get Mermaid string
mmd <- to_mermaid(cg)
mmd@content

# With custom direction
mmd <- to_mermaid(cg, direction = "LR")

Run the code above in your browser using DataLab