Nothing
#' Get all nodes associated with connected components
#'
#' @description
#'
#' Determine which nodes in a graph belong to different weakly connected
#' components (i.e., distinct sets of nodes with traversable paths to and from
#' each node in the set).
#'
#' @inheritParams render_graph
#'
#' @return A data frame with nodes and their membership in different weakly
#' connected components.
#'
#' @examples
#' # Create a graph with 2 cycles
#' graph <-
#' create_graph() %>%
#' add_cycle(n = 4) %>%
#' add_cycle(n = 3)
#'
#' # Check if the graph is connected
#' graph %>%
#' is_graph_connected()
#'
#' # Get the graph's weakly-connected
#' # components
#' graph %>% get_w_connected_cmpts()
#'
#' @export
get_w_connected_cmpts <- function(graph) {
# Validation: Graph object is valid
check_graph_valid(graph)
# Create a graph where only mandatory
# node and edge attributes are retained;
# transform to an igraph object
ig_graph <-
create_graph(
nodes_df = graph %>%
get_node_df() %>%
dplyr::select(id, type, label),
edges_df = graph %>%
get_edge_df() %>%
dplyr::select(id, from, to, rel),
directed = is_graph_directed(graph)) %>%
to_igraph()
# Get the component list from the graph
components <-
ig_graph %>%
igraph::components(mode = "weak")
# Create the output data frame
data.frame(
id = as.integer(names(components$membership)),
wc_component = components$membership,
stringsAsFactors = FALSE)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.