# NOT RUN {
# Set a seed
set.seed(23)
# Create a graph with 6 nodes and 5 edges
graph <-
create_graph() %>%
add_path(n = 6) %>%
set_node_attrs(
node_attr = value,
values = rnorm(node_count(.), 5, 2))
# Select all nodes where the node
# attribute `value` is less than 5
graph <-
graph %>%
select_nodes(
conditions = value < 5.0)
# Show the graph's node data frame
graph %>%
get_node_df()
#> id type label value
#> 1 1 <NA> 1 5.090874
#> 2 2 <NA> 2 8.151559
#> 3 3 <NA> 3 5.436577
#> 4 4 <NA> 4 2.906929
#> 5 5 <NA> 5 4.422623
#> 6 6 <NA> 6 5.963101
# Cache available values from the node attribute
# `value` from the nodes that are selected;
# ensure that the cached vector is numeric
graph <-
graph %>%
cache_node_attrs_ws(
node_attr = value,
name = "node_value")
# Get the cached vector with `get_cache()`
graph %>%
get_cache(name = "node_value")
#> [1] 2.906929 4.422623
# }
Run the code above in your browser using DataLab