delete_node {DiagrammeR} | R Documentation

## Delete a node from an existing graph object

### Description

From a graph object of class `dgr_graph`, delete an existing node by specifying its node ID.

### Usage

    delete_node(graph, node)

### Arguments

`graph` | a graph object of class `dgr_graph`.
`node` | a node ID for the node to be deleted from the graph.

### Value

a graph object of class `dgr_graph`.

### Examples

    # Create a graph with 5 nodes and
    # edges between each in a path
    graph <-
      create_graph() %>%
      add_path(n = 5)

    # Delete node with ID `3`
    graph <- delete_node(graph, node = 3)

    # Verify that the node with ID `3`
    # is no longer in the graph
    get_node_ids(graph)
    #> [1] 1 2 4 5

    # Also note that edges are removed
    # since there were edges between the
    # removed node to and from other nodes
    get_edges(graph)
    #> [1] "1->2" "4->5"

[Package DiagrammeR version 0.9.2 Index]