rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

feat: make graph constructors default to undirected for consistency

Open Copilot opened this issue 4 months ago • 0 comments

Graph constructors were inconsistent - some defaulted to directed (make_tree, make_star, make_graph) while most defaulted to undirected (sample_gnm, make_ring, make_full_graph). This creates unnecessary confusion.

Changes

  • make_tree(): Now defaults to mode = "undirected" (was "out")
  • make_star(): Now defaults to mode = "undirected" (was "in")
  • make_graph(): Now defaults to directed = FALSE (was TRUE)
  • Fixed bug where make_graph() ignored its default directed parameter when using numeric edge vectors
  • Updated deprecated aliases (graph(), graph.tree(), graph.star()) to match

Before/After

# Before (v1.x)
g <- make_tree(10)      # directed tree (mode = "out")
s <- make_star(5)       # directed star (mode = "in")  
m <- make_graph(1:10)   # directed graph

# After (v2.0)
g <- make_tree(10)      # undirected tree
s <- make_star(5)       # undirected star
m <- make_graph(1:10)   # undirected graph

# Directed graphs still available by explicit request
g <- make_tree(10, mode = "out")
s <- make_star(5, mode = "in")
m <- make_graph(1:10, directed = TRUE)

Breaking Change

This is a breaking change for v2.0. Code relying on implicit directed defaults must be updated to explicitly specify directed = TRUE or mode = "in"/"out".

Original prompt

This section details on the original issue you should resolve

<issue_title>Graph constructors are inconsistent in whether they create directed or undirected graphs</issue_title> <issue_description>Some graph constructors create directed graphs by default, some create undirected ones, even when they can create either. This is confusing. Can we make the default undirected for all graph constructors in 2.0, when this makes sense? Opinions?

Examples

  • These are all undirected by default, even though they can create directed graphs as well: sample_gnm, make_ring, make_chordal_ring, make_full_graph, make_bipartite_graph (!) ...
  • These are all directed by default, even though they can create undirected graphs as well: make_tree, make_star, make_graph (!, compare make_bipartite_graph), ...
  • Of course, there are cases when there is only one reasonable choice for the directedness. make_kautz must be directed, make_from_prufer must be undirected, make_line_graph must follow the directness of its argument, make_directed_graph and make_undirected_graph must follow their naming, etc.

</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes igraph/rigraph#519

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Oct 28 '25 21:10 Copilot