add_n_node_clones {DiagrammeR} | R Documentation

## Add one or several clones of an existing node to the graph

### Description

Add n new nodes to a graph object of class `dgr_graph` which are clones of a node already in the graph. All node attributes are preserved except for the node `label` attribute (to maintain the uniqueness of non-`NA` node label values). A vector of node `label` can be provided to bind new labels to the cloned nodes.

### Usage

    add_n_node_clones(graph, n, node, label = NULL)

### Arguments

`graph` | a graph object of class `dgr_graph`.
`n` | the number of node clones to add to the graph.
`node` | a node ID corresponding to the graph node to be cloned.
`label` | an optional vector of node label values. The vector length should correspond to the value set for `n`.

### Value

a graph object of class `dgr_graph`.

### Examples

    # Create a graph with a path of
    # nodes; supply `label`, `type`,
    # and `value` node attributes
    graph <-
      create_graph() %>%
      add_path(
        n = 3,
        label = c("d", "g", "r"),
        type = c("a", "b", "c"),
        value = c(10, 20, 30))

    # Display the graph's internal
    # node data frame
    graph %>%
      get_node_df()
    #>   id type label value
    #> 1  1    a     d    10
    #> 2  2    b     g    20
    #> 3  3    c     r    30

    # Create 3 clones of node `1`
    # but assign new node label
    # values (leaving `label` as
    # NULL yields NA values)
    graph <-
      graph %>%
      add_n_node_clones(
        n = 3,
        node = 1,
        label = c("x", "y", "z"))

    # Display the graph's internal
    # node data frame: nodes `4`,
    # `5`, and `6` are clones of `1`
    graph %>%
      get_node_df()
    #>   id type label value
    #> 1  1    a     d    10
    #> 2  2    b     g    20
    #> 3  3    c     r    30
    #> 4  4    a     x    10
    #> 5  5    a     y    10
    #> 6  6    a     z    10

[Package DiagrammeR version 0.9.2 Index]