Learn R Programming

DiagrammeR (version 0.8.4)

select_nodes_by_id: Select nodes in a graph by ID values

Description

Select nodes in a graph object of class dgr_graph by their node ID values. If nodes have IDs that are monotonically increasing integer values, then numeric ranges can be used for the selection.

Usage

select_nodes_by_id(graph, nodes, set_op = "union")

Arguments

graph
a graph object of class dgr_graph that is created using create_graph.
nodes
a vector of node IDs for the selection of nodes present in the graph.
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.

Value

a graph object of class dgr_graph.

Examples

Run this code
library(magrittr)

# Create a node data frame (ndf)
nodes <- create_nodes(nodes = 1:10)

# Create a graph
graph <- create_graph(nodes_df = nodes)

# Select nodes `1` to `5` and show that
# selection of nodes with `get_selection()`
graph %>%
  select_nodes_by_id(1:5) %>%
  get_selection
#> $nodes
#> [1] "1" "2" "3" "4" "5"

Run the code above in your browser using DataLab