Add one or more edges using a text string

Share:

Description

With a graph object of class dgr_graph, add one or more edges to the graph using a text string. For a directed graph, the string object should be formatted as a series of node ID values as [node_ID_1]->[node_ID_2] separated by a single space. For undirected graphs, -- should replace ->.

Usage

1
add_edges_w_string(graph, edges, rel = NULL)

Arguments

graph

a graph object of class dgr_graph that is created using create_graph.

edges

a single-length vector with a character string specifying the edges.

rel

an optional vector specifying the relationship between the connected nodes.

Value

a graph object of class dgr_graph.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
library(magrittr)

# Create a graph with 10 nodes
graph <-
  create_graph() %>%
  add_n_nodes(10)

# Add edges between nodes using a character string
graph <-
  graph %>%
  add_edges_w_string(
    "1->2 1->3 2->4 2->5 3->6 3->7 4->8 4->9 5->10")

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.