Skip to content

Commit

Permalink
feat: add error when both graph_from_biadjacency()'s arguments `mul…
Browse files Browse the repository at this point in the history
…tiple` and `weighted` are TRUE
  • Loading branch information
maelle authored and aviator-bot committed Oct 1, 2024
1 parent 44bd8f4 commit be6845b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions R/incidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/incidence.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

3 changes: 3 additions & 0 deletions tests/testthat/test-incidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

0 comments on commit be6845b

Please sign in to comment.