Skip to content
Merged
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
4 changes: 2 additions & 2 deletions R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ edge.attributes <- function(graph, index = E(graph)) {

if (!missing(index)) {
index <- as_igraph_es(graph, index)
if (any(duplicated(index)) || any(is.na(index))) {
if (anyDuplicated(index) > 0 || anyNA(index)) {
cli::cli_abort("{.arg index} contains duplicated edges or NAs.")
}
}
Expand Down Expand Up @@ -1302,7 +1302,7 @@ igraph.i.attribute.combination <- function(comb) {
if (is.null(names(comb))) {
names(comb) <- rep("", length(comb))
}
if (any(duplicated(names(comb)))) {
if (anyDuplicated(names(comb)) > 0) {
cli::cli_warn("Some attributes are duplicated")
}
comb <- lapply(comb, function(x) {
Expand Down
8 changes: 4 additions & 4 deletions R/community.R
Original file line number Diff line number Diff line change
Expand Up @@ -1654,21 +1654,21 @@ cluster_leiden <- 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) && !anyNA(weights)) {
weights <- as.numeric(weights)
} else {
weights <- NULL
}

# Parse initial_membership argument
if (!is.null(initial_membership) && !any(is.na(initial_membership))) {
if (!is.null(initial_membership) && !anyNA(initial_membership)) {
initial_membership <- as.numeric(initial_membership)
} else {
initial_membership <- NULL
}

# Parse node weights argument
if (!is.null(vertex_weights) && !any(is.na(vertex_weights))) {
if (!is.null(vertex_weights) && !anyNA(vertex_weights)) {
vertex_weights <- as.numeric(vertex_weights)
if (objective_function == 1) {
# Using modularity
Expand Down Expand Up @@ -1851,7 +1851,7 @@ cluster_walktrap <- 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) && !anyNA(weights)) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down
4 changes: 2 additions & 2 deletions R/conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ graph_from_data_frame <- function(d, directed = TRUE, vertices = NULL) {
## Handle if some elements are 'NA' (first two columns are interpreted as from/to)
ensure_no_na(d[, 1:2], "edge data frame")

if (!is.null(vertices) && any(is.na(vertices[, 1]))) {
if (!is.null(vertices) && anyNA(vertices[, 1])) {
cli::cli_warn(
"In {.code vertices[,1]}, {.code NA} elements were replaced with string {.str NA}."
)
Expand All @@ -1582,7 +1582,7 @@ graph_from_data_frame <- function(d, directed = TRUE, vertices = NULL) {
cli::cli_abort("{.arg vertices} contains no rows")
}
names <- as.character(vertices[, 1])
if (any(duplicated(names))) {
if (anyDuplicated(names) > 0) {
cli::cli_abort("{.arg vertices} contains duplicated vertex names")
}
if (any(!names2 %in% names)) {
Expand Down
8 changes: 4 additions & 4 deletions R/indexing.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ get_adjacency_submatrix <- function(x, i, j, attr = NULL) {
cli::cli_abort("Cannot use {.arg from}/{.arg to} without the other")
}
if (!missing(from)) {
if ((!is.numeric(from) && !is.character(from)) || any(is.na(from))) {
if ((!is.numeric(from) && !is.character(from)) || anyNA(from)) {
cli::cli_abort(
"{.arg from} must be a numeric or character vector without NAs"
)
}
if ((!is.numeric(to) && !is.character(to)) || any(is.na(to))) {
if ((!is.numeric(to) && !is.character(to)) || anyNA(to)) {
cli::cli_abort(
"{.arg to} must be a numeric or character vector without NAs"
)
Expand Down Expand Up @@ -487,12 +487,12 @@ expand.grid.unordered <- function(i, j, loops = FALSE, directed = FALSE) {
cli::cli_abort("Logical or numeric value must be of length 1")
}
if (!missing(from)) {
if ((!is.numeric(from) && !is.character(from)) || any(is.na(from))) {
if ((!is.numeric(from) && !is.character(from)) || anyNA(from)) {
cli::cli_abort(
"{.arg from} must be a numeric or character vector without NAs"
)
}
if ((!is.numeric(to) && !is.character(to)) || any(is.na(to))) {
if ((!is.numeric(to) && !is.character(to)) || anyNA(to)) {
cli::cli_abort(
"{.arg to} must be a numeric or character vector without NAs"
)
Expand Down
4 changes: 2 additions & 2 deletions R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ add_edges <- function(graph, edges, ..., attr = list()) {
attrs <- list(...)
attrs <- append(attrs, attr)
nam <- names(attrs)
if (length(attrs) != 0 && (is.null(nam) || any(nam == ""))) {
if (length(attrs) != 0 && (is.null(nam) || any(!nzchar(nam)))) {
cli::cli_abort("All attributes must be named.")
}

Expand Down Expand Up @@ -212,7 +212,7 @@ add_vertices <- function(graph, nv, ..., attr = list()) {
attrs <- list(...)
attrs <- append(attrs, attr)
nam <- names(attrs)
if (length(attrs) != 0 && (is.null(nam) || any(nam == ""))) {
if (length(attrs) != 0 && (is.null(nam) || any(!nzchar(nam)))) {
cli::cli_abort("All attributes must be named.")
}

Expand Down
10 changes: 5 additions & 5 deletions R/iterators.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ create_es <- function(graph, idx, na_ok = FALSE) {

simple_vs_index <- function(x, i, na_ok = FALSE) {
res <- unclass(x)[i]
if (!na_ok && any(is.na(res))) {
if (!na_ok && anyNA(res)) {
cli::cli_abort("Unknown vertex selected.")
}
class(res) <- "igraph.vs"
Expand Down Expand Up @@ -842,7 +842,7 @@ simple_es_index <- function(x, i, na_ok = FALSE) {
} else {
res <- unclass(x)[i]
}
if (!na_ok && any(is.na(res))) {
if (!na_ok && anyNA(res)) {
cli::cli_abort("Unknown edge selected")
}
attr(res, "env") <- attr(x, "env")
Expand Down Expand Up @@ -1562,7 +1562,7 @@ as_igraph_vs <- function(graph, v, na.ok = FALSE) {
}
if (is.character(v) && "name" %in% vertex_attr_names(graph)) {
v <- as.numeric(match(v, V(graph)$name))
if (!na.ok && any(is.na(v))) {
if (!na.ok && anyNA(v)) {
cli::cli_abort("Invalid vertex names")
}
v
Expand All @@ -1574,7 +1574,7 @@ as_igraph_vs <- function(graph, v, na.ok = FALSE) {
} else {
res <- as.numeric(v)
}
if (!na.ok && any(is.na(res))) {
if (!na.ok && anyNA(res)) {
cli::cli_abort("Invalid vertex name(s)")
}
res
Expand Down Expand Up @@ -1617,7 +1617,7 @@ as_igraph_es <- function(graph, e) {
} else {
res <- as.numeric(e)
}
if (any(is.na(res))) {
if (anyNA(res)) {
cli::cli_abort("Invalid edge names")
}
res
Expand Down
2 changes: 1 addition & 1 deletion R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -2867,7 +2867,7 @@ layout_with_drl <- 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) && !anyNA(weights)) {
weights <- as.numeric(weights)
} else {
weights <- NULL
Expand Down
4 changes: 2 additions & 2 deletions R/make.R
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ graph.bipartite <- function(types, edges, directed = FALSE) {
)
}
edges <- match(edges, vertex.names)
if (any(is.na(edges))) {
if (anyNA(edges)) {
cli::cli_abort(
"edge vector contains a vertex name that is not found in {.arg types}"
)
Expand Down Expand Up @@ -2672,7 +2672,7 @@ make_bipartite_graph <- function(types, edges, directed = FALSE) {
)
}
edges <- match(edges, vertex.names)
if (any(is.na(edges))) {
if (anyNA(edges)) {
cli::cli_abort(
"edge vector contains a vertex name that is not found in {.arg types}"
)
Expand Down
14 changes: 7 additions & 7 deletions R/operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ disjoint_union <- function(...) {
}
vertex.attributes(res) <- attr

if ("name" %in% names(attr) && any(duplicated(attr$name))) {
if ("name" %in% names(attr) && anyDuplicated(attr$name) > 0) {
cli::cli_warn("Duplicate vertex names in disjoint union.")
}

Expand Down Expand Up @@ -690,7 +690,7 @@ difference.igraph <- function(big, small, byname = "auto", ...) {
snames <- V(small)$name
}
perm <- match(bnames, snames)
if (any(is.na(perm))) {
if (anyNA(perm)) {
perm[is.na(perm)] <- seq(from = vcount(small) + 1, to = vcount(big))
}
big <- permute(big, perm)
Expand Down Expand Up @@ -969,7 +969,7 @@ vertex <- function(...) {

# Check for duplicate named arguments
if (!is.null(arg_names)) {
named_args <- arg_names[arg_names != ""]
named_args <- arg_names[nzchar(arg_names)]
if (anyDuplicated(named_args)) {
duplicates <- unique(named_args[duplicated(named_args)])
cli::cli_abort(
Expand Down Expand Up @@ -1142,8 +1142,8 @@ path <- function(...) {
toadd <- unlist(e2, recursive = FALSE)
attr <- list()
} else {
toadd <- unlist(e2[names(e2) == ""])
attr <- e2[names(e2) != ""]
toadd <- unlist(e2[!nzchar(names(e2))])
attr <- e2[nzchar(names(e2))]
}
res <- add_edges(e1, as_igraph_vs(e1, toadd), attr = attr)
} else if ("igraph.vertex" %in% class(e2)) {
Expand All @@ -1167,8 +1167,8 @@ path <- function(...) {
to_add <- unlist(e2, recursive = FALSE)
attr <- list()
} else {
to_add <- unlist(e2[names(e2) == ""])
attr <- e2[names(e2) != ""]
to_add <- unlist(e2[!nzchar(names(e2))])
attr <- e2[nzchar(names(e2))]
}
to_add <- as_igraph_vs(e1, to_add)
lt <- length(to_add)
Expand Down
2 changes: 1 addition & 1 deletion R/other.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ handle_vertex_type_arg <- function(types, graph, required = T) {
cli::cli_warn("vertex types converted to logical.")
}
types <- as.logical(types)
if (any(is.na(types))) {
if (anyNA(types)) {
cli::cli_abort("`NA' is not allowed in vertex types")
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ rglplot.igraph <- function(x, ...) {
rgl::text3d(x, y, z, labels, col = label.color, adj = 0)

edge.labels[is.na(edge.labels)] <- ""
if (any(edge.labels != "")) {
if (any(nzchar(edge.labels))) {
x0 <- layout[, 1][el[, 1]]
x1 <- layout[, 1][el[, 2]]
y0 <- layout[, 2][el[, 1]]
Expand Down
2 changes: 1 addition & 1 deletion R/plot.common.R
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ i.parse.plot.params <- function(graph, params) {
}
}
if (!is.function(p[[type]][[name]])) {
if (any(is.na(p[[type]][[name]]))) {
if (anyNA(p[[type]][[name]])) {
if (name != "label") {
cli::cli_warn(
"{type} attribute {name} contains NAs. Replacing with default value {i.default.values[[type]][[name]]
Expand Down
6 changes: 3 additions & 3 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@
cat(title, "\n", sep = "")

atxt <- .get.attr.codes(object)
atxt <- paste(atxt[atxt != ""], collapse = ", ")
if (atxt != "") {
atxt <- paste(atxt[nzchar(atxt)], collapse = ", ")
if (nzchar(atxt)) {
atxt <- strwrap(
paste(sep = "", "+ attr: ", atxt),
prefix = "| ",
initial = ""
)
cat(atxt, sep = "\n")
}
1 + if (length(atxt) == 1 && atxt == "") 0 else length(atxt)
1 + if (length(atxt) == 1 && !nzchar(atxt)) 0 else length(atxt)
}

#' @importFrom utils capture.output
Expand Down
4 changes: 2 additions & 2 deletions R/sparsedf.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ sdf <- function(..., row.names = NULL, NROW = NULL) {

if (
is.null(names(cols)) ||
any(names(cols) == "") ||
any(duplicated(names(cols)))
any(!nzchar(names(cols))) ||
anyDuplicated(names(cols)) > 0
) {
cli::cli_abort("Columns must be have (unique) names.")
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cliques.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test_that("max_cliques() work", {
} else {
numeric()
}
if (any(duplicated(PX$PX))) {
if (anyDuplicated(PX$PX) > 0) {
cli::cli_abort("foo2")
}
}
Expand Down
Loading