context_accessors: Access graph, nodes, and edges directly inside verbs

Description Usage Value Functions Examples

Description

These three functions makes it possible to directly access either the node data, the edge data or the graph itself while computing inside verbs. It is e.g. possible to add an attribute from the node data to the edges based on the terminating nodes of the edge, or extract some statistics from the graph itself to use in computations.

Usage

1
2
3
4
5
.G()

.N()

.E()

Value

Either a tbl_graph (.G()) or a tibble (.N())

Functions

Examples

1
2
3
4
5
6
# Get data from the nodes while computing for the edges
create_notable('bull') %>%
  activate(nodes) %>%
  mutate(centrality = centrality_power()) %>%
  activate(edges) %>%
  mutate(mean_centrality = (.N()$centrality[from] + .N()$centrality[to])/2)

tidygraph documentation built on May 2, 2019, 8:32 a.m.