It would be great to have the following functionality back:
dlist <- as_data_frame(g, what="both")
graph_from_data_frame(dlist$edges, vertices=dlist$vertices)
In other words, using (parts of) output of as_data_frame in graph_from_data_frame directly. I recall it was possible before recent API changes. Above will work if g has vertex names, but it won't if it does not. See the following reprex:
library(igraph)
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
g <- make_graph(~ A, B -- C, C -- D)
V(g)$a <- letters[1:4]
g1 <- delete_vertex_attr(g, "name")
# 1
dlist <- as_data_frame(g, what="both")
# Works if `g` has names
r <- graph_from_data_frame(dlist$edges, vertices=dlist$vertices, directed=is_directed(g))
identical_graphs(g, r) # Why?
#> [1] FALSE
identical(dlist, as_data_frame(r, what="both"))
#> [1] TRUE
# 2
dlist1 <- as_data_frame(g1, what="both")
# Won't work if `g` does not have names
graph_from_data_frame(dlist1$edges, vertices=dlist1$vertices, directed=is_directed(g1))
#> Error in graph_from_data_frame(dlist1$edges, vertices = dlist1$vertices, : Some vertex names in edge list are not listed in vertex data frame
In particular:
- I think the main reason that this connection is lost is that
as_data_frame( . , what="vertices") does not include the vertex IDs as the first column anymore.
- I don't understand why
g and r are not identical_graphs in # 1. Both edge and vertex data frames are identical. Am I missing something?
It would be great to have the following functionality back:
In other words, using (parts of) output of
as_data_frameingraph_from_data_framedirectly. I recall it was possible before recent API changes. Above will work ifghas vertexnames, but it won't if it does not. See the following reprex:In particular:
as_data_frame( . , what="vertices")does not include the vertex IDs as the first column anymore.gandrare notidentical_graphsin# 1. Both edge and vertex data frames are identical. Am I missing something?