node_present {DiagrammeR} | R Documentation

## Determine whether a specified node is present

### Description

From a graph object of class `dgr_graph`, determine whether a specified node is present.

### Usage

    node_present(graph, node)

### Arguments

`graph` | a graph object of class `dgr_graph`.
`node` | a value that may or may not match a node ID in the graph.

### 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)

    # Verify that node with ID `34` is not in graph
    node_present(graph, 34)
    #> FALSE

    # Is node with ID 5 in the graph?
    node_present(graph, 5)
    #> TRUE

    # Are all node ID values from `1` to `26`
    # in the graph?
    all(sapply(1:26,
          function(x) node_present(graph, x)))
    #> TRUE

[Package DiagrammeR version 0.9.2 Index]