edge_present {DiagrammeR} | R Documentation

## Determine whether a specified edge is present

### Description

From a graph object of class `dgr_graph`, determine whether a directed edge (defined by a pair of node IDs extant in the graph) is present.

### Usage

    edge_present(graph, from, to)

### Arguments

`graph` | a graph object of class `dgr_graph`.
`from` | a node ID from which the edge to be queried is outgoing.
`to` | a node ID to which the edge to be queried is incoming.

### Value

a logical value.

### Examples

    # Set a seed
    set.seed(23)

    # Create a node data frame (ndf)
    ndf <-
      create_node_df(
        n = 26,
        label = TRUE,
        type = c(rep("a", 7),
                 rep("b", 9),
                 rep("c", 8),
                 rep("d", 2)))

    # Create an edge data frame (edf)
    edf <-
      create_edge_df(
        from = sample(1:26, replace = TRUE),
        to = sample(1:26, replace = TRUE),
        rel = c(rep("rel_a", 7),
                rep("rel_b", 9),
                rep("rel_c", 8),
                rep("rel_d", 2)))

    # Create a graph using the ndf and edf
    graph <-
      create_graph(
        nodes_df = ndf,
        edges_df = edf)

    # Is there any edge between nodes with IDs
    # `1` and `2`?
    edge_present(graph, from = 1, to = 2)
    #> FALSE

    # Verify that there is an edge between nodes
    # `9` and `5`
    edge_present(graph, from = 9, to = 5)
    #> TRUE

[Package DiagrammeR version 0.9.2 Index]