select_nodes {DiagrammeR} | R Documentation

## Select nodes in a graph

### Description

Select nodes from a graph object of class `dgr_graph`.

### Usage

    select_nodes(graph, node_attr = NULL, search = NULL, set_op = "union",
      nodes = NULL)

### Arguments

`graph` | a graph object of class `dgr_graph` that is created using `create_graph`.
`node_attr` | an optional character vector of node attribute values for filtering the node ID values returned.
`search` | an option to provide a logical expression with a comparison operator (`>`, `<`, `==`, or `!=`) followed by a number for numerical filtering, or, a regular expression for filtering the nodes returned through string matching.
`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`, 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

    ## Not run:
    # Create a simple graph
    nodes <-
      create_nodes(nodes = c("a", "b", "c", "d"),
                   type = "letter",
                   label = TRUE,
                   value = c(3.5, 2.6, 9.4, 2.7))

    edges <-
      create_edges(from = c("a", "b", "c"),
                   to = c("d", "c", "a"),
                   rel = "leading_to")

    graph <-
      create_graph(nodes_df = nodes,
                   edges_df = edges)

    # Select nodes "a" and "c"
    graph <- select_nodes(graph = graph, nodes = c("a", "c"))

    # Verify that a node selection has been made
    get_selection(graph)
    #> $nodes
    #> [1] "a" "c"

    ## End(Not run)

[Package DiagrammeR version 0.8.2 Index]