Skip to content

Conversation

schochastics
Copy link
Contributor

Fix #543

devtools::load_all("~/git/R_packages/rigraph")
#> ℹ Loading igraph
g <- make_ring(10)
write_graph(g, file = "", format = "graphml")
#> <?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">
#> <!-- Created by igraph -->
#>   <key id="g_name" for="graph" attr.name="name" attr.type="string"/>
#>   <key id="g_mutual" for="graph" attr.name="mutual" attr.type="boolean"/>
#>   <key id="g_circular" for="graph" attr.name="circular" attr.type="boolean"/>
#>   <graph id="G" edgedefault="undirected">
#>     <data key="g_name">Ring graph</data>
#>     <data key="g_mutual">false</data>
#>     <data key="g_circular">true</data>
#>     <node id="n0">
#>     </node>
#>     <node id="n1">
#>     </node>
#>     <node id="n2">
#>     </node>
#>     <node id="n3">
#>     </node>
#>     <node id="n4">
#>     </node>
#>     <node id="n5">
#>     </node>
#>     <node id="n6">
#>     </node>
#>     <node id="n7">
#>     </node>
#>     <node id="n8">
#>     </node>
#>     <node id="n9">
#>     </node>
#>     <edge source="n0" target="n1">
#>     </edge>
#>     <edge source="n1" target="n2">
#>     </edge>
#>     <edge source="n2" target="n3">
#>     </edge>
#>     <edge source="n3" target="n4">
#>     </edge>
#>     <edge source="n4" target="n5">
#>     </edge>
#>     <edge source="n5" target="n6">
#>     </edge>
#>     <edge source="n6" target="n7">
#>     </edge>
#>     <edge source="n7" target="n8">
#>     </edge>
#>     <edge source="n8" target="n9">
#>     </edge>
#>     <edge source="n0" target="n9">
#>     </edge>
#>   </graph>
#> </graphml>


s1 <- r"---(<?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">
<!-- Created by igraph -->
  <key id="g_name" for="graph" attr.name="name" attr.type="string"/>
  <key id="g_mode" for="graph" attr.name="mode" attr.type="string"/>
  <key id="g_center" for="graph" attr.name="center" attr.type="double"/>
  <graph id="G" edgedefault="directed">
    <data key="g_name">In-star</data>
    <data key="g_mode">in</data>
    <data key="g_center">1</data>
    <node id="n0">
    </node>
    <node id="n1">
    </node>
    <edge source="n1" target="n0">
    </edge>
  </graph>
</graphml>
)---"
g1 <- read_graph(s1, format = "graphml")
g1
#> IGRAPH c88e052 D--- 2 1 -- In-star
#> + attr: name (g/c), mode (g/c), center (g/n), id (v/c)
#> + edge from c88e052:
#> [1] 2->1

g <- make_ring(10)
s1 <- r"---(0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 0 9)---"
g1 <- read_graph(s1, format = "edgelist", directed = FALSE)
isomorphic(g, g1)
#> [1] TRUE

Created on 2025-07-09 with reprex v2.1.1

cc @ntamas @szhorvat @clpippel since you all were discussing this. I hope I understood the issue correctly and the implemented solution makes sense

@schochastics schochastics marked this pull request as draft July 9, 2025 13:05
@schochastics schochastics added this to the 2.3.0 milestone Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Be able to read and write to strings in read_igraph, write_igraph

1 participant