DiagrammeR (version 0.9.0)

is_graph_connected: Is the graph a connected graph?

Description

Determines whether a graph is a connected graph.

Usage

is_graph_connected(graph)

Arguments

graph

a graph object of class dgr_graph.

Value

a logical value.

Examples

Run this code
# NOT RUN {
# This graph, created using `create_random_graph()`
# is almost fully connected but there is an
# isolated node with no edges
graph_1 <-
  create_random_graph(
    30, 50, set_seed = 1)

graph_1 %>% is_graph_connected
#> [1] FALSE

# The following graph is fully connected
graph_2 <-
  create_random_graph(
    36, 50, set_seed = 1)

graph_2 %>% is_graph_connected()
#> [1] TRUE

# Modify `graph_2` so that there are two
# clusters of nodes (i.e., making the graph
# not connected)
graph_3 <-
  graph_2 %>%
  delete_edge(10, 36) %>%
  delete_edge(25, 27) %>%
  delete_edge(28, 29) %>%
  delete_edge(4, 29) %>%
  delete_edge(24, 32)

graph_3 %>% is_graph_connected()
#> [1] FALSE
# }

Run the code above in your browser using DataLab