diff --git a/R/attributes.R b/R/attributes.R index 89fa53e2ee..db922b7fff 100644 --- a/R/attributes.R +++ b/R/attributes.R @@ -1008,9 +1008,31 @@ is_weighted <- function(graph) { is_bipartite <- function(graph) { ensure_igraph(graph) - "type" %in% vertex_attr_names(graph) + has_type_attr <- "type" %in% vertex_attr_names(graph) + + bipartite_result <- bipartite_mapping(graph) + + if (has_type_attr) { + if (!bipartite_result$res) { + cli::cli_warn("{.arg graph} has a type attribute but is not actually bipartite.") + FALSE + } else { + if (!all(bipartite_result$type == vertex_attr(graph, "type")) & !all(bipartite_result$type == !vertex_attr(graph, "type"))) { + cli::cli_warn("{.arg graph} is bipartite but has a wrong 'type' vertex attribute. You can correct it using:\n {.code V(graph)$type <- bipartite_mapping(graph)$type}") + } + TRUE + } + } else { + if (bipartite_result$res) { + cli::cli_warn("{.arg graph} is bipartite but has no 'type' vertex attribute. You can add it using:\n {.code V(graph)$type <- bipartite_mapping(graph)$type}") + TRUE + } else { + FALSE + } + } } + ############# igraph.i.attribute.combination <- function(comb) {