node_present {DiagrammeR} | R Documentation

## Determine whether a specified node is present in an existing graph object

### 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` that is created using `create_graph`.
`node` | a value that may or may not match a node ID in the graph.

### Value

a logical value.

### Examples

    ## Not run:
    # Before finding out whether a particular node is present,
    # create a simple graph
    nodes <-
      create_nodes(nodes = LETTERS,
                   label = TRUE,
                   type = c(rep("a_to_g", 7),
                            rep("h_to_p", 9),
                            rep("q_to_x", 8),
                            rep("y_and_z",2)))

    edges <-
      create_edges(from = sample(LETTERS, replace = TRUE),
                   to = sample(LETTERS, replace = TRUE),
                   label = "edge",
                   rel = "letter_to_letter")

    graph <-
      create_graph(nodes_df = nodes,
                   edges_df = edges,
                   graph_attrs = "layout = neato",
                   node_attrs = c("fontname = Helvetica",
                                  "shape = circle"))

    # Verify that node with ID 'a' is not in graph
    node_present(graph, "a")
    #> FALSE

    # Is node with ID 'A' in the graph?
    node_present(graph, "A")
    #> TRUE

    # Are all node ID values from the LETTERS vector
    in the graph?
    all(sapply(LETTERS, function(x) node_present(graph, x)))
    #> TRUE

    ## End(Not run)

[Package DiagrammeR version 0.8.2 Index]