cache_edge_attrs_ws {DiagrammeR} | R Documentation

## Cache edge attributes (based on a selection of edges) in the graph

### Description

From a graph object of class `dgr_graph`, get edge attribute properties for edges available in a selection and cache those values in the graph for later retrieval using `get_cache`.

Selections of edges can be performed using the following `select_...` functions: `select_edges()`, `select_last_edge()`, or `select_edges_by_node_id()`. Selections of edges can also be performed using the following traversal functions: `trav_out_edge()`, `trav_in_edge()`, or `trav_both_edge()`.

### Usage

    cache_edge_attrs_ws(graph, edge_attr, name = NULL, mode = NULL)

### Arguments

`graph` | a graph object of class `dgr_graph`.
`edge_attr` | the edge attribute from which to obtain values.
`name` | an optional name for the cached vector.
`mode` | a option to recast the returned vector of edge attribute value as `numeric` or `character`.

### Value

a graph object of class `dgr_graph`. # Set a seed set.seed(23)

# Create a graph with 6 nodes and 5 edges graph <- create_graph() add_path(n = 6) set_edge_attrs( edge_attr = value, values = rnorm(edge_count(.), 5, 2))

# Select all edges where the edge attribute # 'value' is less than 5 graph <- graph select_edges( conditions = value < 5.0)

# Show the graph's edge data frame graph get_edge_df() #> id from to rel value #> 1 1 1 2 <NA> 5.090874 #> 2 2 2 3 <NA> 8.151559 #> 3 3 3 4 <NA> 5.436577 #> 4 4 4 5 <NA> 2.906929 #> 5 5 5 6 <NA> 4.422623

# Cache available values from the edge # attribute 'value' from the edges that # are selected; ensure that the cached # vector is numeric graph <- graph cache_edge_attrs_ws( edge_attr = value, name = "edge_value")

# Get the cached vector with 'get_cache()' graph get_cache(name = "edge_value") #> [1] 2.906929 4.422623

[Package DiagrammeR version 0.9.2 Index]