# NOT RUN {
# Set a seed
set.seed(23)
# Create a graph with 10 nodes and 9 edges
graph <-
create_graph() %>%
add_n_nodes(n = 10) %>%
add_edges_w_string(
edges =
"1->2 1->3 2->4 2->5 3->6
3->7 4->8 4->9 5->10") %>%
set_edge_attrs(
edge_attr = "value",
values = rnorm(edge_count(.), 5, 2))
# Cache all values from the edge attribute
# `value` as a numeric vector
graph <-
graph %>%
cache_edge_attrs(
edge_attr = value,
name = "edge_value")
# Get the mean from all values available in
# the cache
graph %>%
get_cache(name = "edge_value") %>%
mean()
#> [1] 5.744332
# }
Run the code above in your browser using DataLab