# NOT RUN {
# Set a seed
set.seed(23)
# Create a graph with 6 nodes and 5 edges
graph <-
create_graph() %>%
add_path(6) %>%
set_edge_attrs(
"value", rnorm(edge_count(.), 5, 2))
# Select all edges where the edge attribute
# `value` is less than 5
graph <-
graph %>%
select_edges("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("value", "numeric")
# Get the cached vector and get its
# difference from 5
graph %>% get_cache() %>% {x <- .; 5 - x}
#> [1] 2.0930707 0.5773773
# }
Run the code above in your browser using DataLab