Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -1289,11 +1289,9 @@ igraph.i.attribute.combination <- function(comb) {
}
comb <- as.list(comb)
if (
any(
!sapply(comb, function(x) {
is.function(x) || (is.character(x) && length(x) == 1)
})
)
!all(sapply(comb, function(x) {
is.function(x) || (is.character(x) && length(x) == 1)
}))
) {
cli::cli_abort(
"Attribute combination element must be a function or character scalar."
Expand Down
6 changes: 3 additions & 3 deletions R/centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ arpack <- function(
}

defaults <- arpack_defaults()
if (any(!names(options) %in% names(defaults))) {
if (!all(names(options) %in% names(defaults))) {
unknown_options <- setdiff(names(options), names(defaults))
cli::cli_abort(
"Can't use unkown ARPACK {cli::qty(unknown_options)} option{?s}:
Expand Down Expand Up @@ -1975,7 +1975,7 @@ alpha.centrality.dense <- function(
} else if (is.character(weights) && length(weights) == 1) {
## name of an edge attribute, nothing to do
attr <- weights
} else if (any(!is.na(weights))) {
} else if (!all(is.na(weights))) {
## weights != NULL and weights != rep(NA, x)
graph <- set_edge_attr(graph, "weight", value = as.numeric(weights))
attr <- "weight"
Expand Down Expand Up @@ -2022,7 +2022,7 @@ alpha.centrality.sparse <- function(
} else if (is.character(weights) && length(weights) == 1) {
## name of an edge attribute, nothing to do
attr <- weights
} else if (any(!is.na(weights))) {
} else if (!all(is.na(weights))) {
## weights != NULL and weights != rep(NA, x)
graph <- set_edge_attr(graph, "weight", value = as.numeric(weights))
attr <- "weight"
Expand Down
14 changes: 7 additions & 7 deletions R/community.R
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ modularity_matrix <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -1464,7 +1464,7 @@ cluster_spinglass <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -1979,7 +1979,7 @@ cluster_edge_betweenness <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -2071,7 +2071,7 @@ cluster_fast_greedy <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -2246,7 +2246,7 @@ cluster_leading_eigen <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -2491,7 +2491,7 @@ cluster_louvain <- function(graph, weights = NULL, resolution = 1) {
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -2583,7 +2583,7 @@ cluster_optimal <- function(graph, weights = NULL) {
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ graph_from_data_frame <- function(d, directed = TRUE, vertices = NULL) {
if (any(duplicated(names))) {
cli::cli_abort("{.arg vertices} contains duplicated vertex names")
}
if (any(!names2 %in% names)) {
if (!all(names2 %in% names)) {
cli::cli_abort(
"Some vertex names in {.arg d} are not listed in {.arg vertices}"
)
Expand Down
2 changes: 1 addition & 1 deletion R/glet.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ graphlet_proj <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/iterators.R
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ is_igraph_es <- function(x) {
parse_op_args <- function(..., what, is_fun, as_fun, check_graph = TRUE) {
args <- list(...)

if (any(!sapply(args, is_fun))) {
if (!all(sapply(args, is_fun))) {
cli::cli_abort("Not {what} sequence")
}

Expand Down
4 changes: 2 additions & 2 deletions R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ layout_with_fr <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -1875,7 +1875,7 @@ layout_with_kk <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ difference.igraph <- function(big, small, byname = "auto", ...) {
if (byname) {
bnames <- V(big)$name
snames <- V(small)$name
if (any(!snames %in% bnames)) {
if (!all(snames %in% bnames)) {
small <- small - setdiff(snames, bnames)
snames <- V(small)$name
}
Expand Down
10 changes: 5 additions & 5 deletions R/structural-properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ diameter <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -790,7 +790,7 @@ get_diameter <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -826,7 +826,7 @@ farthest_vertices <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -1802,7 +1802,7 @@ transitivity <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down Expand Up @@ -3352,7 +3352,7 @@ laplacian_matrix <- function(
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
weights <- E(graph)$weight
}
if (!is.null(weights) && any(!is.na(weights))) {
if (!is.null(weights) && !all(is.na(weights))) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ test_that("without_loops", {
)

expect_identical_graphs(g1, g2)
expect_true(all(!which_loop(g2)))
expect_all_false(which_loop(g2))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which_loops() returns a vector a logical so I think this is what we meant?

})


Expand All @@ -345,7 +345,7 @@ test_that("without_multiple", {
)

expect_identical_graphs(g1, g2)
expect_true(all(!which_multiple(g2)))
expect_all_false(which_multiple(g2))
})


Expand All @@ -358,8 +358,8 @@ test_that("simplified", {
)

expect_identical_graphs(g1, g2)
expect_true(all(!which_multiple(g2)))
expect_true(all(!which_loop(g2)))
expect_true(!any(which_multiple(g2)))
expect_true(!any(which_loop(g2)))
})


Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-glet.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ graphlets.old <- function(graph) {
if (!is_weighted(graph)) {
cli::cli_abort("Graph not weighted")
}
if (min(E(graph)$weight) <= 0 || any(!is.finite(E(graph)$weight))) {
if (min(E(graph)$weight) <= 0 || !all(is.finite(E(graph)$weight))) {
cli::cli_abort("Edge weights must be non-negative and finite")
}

Expand Down Expand Up @@ -104,7 +104,7 @@ graphlets.project.old <- function(graph, cliques, iter, Mu = NULL) {
if (!is_weighted(graph)) {
cli::cli_abort("Graph not weighted")
}
if (min(E(graph)$weight) <= 0 || any(!is.finite(E(graph)$weight))) {
if (min(E(graph)$weight) <= 0 || !all(is.finite(E(graph)$weight))) {
cli::cli_abort("Edge weights must be non-negative and finite")
}
if (
Expand Down