From be6845beaa503b06a192f7275c39a48454221781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 1 Oct 2024 14:28:12 +0200 Subject: [PATCH] feat: add error when both `graph_from_biadjacency()`'s arguments `multiple` and `weighted` are TRUE --- R/incidence.R | 7 +++++++ tests/testthat/_snaps/incidence.md | 9 +++++++++ tests/testthat/test-incidence.R | 3 +++ 3 files changed, 19 insertions(+) diff --git a/R/incidence.R b/R/incidence.R index 6471af0a38..49120ba4dd 100644 --- a/R/incidence.R +++ b/R/incidence.R @@ -218,6 +218,13 @@ graph_from_biadjacency_matrix <- function(incidence, directed = FALSE, if (!is.null(weighted)) { if (is.logical(weighted) && weighted) { + + if (multiple) { + cli::cli_abort(c( + "{.arg multiple} and {.arg weighted} cannot be both {.code TRUE}.", + "igraph either interprets numbers larger than 1 as weights or as multiplicities, but it cannot be both." + )) + } weighted <- "weight" } if (is.logical(weighted) && !weighted) { diff --git a/tests/testthat/_snaps/incidence.md b/tests/testthat/_snaps/incidence.md index ed8636ccef..b15badd95f 100644 --- a/tests/testthat/_snaps/incidence.md +++ b/tests/testthat/_snaps/incidence.md @@ -76,3 +76,12 @@ ! `weighted` can't be a number. i See `?graph_from_biadjacency_matrix()`'s manual page. +--- + + Code + (g <- graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE)) + Condition + Error in `graph_from_biadjacency_matrix()`: + ! `multiple` and `weighted` cannot be both `TRUE`. + igraph either interprets numbers larger than 1 as weights or as multiplicities, but it cannot be both. + diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R index 73d0efaff5..7b871739e1 100644 --- a/tests/testthat/test-incidence.R +++ b/tests/testthat/test-incidence.R @@ -165,4 +165,7 @@ test_that("graph_from_biadjacency_matrix() errors well", { expect_snapshot(error = TRUE, { (g <- graph_from_biadjacency_matrix(inc, weight = 42)) }) + expect_snapshot(error = TRUE, { + (g <- graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE)) + }) })