select_nodes: Select nodes in a graph

Description Usage Arguments Value Examples

Description

Select nodes from a graph object of class dgr_graph.

Usage

1
select_nodes(graph, conditions = NULL, set_op = "union", nodes = NULL)

Arguments

graph

a graph object of class dgr_graph.

conditions

an option to use filtering conditions for the retrieval of nodes.

set_op

the set operation to perform upon consecutive selections of graph nodes. This can either be as a union (the default), as an intersection of selections with intersect, or, as a difference on the previous selection, if it exists.

nodes

an optional vector of node IDs for filtering list of nodes present in the graph.

Value

a graph object of class dgr_graph.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Create a node data frame (ndf)
ndf <-
  create_node_df(
    n = 4,
    type = c("a", "a", "z", "z"),
    label = TRUE,
    value = c(3.5, 2.6, 9.4, 2.7))

# Create an edge data frame (edf)
edf <-
  create_edge_df(
    from = c(1, 2, 3),
    to = c(4, 3, 1),
    rel = c("a", "z", "a"))

# Create a graph with the ndf and edf
graph <-
  create_graph(
    nodes_df = ndf,
    edges_df = edf)

# Explicitly select nodes `1` and `3`
graph <-
  graph %>%
  select_nodes(nodes = c(1, 3))

# Verify that the node selection has been made
# using the `get_selection()` function
get_selection(graph)
#> [1] 1 3

# Select nodes based on the node `type`
# being `z`
graph <-
  graph %>%
  clear_selection() %>%
  select_nodes(
    conditions = "type == 'z'")

# Verify that an node selection has been made, and
# recall that the `3` and `4` nodes are of the
# `z` type
get_selection(graph)
#> [1] 3 4

# Select edges based on the node value attribute
# being greater than 3.0 (first clearing the current
# selection of nodes)
graph <-
  graph %>%
  clear_selection() %>%
  select_nodes(
    conditions = "value > 3.0")

# Verify that the correct node selection has been
# made; in this case, nodes `1` and `3` have values
# for `value` greater than 3.0
get_selection(graph)
#> [1] 1 3


Search within the DiagrammeR package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.