From 6163470c1d0b31d9caadf61057a59218933602bb Mon Sep 17 00:00:00 2001 From: "Carl A. B. Pearson" Date: Thu, 17 Oct 2024 17:15:47 -0400 Subject: [PATCH] add test case for bind_graph on lists + implement fix --- R/bind.R | 4 ++-- tests/testthat/test-bind.R | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/R/bind.R b/R/bind.R index c515a7f..b984a95 100644 --- a/R/bind.R +++ b/R/bind.R @@ -46,12 +46,12 @@ #' graph %>% bind_graphs(new_graph) #' bind_graphs <- function(.data, ...) { - .data <- unfocus(.data) if (is_bare_list(.data)) { - .data <- lapply(c(.data, list2(...)), as_tbl_graph) + .data <- lapply(lapply(c(.data, list2(...)), unfocus), as_tbl_graph) dots <- .data[-1] .data <- .data[[1]] } else { + .data <- unfocus(.data) .data <- as_tbl_graph(.data) dots <- lapply(list2(...), as_tbl_graph) } diff --git a/tests/testthat/test-bind.R b/tests/testthat/test-bind.R index fef1671..9abdc67 100644 --- a/tests/testthat/test-bind.R +++ b/tests/testthat/test-bind.R @@ -10,6 +10,15 @@ test_that("bind_graphs works", { tbl <- as_tibble(gr) expect_true(all(lengths(lapply(split(tbl$group, tbl$comp), unique)) == 1)) }) + +test_that("bind_graphs works for .data a list of supported objects", { + gr1 <- create_notable('bull') + gr2 <- gr1 + gr1 <- mutate(gr1, group = 1) + gr2 <- mutate(gr2, group = 2) + gr <- expect_no_error(bind_graphs(list(gr1, gr2))) +}) + test_that('bind_nodes works', { gr1 <- tbl_graph(head(mtcars)) gr1 <- bind_nodes(gr1, tail(mtcars))