cache_edge_attrs: Cache edge attributes in the graph

Description Usage Arguments Value Examples

View source: R/cache_edge_attrs.R

Description

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

Usage

1
2
cache_edge_attrs(graph, edge_attr, name = NULL, mode = NULL, from = NULL,
  to = 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.

from

an optional vector of node IDs from which the edge is outgoing for filtering the list of edges present in the graph.

to

an optional vector of node IDs to which the edge is incoming for filtering the list of edges present in the graph.

Value

a graph object of class dgr_graph.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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

DiagrammeR documentation built on Sept. 7, 2017, 1:06 a.m.