add_forward_edges_ws {DiagrammeR} | R Documentation |
Add edges in the same direction
of one or more edges available as an edge selection
in a graph object of class dgr_graph
. New
graph edges have the same edge definitions as those
in the selection except with new edge ID values.
There is also the option to assign a common
rel
grouping to the newly created edges.
Upon addition of the edges, the edge selection will
be retained for further selection or traversal
operations.
Selections of edges can be performed using
the following select_...
functions:
select_edges()
,
select_last_edge()
, or
select_edges_by_node_id()
.
Selections of edges can also be performed using
the following traversal functions:
trav_out_edge()
, trav_in_edge()
,
or trav_both_edge()
.
add_forward_edges_ws(graph, rel = NULL)
graph |
a graph object of class
|
rel |
an optional string to apply a
|
a graph object of class dgr_graph
.
# Create an empty graph, add 2 nodes to it, # and create the edge `1->2` graph <- create_graph() %>% add_n_nodes( n = 2, type = "type_a", label = c("a_1", "a_2")) %>% add_edge( from = 1, to = 2, rel = "a") # Get the graph's edges graph %>% get_edge_ids() #> [1] 1 # Select the edge and create 2 additional edges # with the same definition (`1->2`) but with # different `rel` values (`b` and `c`) graph <- graph %>% select_edges() %>% add_forward_edges_ws(rel = "b") %>% add_forward_edges_ws(rel = "c") %>% clear_selection() # Get the graph's edge data frame get_edge_df(graph) #> id from to rel #> 1 1 1 2 a #> 2 2 1 2 b #> 3 3 1 2 c