feat: accept two-column matrices/data frames in edge functions (#1827)#2700
Open
schochastics wants to merge 5 commits into
Open
feat: accept two-column matrices/data frames in edge functions (#1827)#2700schochastics wants to merge 5 commits into
schochastics wants to merge 5 commits into
Conversation
Extend the n×2 matrix / two-column data frame edge specification that `get_edge_ids()` already supports (via `el_to_vec()`) to the other functions that take edges as pairs of vertices: - `add_edges()` / `delete_edges()` - `edge()` / `edges()` (via the `+` and `-` operators) - `make_graph()` (and `make_directed_graph()` / `make_undirected_graph()`) - `E(graph, P = )` For all of these an n×2 matrix or two-column data frame is now the natural edge-list form; 2×n and 2×2 matrices are deprecated (defunct), consistent with `get_edge_ids()`. This resolves the counterintuitive transposition requirement from #550. `make_graph()` previously accepted a matrix but flattened it column-major, so a plain n×2 edge list produced the wrong graph and the transposed 2×n form was the working idiom; that interpretation is now corrected. Internal callers that passed 2×n matrices (graph_from_edgelist, graph_from_data_frame, incidence/adjacency constructors, indexing) are updated to pass explicit flat vectors. `el_to_vec()` gains `arg`/`fn` parameters so error messages name the correct function. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 713cdd8 is merged into main:
|
The `distances()` roxygen example passed `t(el[, 1:2])` (a 2×n matrix) to `add_edges()`, relying on the old column-major flattening. Since 2×n matrices are now defunct, pass the n×2 matrix `el[, 1:2]` directly, which produces the same graph. Fixes the R CMD check example failure. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if be3d283 is merged into main:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1827.
get_edge_ids()was changed in #1663 to accept the natural edge-list forms — an n×2 matrix or a two-column data frame — via theel_to_vec()helper. This PR applies the same treatment to the other functions that take edges as pairs of vertices, so the same edge list can be passed everywhere with no manual transposition (the core complaint in #550):add_edges()/delete_edges()edge()/edges()(via the+and-operators)make_graph()(andmake_directed_graph()/make_undirected_graph())E(graph, P = )For all of these, an n×2 matrix or two-column data frame is now the canonical edge-list form. 2×n and 2×2 matrices are deprecated (defunct), consistent with
get_edge_ids().make_graph()(please read)Unlike the other functions,
make_graph()already accepted a matrix — but it flattened it column-major. The practical consequences:as_edgelist(g)) silently produced the wrong graph.t(edgelist)) was the working idiom.This PR makes the n×2 matrix the correct, canonical form and turns the 2×n form into a defunct error. This is a breaking change: code relying on
make_graph(t(el))must now passmake_graph(el)(n×2) directly. This is intentional and is exactly what #550 asked for, but it is more disruptive than for the other functions, which previously errored or mis-handled matrices rather than silently accepting a transposed one.Implementation notes
el_to_vec()gainsarg/fnparameters so error/deprecation messages name the calling function (e.g. "theedgesargument ofadd_edges()"). Defaults preserve the existingget_edge_idswording, so existing snapshots are unchanged.is.data.frame(x) || inherits(x, "matrix")before normalizing, so vectors andigraph.vs/igraph.essequences keep their existing behavior.delete_edges()converts a matrix/df of vertex pairs to edge IDs viaget_edge_ids(..., error = TRUE)(itsedgesarg is an edge selector, not a vertex sequence), preserving numeric-edge-id and"a|b"semantics for vectors.c(...)):graph_from_edgelist(),graph_from_data_frame(), the incidence/adjacency constructors, and[<-indexing. (graph_from_data_frame()was in fact already broken by theadd_edgeschange and is fixed here.)Tests
Added matrix/data-frame acceptance, vector/
igraph.vsback-compat, 2×n/2×2 rejection, andas_edgelist()round-trip (#550) cases acrosstest-interface.R,test-operators.R,test-make.R, andtest-iterators.R. Updatedtest-conversion.Rto use the now-natural n×2 form.Full suite: 1553 test groups, 0 failures, 0 errors. No snapshot changes.
🤖 Generated with Claude Code