feat: make graph constructors default to undirected for consistency
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 tomode = "undirected"(was"out") -
make_star(): Now defaults tomode = "undirected"(was"in") -
make_graph(): Now defaults todirected = FALSE(wasTRUE) - Fixed bug where
make_graph()ignored its defaultdirectedparameter 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(!, comparemake_bipartite_graph), ...- Of course, there are cases when there is only one reasonable choice for the directedness.
make_kautzmust be directed,make_from_prufermust be undirected,make_line_graphmust follow the directness of its argument,make_directed_graphandmake_undirected_graphmust 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.