From f95501d757bd4524575fa908d3a5423391747cc8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Mar 2026 18:46:55 +0000 Subject: [PATCH 1/3] Initial plan From 9ef31a9cec89b3ed793424da30988f1ca17f2621 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Mar 2026 19:02:58 +0000 Subject: [PATCH 2/3] perf: speed up .apply_modifiers in make.R, removing TODO comments Agent-Logs-Url: https://github.com/igraph/rigraph/sessions/6623329c-8d18-4af2-ad47-a28ac5c5fbd8 Co-authored-by: schochastics <17147355+schochastics@users.noreply.github.com> --- R/make.R | 67 +++++++++++++++-------------- tests/testthat/_snaps/attributes.md | 16 +++++++ tests/testthat/test-attributes.R | 10 +++++ 3 files changed, 61 insertions(+), 32 deletions(-) diff --git a/R/make.R b/R/make.R index 3c38e65b71d..ae223235e35 100644 --- a/R/make.R +++ b/R/make.R @@ -844,19 +844,9 @@ graph.atlas <- function(n) { .apply_modifiers <- function(graph, mods) { for (m in mods) { if (m$id == "without_attr") { - ## TODO: speed this up - ga <- graph_attr_names(graph) - va <- vertex_attr_names(graph) - ea <- edge_attr_names(graph) - for (g in ga) { - graph <- delete_graph_attr(graph, g) - } - for (v in va) { - graph <- delete_vertex_attr(graph, v) - } - for (e in ea) { - graph <- delete_edge_attr(graph, e) - } + graph.attributes(graph) <- setNames(list(), character()) + vertex.attributes(graph) <- setNames(list(), character()) + edge.attributes(graph) <- setNames(list(), character()) } else if (m$id == "without_loops") { graph <- simplify(graph, remove.loops = TRUE, remove.multiple = FALSE) } else if (m$id == "without_multiples") { @@ -865,31 +855,44 @@ graph.atlas <- function(n) { graph <- simplify(graph) } else if (m$id == "with_vertex_") { m$args <- lapply(m$args, eval) - ## TODO speed this up - for (a in seq_along(m$args)) { - n <- names(m$args)[a] - v <- m$args[[a]] - stopifnot(!is.null(n)) - graph <- set_vertex_attr(graph, n, value = v) + stopifnot(!is.null(names(m$args))) + vattrs <- vertex.attributes(graph) + n <- vcount(graph) + for (nm in names(m$args)) { + v <- m$args[[nm]] + if (length(v) == 1) { + vattrs[[nm]] <- rep(unname(v), n) + } else if (length(v) == n) { + vattrs[[nm]] <- unname(v) + } else { + cli::cli_abort( + "Length of new attribute value must be 1 or {n}, the number of target vertices, not {length(v)}." + ) + } } + vertex.attributes(graph) <- vattrs } else if (m$id == "with_edge_") { m$args <- lapply(m$args, eval) - ## TODO speed this up - for (a in seq_along(m$args)) { - n <- names(m$args)[a] - v <- m$args[[a]] - stopifnot(!is.null(n)) - graph <- set_edge_attr(graph, n, value = v) + stopifnot(!is.null(names(m$args))) + eattrs <- edge.attributes(graph) + n <- ecount(graph) + for (nm in names(m$args)) { + v <- m$args[[nm]] + if (length(v) == 1) { + eattrs[[nm]] <- rep(unname(v), n) + } else if (length(v) == n) { + eattrs[[nm]] <- unname(v) + } else { + cli::cli_abort( + "Length of new attribute value must be 1 or {n}, the number of target edges, not {length(v)}." + ) + } } + edge.attributes(graph) <- eattrs } else if (m$id == "with_graph_") { m$args <- lapply(m$args, eval) - ## TODO speed this up - for (a in seq_along(m$args)) { - n <- names(m$args)[a] - v <- m$args[[a]] - stopifnot(!is.null(n)) - graph <- set_graph_attr(graph, n, value = v) - } + stopifnot(!is.null(names(m$args))) + graph.attributes(graph) <- modifyList(graph.attributes(graph), m$args) } } diff --git a/tests/testthat/_snaps/attributes.md b/tests/testthat/_snaps/attributes.md index 172c445888a..98ec946572c 100644 --- a/tests/testthat/_snaps/attributes.md +++ b/tests/testthat/_snaps/attributes.md @@ -1,3 +1,19 @@ +# with_vertex_ + + Code + make_(from_literal(A - A:B:C, B - A:B:C), with_vertex_(color = 1:2)) + Condition + Error in `.apply_modifiers()`: + ! Length of new attribute value must be 1 or 3, the number of target vertices, not 2. + +# with_edge_ + + Code + make_(from_literal(A - A:B:C, B - A:B:C), with_edge_(color = 1:2)) + Condition + Error in `.apply_modifiers()`: + ! Length of new attribute value must be 1 or 3, the number of target edges, not 2. + # error messages work Code diff --git a/tests/testthat/test-attributes.R b/tests/testthat/test-attributes.R index bf54e2ae311..3d614cc2455 100644 --- a/tests/testthat/test-attributes.R +++ b/tests/testthat/test-attributes.R @@ -379,6 +379,11 @@ test_that("with_vertex_", { expect_identical_graphs(g1, g2) expect_equal(V(g2)$color, rep("red", gorder(g2))) expect_equal(V(g2)$foo, paste0("xx", 1:3)) + + expect_snapshot( + make_(from_literal(A - A:B:C, B - A:B:C), with_vertex_(color = 1:2)), + error = TRUE + ) }) @@ -398,6 +403,11 @@ test_that("with_edge_", { expect_identical_graphs(g1, g2) expect_equal(E(g1)$color, E(g2)$color) expect_equal(E(g1)$foo, E(g2)$foo) + + expect_snapshot( + make_(from_literal(A - A:B:C, B - A:B:C), with_edge_(color = 1:2)), + error = TRUE + ) }) From 7adb10eb953645b2f5fd3464a1c6377579852336 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Apr 2026 15:18:45 +0000 Subject: [PATCH 3/3] fix: replace setNames and modifyList with base R equivalents to avoid NAMESPACE NOTEs Agent-Logs-Url: https://github.com/igraph/rigraph/sessions/dc1d94b4-1708-4b04-b5a1-5419a36aa82e Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- R/make.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/make.R b/R/make.R index ae223235e35..672123ede2e 100644 --- a/R/make.R +++ b/R/make.R @@ -844,9 +844,9 @@ graph.atlas <- function(n) { .apply_modifiers <- function(graph, mods) { for (m in mods) { if (m$id == "without_attr") { - graph.attributes(graph) <- setNames(list(), character()) - vertex.attributes(graph) <- setNames(list(), character()) - edge.attributes(graph) <- setNames(list(), character()) + graph.attributes(graph) <- structure(list(), names = character(0)) + vertex.attributes(graph) <- structure(list(), names = character(0)) + edge.attributes(graph) <- structure(list(), names = character(0)) } else if (m$id == "without_loops") { graph <- simplify(graph, remove.loops = TRUE, remove.multiple = FALSE) } else if (m$id == "without_multiples") { @@ -892,7 +892,7 @@ graph.atlas <- function(n) { } else if (m$id == "with_graph_") { m$args <- lapply(m$args, eval) stopifnot(!is.null(names(m$args))) - graph.attributes(graph) <- modifyList(graph.attributes(graph), m$args) + graph.attributes(graph) <- modify_list(graph.attributes(graph), m$args) } }