A utils function
Arguments
- g
igraph object
- search_term
string of expression or names of node to search
- as_ids
when T return only index
- search_in
dip argument that when set to edge can search in edges
Examples
set.seed(1)
g = make_tree(12, 3)
V(g)$attr <- sample(letters, length(g))
V(g)$name <- paste0(seq(length(g)), ".", V(g)$attr)
search_idx(g, "attr == 'v'")
#> + 0/0 vertices, named, from d5e7d08:
search_idx(g, '9.w')
#> + 1/1 vertex, named, from 6e68f35:
#> [1] 9.w
# if tidygraph is loaded in environment this will work
library(tidygraph)
#>
#> Attaching package: ‘tidygraph’
#> The following object is masked from ‘package:igraph’:
#>
#> groups
#> The following object is masked from ‘package:stats’:
#>
#> filter
search_idx(g, 'node_is_root()')
#> + 1/1 vertex, named, from aee919a:
#> [1] 1.y