get_nodes {DiagrammeR} | R Documentation

## Get a vector of node ID values

### Description

Obtain a vector of node ID values from a graph object or a node data frame. An optional filter by node attribute can limit the set of node ID values returned.

### Usage

    get_nodes(x, node_attr = NULL, match = NULL)

### Arguments

`x` | either a graph object of class `dgr_graph` that is created using `create_graph` or a node data frame.
`node_attr` | an optional character vector of node attribute values for filtering the node ID values returned.
`match` | an option to provide a logical expression with a comparison operator (`>`, `<`, `==`, or `!=`) followed by a number for numerical filtering, or, a character string for filtering the edges returned through string matching.

### Value

a vector of node ID values.

### Examples

    ## Not run:
    # Before getting node ID values, create a simple graph
    nodes <-
      create_nodes(nodes = c("a", "b", "c", "d"),
                   type = "letter",
                   color = c("red", "green", "grey", "blue"),
                   value = c(3.5, 2.6, 9.4, 2.7))

    graph <-
      create_graph(nodes_df = nodes)

    # Get a vector of all nodes in a graph
    get_nodes(graph)
    #> [1] "a" "b" "c" "d"

    # Get a vector of node ID values from a node data frame
    get_nodes(nodes)
    #> [1] "a" "b" "c" "d"

    # Get a vector of node ID values using a numeric
    # comparison (i.e., all nodes with 'value' attribute
    # greater than 3)
    get_nodes(graph,
              node_attr = "value",
              match = "> 3")
    #> [1] "a" "c"

    # Get a vector of node ID values using a match
    # pattern (i.e., all nodes with 'color' attribute
    # of "green")
    get_nodes(graph,
              node_attr = "color",
              match = "green")
    #> [1] "b"

    ## End(Not run)

[Package DiagrammeR version 0.8.2 Index]