From a graph object of class dgr_graph, get node attribute properties for one or more nodes and cache those values in the graph for later retrieval using get_cache.

cache_node_attrs(graph, node_attr, name = NULL, mode = NULL, nodes = NULL)

Arguments

graph

a graph object of class dgr_graph.

node_attr

the node attribute from which to obtain values.

name

an optional name for the cached vector.

mode

a option to recast the returned vector of node attribute value as numeric or character.

nodes

an optional vector of node IDs for filtering the list of nodes present in the graph.

Value

a graph object of class dgr_graph.

Examples

# 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) %>%
  set_node_attrs(
    node_attr = value,
    values = rnorm(node_count(.), 5, 2)) %>%
  add_edges_w_string(
    edges =
      "1->2 1->3 2->4 2->5 3->6
       3->7 4->8 4->9 5->10")

# Cache all values from the node attribute `value`
# as a numeric vector
graph <-
  graph %>%
  cache_node_attrs(
    node_attr = value,
    name = "node_value")

# Get the mean from all values available in
# the cache
graph %>%
  get_cache(name = "node_value") %>%
  mean()
#> [1] 5.766209
# }