Skip to contents

Converts a caugi graph to the GraphML XML format as a string. GraphML is widely supported by graph analysis tools and libraries.

Usage

to_graphml(x)

Arguments

x

A caugi object.

Value

A caugi_graphml object containing the GraphML representation.

Details

The GraphML export includes:

  • Node IDs and labels

  • Edge types stored as a custom edge_type attribute

  • Graph class stored as a graph-level attribute

Edge types are encoded using the caugi DSL operators (e.g., "–>", "<->"). This allows for perfect round-trip conversion back to caugi.

Examples

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

# Get GraphML string
graphml <- to_graphml(cg)
cat(graphml@content)
#> <?xml version="1.0" encoding="UTF-8"?>
#> <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
#>   <key id="edge_type" for="edge" attr.name="edge_type" attr.type="string"/>
#>   <key id="graph_class" for="graph" attr.name="graph_class" attr.type="string"/>
#>   <graph id="G" edgedefault="directed">
#>     <data key="graph_class">DAG</data>
#>     <node id="A"/>
#>     <node id="B"/>
#>     <node id="C"/>
#>     <node id="D"/>
#>     <edge source="A" target="B">
#>       <data key="edge_type">--&gt;</data>
#>     </edge>
#>     <edge source="A" target="C">
#>       <data key="edge_type">--&gt;</data>
#>     </edge>
#>     <edge source="B" target="D">
#>       <data key="edge_type">--&gt;</data>
#>     </edge>
#>     <edge source="C" target="D">
#>       <data key="edge_type">--&gt;</data>
#>     </edge>
#>   </graph>
#> </graphml>

# Write to file
if (FALSE) { # \dontrun{
write_graphml(cg, "graph.graphml")
} # }