Some functions in the 'tidygraph' package require the index of a node. This function evalutes an input expression in the dplyr::filter() function in the node tibble of a tidygraph object and returns the indices of the nodes that pass.

get_node_index(gr, expr)

Arguments

gr

a tidygraph

expr

an expression to be quoted and evaluated in the context of the node tibble of the tidygraph object

Examples

get_node_index(quick_barabasi(10), name == "B")
#> [1] 2
get_node_index(quick_barabasi(10), name %in% c("B", "C", "D"))
#> [1] 2 3 4
get_node_index(quick_barabasi(10), stringr::str_detect(name, "A|B|C"))
#> [1] 1 2 3