random_edge_nodes: Return the nodes for a randomly selected edge

Description Usage Arguments Value Examples

View source: R/random_edge_nodes.R

Description

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.

Usage

1
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

1
2
3
4
set.seed(0)
gr <- tidygraph::create_ring(5)
gr <- tidygraph::mutate(gr, .idx = 1:dplyr::n())
random_edge_nodes(gr)

jhrcook/wext documentation built on May 17, 2021, 1:19 a.m.