Skip to content

Commit

Permalink
fixed cli calls
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics committed Feb 13, 2025
1 parent eed70e3 commit d910e60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 12 additions & 6 deletions R/games.R
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ sample_pref <- function(nodes, types, type.dist = rep(1, types),
cli::cli_abort(c(
"{.arg pref.matrix} must have {.arg types} rows and columns.",
i = "See {.fun igraph::sample_pref}'s manual."
))
))
}

on.exit(.Call(R_igraph_finalizer))
Expand Down Expand Up @@ -1462,10 +1462,16 @@ sample_asym_pref <- function(nodes, types,
pref.matrix = matrix(1, types, types),
loops = FALSE) {
if (nrow(pref.matrix) != types || ncol(pref.matrix) != types) {
cli::cli_abort("Invalid size for preference matrix")
cli::cli_abort(c(
"{.arg pref.matrix} must have {.arg types} rows and columns.",
i = "See {.fun igraph::sample_asym_pref}'s manual."
))
}
if (nrow(type.dist.matrix) != types || ncol(type.dist.matrix) != types) {
cli::cli_abort("Invalid size for type distribution matrix")
cli::cli_abort(c(
"{.arg type.dist.matrix} must have {.arg types} rows and columns.",
i = "See {.fun igraph::sample_asym_pref}'s manual."
))
}

on.exit(.Call(R_igraph_finalizer))
Expand Down Expand Up @@ -1760,16 +1766,16 @@ sample_bipartite <- function(n1, n2, type = c("gnp", "gnm"), p, m,
)

if (type == "gnp" && missing(p)) {
cli::cli_abort("Connection probability `p' is not given for Gnp graph")
cli::cli_abort("Connection probability {.arg p} must be given for Gnp graph")
}
if (type == "gnp" && !missing(m)) {
cli::cli_warn("Number of edges {.arg m} is ignored for Gnp graph.")
}
if (type == "gnm" && missing(m)) {
cli::cli_abort("Number of edges `m' is not given for Gnm graph")
cli::cli_abort("Number of edges {.arg m} must be given for Gnm graph")
}
if (type == "gnm" && !missing(p)) {
cli::cli_warn("Connection probability {.arg p} is ignored for Gnp graph.")
cli::cli_warn("Connection probability {.arg p} is ignored for Gnm graph.")
}

on.exit(.Call(R_igraph_finalizer))
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-games.R
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ test_that("HSBM with list arguments works", {
blocks * vertices_per_block,
rep(vertices_per_block, blocks),
rho = list(rho, rho), C = C, p = 0
),
"Lengths of `m', `rho' and `C' must match"
)
)

###
Expand Down

0 comments on commit d910e60

Please sign in to comment.