diff --git a/R/make.R b/R/make.R index 2abbe4a054..5abbd2172b 100644 --- a/R/make.R +++ b/R/make.R @@ -1819,7 +1819,7 @@ graph_from_literal_i <- function(mf) { ids <- seq(along.with = v) names(ids) <- v res <- make_graph(unname(ids[edges]), n = length(v), directed = directed) - if (simplify) { + if (simplify && !is_simple(res)) { res <- simplify(res) } res <- set_vertex_attr(res, "name", value = v) diff --git a/tests/testthat/_snaps/make.md b/tests/testthat/_snaps/make.md index 8fc69bf850..f8c8f1d350 100644 --- a/tests/testthat/_snaps/make.md +++ b/tests/testthat/_snaps/make.md @@ -63,7 +63,7 @@ IGRAPH UN-- 3 3 -- + attr: name (v/c) + edges (vertex names): - [1] A--B A--C B--C + [1] A--B B--C A--C # graph_from_literal() and undirected explosion @@ -112,7 +112,7 @@ IGRAPH DN-- 3 3 -- + attr: name (v/c) + edges (vertex names): - [1] A->B C->A C->B + [1] A->B C->B C->A # graph_from_literal() and directed explosion @@ -129,7 +129,7 @@ IGRAPH DN-- 13 19 -- + attr: name (v/c) + edges (vertex names): - [1] A->D A->E B->D B->E C->D C->E F->D F->E F->I G->D G->E G->I H->D H->E H->I + [1] A->D A->E B->D B->E C->D C->E F->D G->D H->D F->E G->E H->E F->I G->I H->I [16] J->I K->I L->I M->I # graph_from_literal(simplify = FALSE) diff --git a/tests/testthat/_snaps/structural-properties.md b/tests/testthat/_snaps/structural-properties.md index e006e10afc..b53681b46f 100644 --- a/tests/testthat/_snaps/structural-properties.md +++ b/tests/testthat/_snaps/structural-properties.md @@ -10,7 +10,8 @@ # bfs() works Code - g <- graph_from_literal(a - +b - +c, z - +a, d) + el <- structure(c("a", "b", "z", "b", "c", "a"), dim = 3:2) + g <- graph_from_edgelist(el) + vertex("d") bfs(g, root = 2, mode = "out", unreachable = FALSE, order = TRUE, rank = TRUE, parent = TRUE, pred = TRUE, succ = TRUE, dist = TRUE) Output diff --git a/tests/testthat/test-conversion.R b/tests/testthat/test-conversion.R index 5fddb5f12f..d5f9ff8d40 100644 --- a/tests/testthat/test-conversion.R +++ b/tests/testthat/test-conversion.R @@ -18,7 +18,8 @@ test_that("as_directed works", { }) test_that("as_directed keeps attributes", { - g <- graph_from_literal(A - B - C, D - A, E) + el <- structure(c("A", "A", "B", "B", "D", "C"), dim = 3:2) + g <- graph_from_edgelist(el, directed = FALSE) + vertex("E") g$name <- "Small graph" g_mutual <- as_directed(g, mode = "mutual") expect_equal(g_mutual$name, g$name) @@ -59,7 +60,11 @@ test_that("as.undirected() deprecation", { }) test_that("as_undirected() keeps attributes", { - g <- graph_from_literal(A +-+ B, A --+ C, C +-+ D) + el <- structure( + c("A", "A", "B", "C", "D", "B", "C", "A", "D", "C"), + dim = c(5L, 2L) + ) + g <- graph_from_edgelist(el, directed = TRUE) g$name <- "Tiny graph" E(g)$weight <- seq_len(ecount(g)) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 3083a8bbf7..fe0590a4b5 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -50,7 +50,13 @@ test_that("st_cuts() works", { expect_equal(unvs(all_cuts_path$cuts), list(1, 2, 3, 4)) expect_equal(unvs(all_cuts_path$partition1s), list(1, 1:2, 1:3, 1:4)) - g_star_v7 <- graph_from_literal(s -+ a:b -+ t, a -+ 1:2:3 -+ b) + el <- structure( + c( + "s", "s", "a", "a", "a", "a", "b", "1", "2", "3", + "a", "b", "t", "1", "2", "3", "t", "b", "b", "b"), + dim = c(10L, 2L) + ) + g_star_v7 <- graph_from_edgelist(el) all_cuts_star_v7 <- st_cuts(g_star_v7, source = "s", target = "t") expect_equal( unvs(all_cuts_star_v7$cuts), @@ -84,8 +90,13 @@ test_that("st_cuts() works", { c(1, 2, 5, 6, 7, 3) ) ) - - g_star_v9 <- graph_from_literal(s -+ a:b -+ t, a -+ 1:2:3:4:5 -+ b) + el <- structure( + c("s", "s", "a", "a", "a", "a", "a", "a", "b", "1", + "2", "3", "4", "5", "a", "b", "t", "1", "2", "3", "4", "5", "t", + "b", "b", "b", "b", "b"), + dim = c(14L, 2L) + ) + g_star_v9 <- graph_from_edgelist(el) all_cuts_star_v9 <- st_min_cuts(g_star_v9, source = "s", target = "t") expect_equal(all_cuts_star_v9$value, 2) expect_equal(unvs(all_cuts_star_v9$cuts), list(c(1, 2), c(1, 9), c(3, 9))) diff --git a/tests/testthat/test-operators.R b/tests/testthat/test-operators.R index afa804d5f1..d9df14b762 100644 --- a/tests/testthat/test-operators.R +++ b/tests/testthat/test-operators.R @@ -108,8 +108,15 @@ test_that("compose() works", { }) test_that("compose works for named graphs", { - g1 <- graph_from_literal(A - B:D:E, B - C:D, C - D, D - E) - g2 <- graph_from_literal(A - B - E - A) + el1 <- structure( + c( + "A", "A", "A", "B", "B", "D", "D", "B", "D", "E", + "D", "C", "E", "C"), + dim = c(7L, 2L) + ) + el2 <- structure(c("A", "A", "B", "B", "E", "E"), dim = 3:2) + g1 <- graph_from_edgelist(el1, directed = FALSE) + g2 <- graph_from_edgelist(el2, directed = FALSE) V(g1)$bar1 <- seq_len(vcount(g1)) V(g2)$bar2 <- seq_len(vcount(g2)) diff --git a/tests/testthat/test-structural-properties.R b/tests/testthat/test-structural-properties.R index f938d495dd..6177ddc72e 100644 --- a/tests/testthat/test-structural-properties.R +++ b/tests/testthat/test-structural-properties.R @@ -188,7 +188,8 @@ test_that("bfs() works", { local_igraph_options(print.id = FALSE) expect_snapshot({ - g <- graph_from_literal(a -+ b -+ c, z -+ a, d) + el <- structure(c("a", "b", "z", "b", "c", "a"), dim = 3:2) + g <- graph_from_edgelist(el) + vertex("d") bfs( g, root = 2,