Flip direction of igraph edges

flip_edges(g, edge_idx, verbose = FALSE, ...)

Arguments

g

igraph object

edge_idx

integer index of edges in the order they are stored in igraph::E(g), or what igraph calls an "edge sequence" which is a character name for each node, defined as "node1|node2". For example "D|A" would define an edge from node name "D" to node name "A". When verbose=TRUE a summary table is printed out to show which edges were flipped.

verbose

logical indicating whether to print verbose output. When verbose=TRUE a summary table is printed with these columns:

  • edge_seq: the input edge sequence, for example when edge_idx is provided as a character vector, the input vector is printed here.

  • edge_seq_matched: edge sequence that matched the g object. For example, when edge_idx input is a character vector, only the edges that match the g input are included here.

  • edge_idx: the integer index values of edges flipped. An NA value indicates the edge was not flipped, which should only happen when input edge_idx is provided as a character vector and some edges do not match the g input.

...

additional arguments are ignored.

Details

This function simply flips the direction of igraph edges, keeping all other node and edge attributes.

Note that this function will flip the order of nodes for each edge defined by edge_idx, regardless whether the igraph itself is a directed graph.

When edge_idx is provided as a character vector edge sequence, any entries that do not match edges in g are ignored. A summary table is printed when verbose=TRUE.

Examples

am <- matrix(ncol=5, nrow=5, byrow=TRUE,
   data=c(0,0,0,0,0,
      1,0,0,0,0,
      1,0,0,0,0,
      1,0,0,0,0,
      1,0,0,0,0),
   dimnames=list(head(LETTERS, 5),
      head(LETTERS, 5)))
am;
#>   A B C D E
#> A 0 0 0 0 0
#> B 1 0 0 0 0
#> C 1 0 0 0 0
#> D 1 0 0 0 0
#> E 1 0 0 0 0
g1 <- igraph::graph_from_adjacency_matrix(am)
plot(g1);

g2 <- flip_edges(g1, 3:4);
plot(g2);