DiagrammeR (version 0.9.2)

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(
    n = 30, m = 40,
    set_seed = 23)

graph_1 %>%
  is_graph_connected()
#> [1] FALSE

# The following graph is fully connected
graph_2 <-
  create_random_graph(
    n = 30, m = 50,
    set_seed = 23)

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); this is easily done by
# removing one of the nodes that is an
# articulation point
graph_2 %>%
  delete_node(
    node = get_articulation_points(.)[1]) %>%
  is_graph_connected()
#> [1] FALSE
# }

Run the code above in your browser using DataCamp Workspace