get_edges {DiagrammeR} | R Documentation |
Obtain a vector, data frame, or list of node IDs from a graph object or an edge data frame. An optional filter by edge attribute can limit the set of edges returned.
get_edges(x, edge_attr = NULL, match = NULL, return_type = "vector")
x |
either a graph object of class
|
edge_attr |
an optional character vector of edge attribute values for filtering the edges returned. |
match |
an option to provide a logical
expression with a comparison operator ( |
return_type |
using |
a list, data frame, or a vector object,
depending on the value given to return_type
.
# Create a node data frame (ndf) 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)) # Create an edge data frame (edf) edges <- create_edges( from = c("a", "b", "c"), to = c("d", "c", "a"), rel = "leading_to", color = c("pink", "blue", "red"), value = c(3.9, 2.5, 7.3)) # Create a graph graph <- create_graph( nodes_df = nodes, edges_df = edges) # Get all edges within a graph, returned as a list get_edges(graph) #> [[1]] #> [1] "a" "b" "c" #> #> [[2]] #> [1] "d" "c" "a" # Get all edges within a graph, returned as a # data frame get_edges(graph, return_type = "df") #> from to #> 1 a d #> 2 b c #> 3 c a # Get all edges within a graph, returned as a vector get_edges(graph, return_type = "vector") #> [1] "a -> d" "b -> c" "c -> a" # Get a vector of edges using a numeric # comparison (i.e., all edges with a `value` # attribute greater than 3) get_edges( graph, edge_attr = "value", match = "> 3", return_type = "vector") #> [1] "a -> d" "c -> a" # Get a vector of edges using a match get_edges( graph, edge_attr = "color", match = "pink", return_type = "vector") #> [1] "a -> d"