Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

is_graph_dag

Is the graph a directed acyclic graph?


Description

Provides a logical value on whether the graph is a directed acyclic graph (DAG). The conditions for a graph that is a DAG are that it should be a directed graph and it should not contain any cycles.

Usage

is_graph_dag(graph)

Arguments

graph

A graph object of class dgr_graph.

Value

A logical value.

Examples

# Create a directed graph containing
# only a balanced tree
graph_tree <-
  create_graph() %>%
  add_balanced_tree(
    k = 2, h = 3)

# Determine whether this graph
# is a DAG
graph_tree %>%
  is_graph_dag()

# Create a directed graph containing
# a single cycle
graph_cycle <-
  create_graph() %>%
  add_cycle(n = 5)

# Determine whether this graph
# is a DAG
graph_cycle %>%
  is_graph_dag()

# Create an undirected graph
# containing a balanced tree
graph_tree_undirected <-
  create_graph(
    directed = FALSE) %>%
  add_balanced_tree(
    k = 2, h = 2)

# Determine whether this graph
# is a DAG
graph_tree_undirected %>%
  is_graph_dag()

DiagrammeR

Graph/Network Visualization

v1.0.6.1
MIT + file LICENSE
Authors
Richard Iannone [aut, cre] (<https://orcid.org/0000-0003-3925-190X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.