# NOT RUN {
# Create a graph with 4 nodes
graph <-
create_graph() %>%
add_node(label = "one") %>%
add_node(label = "two") %>%
add_node(label = "three") %>%
add_node(label = "four")
# Add edges between nodes using a
# character string with node ID values
graph_node_id <-
graph %>%
add_edges_w_string(
edges = "1->2 1->3 2->4 2->3")
# Show the graph's internal edge data frame
get_edge_df(graph_node_id)
#> id from to rel
#> 1 1 1 2 <NA>
#> 2 2 1 3 <NA>
#> 3 3 2 4 <NA>
#> 4 4 2 3 <NA>
# Add edges between nodes using a
# character string with node label values
# and setting `use_labels = TRUE`; note
# that all nodes must have unique `label`
# values to use this option
graph_node_label <-
graph %>%
add_edges_w_string(
edges =
"one->two one->three
two->four two->three",
use_labels = TRUE)
# Show the graph's internal edge data frame
# (it's the same as before)
get_edge_df(graph_node_label)
#> id from to rel
#> 1 1 1 2 <NA>
#> 2 2 1 3 <NA>
#> 3 3 2 4 <NA>
#> 4 4 2 3 <NA>
# }
Run the code above in your browser using DataLab