Skip to content

Commit 8e04b91

Browse files
SebKrantzclaude
andcommitted
Rename simplify_network shortest-paths result attributes (breaking)
For consistency with the cluster method and consolidate_graph(): attr(result, "edges") -> attr(result, "keep.edges") attr(result, "edge_counts") -> attr(result, "edge.counts") Update docs, tests, and NEWS accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c2b46a1 commit 8e04b91

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030

3131
- The simplified graph returned by `method = "cluster"` now carries a `keep.edges` attribute containing the integer indices of the edges retained from the original graph.
3232

33+
## Result Attributes — Breaking Changes
34+
35+
- **`simplify_network(method = "shortest-paths")`**: the two result attributes have been renamed for consistency with the cluster method and `consolidate_graph()`:
36+
- `"edges"``"keep.edges"` (integer vector of retained edge indices)
37+
- `"edge_counts"``"edge.counts"` (traversal counts for each retained edge)
38+
Update any code that reads `attr(result, "edges")` or `attr(result, "edge_counts")`.
39+
3340
## Result Attributes
3441

3542
- The grouping/edge-tracking attributes attached to results are now consistent and documented. `consolidate_graph()` attaches `keep.edges` and `group.id` together (aligned, same length) for `recursive = "none"` or `"partial"`; with the default `recursive = "full"` they are omitted (the mapping would span multiple passes), which is now stated in the documentation. `create_undirected_graph()` now also exposes `group.id` and `group.sizes` (previously only `group.starts`, and undocumented), and `consolidate_graph()` strips any stale grouping attributes carried in from upstream operations.

R/utils.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,8 @@ compute_degrees <- function(from_vec, to_vec) {
10201020
#' \item For \code{method = "shortest-paths"}:
10211021
#' \itemize{
10221022
#' \item All columns from the input \code{graph_df} (for edges that were kept)
1023-
#' \item Attribute \code{"edges"}: integer vector of edge indices from the original graph
1024-
#' \item Attribute \code{"edge_counts"}: integer vector indicating how many times each edge was traversed
1023+
#' \item Attribute \code{"keep.edges"}: integer vector of edge indices from the original graph
1024+
#' \item Attribute \code{"edge.counts"}: integer vector indicating how many times each retained edge was traversed
10251025
#' }
10261026
#' \item For \code{method = "cluster"}:
10271027
#' \itemize{
@@ -1317,8 +1317,8 @@ simplify_network <- function(graph_df, nodes = NULL, method = c("shortest-paths"
13171317
if(verbose) cat(sprintf("Retained %d/%d edges traversed by shortest paths (%.1f%%)\n",
13181318
length(edges), fnrow(graph_df),
13191319
100 * length(edges) / fnrow(graph_df)))
1320-
attr(result, "edges") <- edges
1321-
attr(result, "edge_counts") <- edges_traversed[edges]
1320+
attr(result, "keep.edges") <- edges
1321+
attr(result, "edge.counts") <- edges_traversed[edges]
13221322

13231323
} else {
13241324

man/simplify_network.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-consolidation.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ test_that("simplify_network shortest-paths has edges attribute", {
464464
method = "shortest-paths",
465465
cost.column = "cost", verbose = FALSE)
466466

467-
expect_true(!is.null(attr(result, "edges")))
468-
expect_true(all(attr(result, "edges") <= nrow(graph)))
467+
expect_true(!is.null(attr(result, "keep.edges")))
468+
expect_true(all(attr(result, "keep.edges") <= nrow(graph)))
469469
})
470470

471471
test_that("simplify_network shortest-paths has edge_counts attribute", {
@@ -479,7 +479,7 @@ test_that("simplify_network shortest-paths has edge_counts attribute", {
479479
method = "shortest-paths",
480480
cost.column = "cost", verbose = FALSE)
481481

482-
edge_counts <- attr(result, "edge_counts")
482+
edge_counts <- attr(result, "edge.counts")
483483
expect_true(!is.null(edge_counts))
484484
expect_true(all(edge_counts > 0))
485485
})
@@ -540,8 +540,8 @@ test_that("simplify_network shortest-paths nthreads matches single-thread output
540540
nthreads = 2L, verbose = FALSE)
541541

542542
expect_identical(res_multi, res_single)
543-
expect_identical(attr(res_multi, "edges"), attr(res_single, "edges"))
544-
expect_identical(attr(res_multi, "edge_counts"), attr(res_single, "edge_counts"))
543+
expect_identical(attr(res_multi, "keep.edges"), attr(res_single, "keep.edges"))
544+
expect_identical(attr(res_multi, "edge.counts"), attr(res_single, "edge.counts"))
545545
})
546546

547547
test_that("consolidate_graph leaves pure cycles intact (no crash/hang, C == R)", {

0 commit comments

Comments
 (0)