Return the nodes of an edge in the graph gr selected at random. Edges from other nodes can be ignored by passing their index(es) to ignore_nodes_connected_to. This is used in swapping edges by passing the nodes for the first edge to be ignored in the selection of the second edge.

random_edge_nodes(gr, ignore_nodes_connected_to = c())

Arguments

gr

tidygraph graph object; must have the node attribute .idx with the node indices

ignore_nodes_connected_to

a vector of indices for the nodes whose edges to ignore

Value

a vector of two indices for the nodes of the edge selected; if no edge was able to be selected, then integer(0) is returned

Examples

set.seed(0) gr <- tidygraph::create_ring(5) gr <- tidygraph::mutate(gr, .idx = 1:dplyr::n()) random_edge_nodes(gr)
#> `.env` is deprecated and no longer has any effect
#> [1] 1 5