Using magrittr pipes

knitr::opts_chunk$set(collapse = T, comment = "#>", warning = FALSE, message = FALSE, fig.align = "center")
options(tibble.print_min = 4L, tibble.print_max = 4L)

Improving code readability

Since each generator function expects the graph object as its first argument one can make use of the fantastic magrittr pipes to improve reading. See the documentation of the magrittr package for details on the forward-pipe operator.

library(grapherator)
library(magrittr)

set.seed(1) # reproducability
g = graph(lower = 0, upper = 10) %>%
  addNodes(n = 20, generator = addNodesUniform) %>%
  addEdges(generator = addEdgesComplete) %>%
  addWeights(generator = addWeightsRandom, method = runif, min = 5, max = 10) %>%
  addWeights(generator = addWeightsRandom, method = runif, min = 5, max = 10)
print(g)
do.call(gridExtra::grid.arrange, c(plot(g), list(nrow = 1)))


Try the grapherator package in your browser

Any scripts or data that you put into this service are public.

grapherator documentation built on May 1, 2019, 8:19 p.m.