Converts a caugi graph to the GraphML XML format as a string. GraphML is widely supported by graph analysis tools and libraries.
Details
The GraphML export includes:
Node IDs and labels
Edge types stored as a custom
edge_typeattributeGraph 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.
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_mermaid(),
write_caugi(),
write_dot(),
write_graphml(),
write_mermaid()
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">--></data>
#> </edge>
#> <edge source="A" target="C">
#> <data key="edge_type">--></data>
#> </edge>
#> <edge source="B" target="D">
#> <data key="edge_type">--></data>
#> </edge>
#> <edge source="C" target="D">
#> <data key="edge_type">--></data>
#> </edge>
#> </graph>
#> </graphml>
# Write to file
if (FALSE) { # \dontrun{
write_graphml(cg, "graph.graphml")
} # }