add_edge_clone: Add a clone of an existing edge to the graph

View source: R/add_edge_clone.R

add_edge_cloneR Documentation

Add a clone of an existing edge to the graph

Description

Add a new edge to a graph object of class dgr_graph which is a clone of an edge already in the graph. All edge attributes are preserved.

Usage

add_edge_clone(graph, edge, from, to)

Arguments

graph

A graph object of class dgr_graph.

edge

An edge ID corresponding to the graph edge to be cloned.

from

The outgoing node from which the edge is connected.

to

The incoming nodes to which each edge is connected.

Value

A graph object of class dgr_graph.

See Also

Other edge creation and removal: add_edge(), add_edge_df(), add_edges_from_table(), add_edges_w_string(), add_forward_edges_ws(), add_reverse_edges_ws(), copy_edge_attrs(), create_edge_df(), delete_edge(), delete_edges_ws(), delete_loop_edges_ws(), drop_edge_attrs(), edge_data(), join_edge_attrs(), mutate_edge_attrs(), mutate_edge_attrs_ws(), recode_edge_attrs(), rename_edge_attrs(), rescale_edge_attrs(), rev_edge_dir(), rev_edge_dir_ws(), set_edge_attr_to_display(), set_edge_attrs(), set_edge_attrs_ws()

Examples

# Create a graph with a path of
# 2 nodes; supply a common `rel`
# edge attribute for all edges
# in this path and then add a
# `color` edge attribute
graph <-
  create_graph() %>%
  add_path(
    n = 2,
    rel = "a") %>%
  select_last_edges_created() %>%
  set_edge_attrs(
    edge_attr = color,
    values = "steelblue") %>%
  clear_selection()

# Display the graph's internal
# edge data frame
graph %>% get_edge_df()

# Create a new node (will have
# node ID of `3`) and then
# create an edge between it and
# node `1` while reusing the edge
# attributes of edge `1` -> `2`
# (edge ID `1`)
graph_2 <-
  graph %>%
  add_node() %>%
  add_edge_clone(
    edge = 1,
    from = 3,
      to = 1)

# Display the graph's internal
# edge data frame
graph_2 %>% get_edge_df()

# The same change can be performed
# with some helper functions in the
# `add_edge_clone()` function call
graph_3 <-
  graph %>%
    add_node() %>%
    add_edge_clone(
      edge = get_last_edges_created(.),
      from = get_last_nodes_created(.),
      to = 1)

# Display the graph's internal
# edge data frame
graph_3 %>% get_edge_df()


DiagrammeR documentation built on June 22, 2024, 11:21 a.m.