VPSPulse Mirrors

High-Performance Open-Source Archive

Using magrittr pipes

Using magrittr pipes

Jakob Bossek

2017-12-20

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)
#> GRAPHERATOR GRAPH
#> #nodes           : 20 (UNG)
#> #edges           : 190 (CEG)
#> #weights per edge: 2 (RWG,RWG)
do.call(gridExtra::grid.arrange, c(plot(g), list(nrow = 1)))
Example network.

Example network.

Need mirroring services?
Contact our team at info@vpspulse.com.

Mirror powered by VPSpulse

Infrastructure sponsored by VPSPulse & Secure Payments by ArionPay.