The reroute verb lets you change the beginning and end node of edges by specifying the new indexes of the start and/or end node(s). Optionally only a subset of the edges can be rerouted using the subset argument, which should be an expression that are to be evaluated in the context of the edge data and should return an index compliant vector (either logical or integer).

reroute(.data, from = NULL, to = NULL, subset = NULL)

Arguments

.data

A tbl_graph or morphed_tbl_graph object. grouped_tbl_graph will be ungrouped prior to rerouting

from, to

The new indexes of the terminal nodes. If NULL nothing will be changed

subset

An expression evaluating to an indexing vector in the context of the edge data. If NULL it will use focused edges if available or all edges

Value

An object of the same class as .data

Examples

# Switch direction of edges
create_notable('meredith') %>%
  activate(edges) %>%
  reroute(from = to, to = from)
#> # A tbl_graph: 70 nodes and 140 edges
#> #
#> # An undirected simple graph with 1 component
#> #
#> # Edge Data: 140 × 2 (active)
#>     from    to
#>    <int> <int>
#>  1     1     5
#>  2     1     6
#>  3     1     7
#>  4     2     5
#>  5     2     6
#>  6     2     7
#>  7     3     5
#>  8     3     6
#>  9     3     7
#> 10     4     5
#> # ℹ 130 more rows
#> #
#> # Node Data: 70 × 0

# Using subset
create_notable('meredith') %>%
  activate(edges) %>%
  reroute(from = 1, subset = to > 10)
#> # A tbl_graph: 70 nodes and 140 edges
#> #
#> # An undirected multigraph with 17 components
#> #
#> # Edge Data: 140 × 2 (active)
#>     from    to
#>    <int> <int>
#>  1     1     5
#>  2     1     6
#>  3     1     7
#>  4     2     5
#>  5     2     6
#>  6     2     7
#>  7     3     5
#>  8     3     6
#>  9     3     7
#> 10     4     5
#> # ℹ 130 more rows
#> #
#> # Node Data: 70 × 0