DiagrammeR (version 0.9.2)

set_cache: Cache a vector in the graph

Description

Place any in the cache of a graph object of class dgr_graph.

Usage

set_cache(graph, name = NULL, to_cache, col = NULL)

Arguments

graph

a graph object of class dgr_graph.

name

an optional name for the cached vector.

to_cache

any vector or data frame.

col

if a data frame is provided in to_cache then a column name from that data frame must provided here.

Value

a graph object of class dgr_graph.

Examples

Run this code
# NOT RUN {
# Create a random graph
graph <-
  create_random_graph(
    n = 10, m = 22,
    set_seed = 23)

# Get the closeness values for all nodes from `1`
# to `10` and store in the graph's cache
graph <-
  graph %>%
  set_cache(
    name = "closeness_vector",
    to_cache = get_closeness(.),
    col = "closeness")

# Get the graph's cache
get_cache(
  graph,
  name = "closeness_vector")
#> [1] 0.07142857 0.07142857 0.07142857 0.06250000
#> [5] 0.07692308 0.09090909 0.06666667 0.05882353
#> [9] 0.07692308 0.07692308

# Get the difference of betweenness and closeness
# values for nodes in the graph and store in the
# graph's cache
graph <-
  graph %>%
  set_cache(
    name = "difference",
    to_cache = get_betweenness(.)$betweenness -
               get_closeness(.)$closeness)

# Get the graph's cache
get_cache(
  graph,
  name = "difference")
#> [1] 5.83333333  4.83333333  1.71428571 -0.06250000
#> [5] 5.66117216 20.43290043  3.26666667 -0.05882353
#> [9] 3.66117216  3.99450549
# }

Run the code above in your browser using DataLab