get_edge_attrs: Get edge attribute values

Description Usage Arguments Value Examples

View source: R/get_edge_attrs.R

Description

From a graph object of class dgr_graph, get edge attribute values for one or more edges.

Usage

1
get_edge_attrs(graph, edge_attr, from = NULL, to = NULL)

Arguments

graph

a graph object of class dgr_graph.

edge_attr

the name of the attribute for which to get values.

from

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

to

an optional vector of node IDs from which the edge is incoming for filtering the list of edges.

Value

a named vector of edge attribute values for the attribute given by edge_attr by edge.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Create a simple graph where
# edges have an edge attribute
# named `value`
graph <-
  create_graph() %>%
  add_n_nodes(n = 4) %>%
  {
    edges <-
      create_edge_df(
        from = c(1, 2, 1, 4),
          to = c(2, 3, 4, 3),
         rel = "rel")
    add_edge_df(
      graph = .,
      edge_df = edges)
  } %>%
  set_edge_attrs(
    edge_attr = value,
    values = 1.6,
    from = 1,
      to = 2) %>%
  set_edge_attrs(
    edge_attr = value,
    values = 4.3,
    from = 1,
      to = 4) %>%
  set_edge_attrs(
    edge_attr = value,
    values = 2.9,
    from = 2,
      to = 3) %>%
  set_edge_attrs(
    edge_attr = value,
    values = 8.4,
    from = 4,
      to = 3)

# Get the values for the
# `value` edge attribute
graph %>%
  get_edge_attrs(
    edge_attr = value)
#> 1->2 2->3 1->4 4->3
#>  1.6  2.9  4.3  8.4

# To only return edge attribute
# values for specified edges, use
# the `from` and `to` arguments
graph %>%
  get_edge_attrs(
    edge_attr = value,
    from = c(1, 2),
      to = c(2, 3))
#> 1->2 2->3
#>  1.6  2.9

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