-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better cooperation of as_data_frame() and graph_from_data_frame() ? #223
Comments
We have the same problem in our scripts. This seems weird as the same function call to What can we do to help debugging this? |
Quick update to this: When I try a cascade of g <- make_graph(~ A, B -- C, C -- D)
V(g)$a <- letters[1:4]
dlist <- as_data_frame(g, what="both")
r <- graph_from_data_frame(dlist$edges, vertices=dlist$vertices, directed=TRUE)
r <- as.undirected(r)
identical_graphs(g, r)
# [1] TRUE I hope this helps identifying the problem. |
Any news on this? |
Thanks, confirmed. The first problem seems to be due to a bogus difference between an empty vector and The second problem can be fixed with a more careful implementation of library(igraph, warn.conflicts = FALSE)
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
waldo::compare(unclass(g)[1:9], unclass(r)[1:9])
#> `names(old[[9]][[4]])` is a character vector ()
#> `names(new[[9]][[4]])` is absent
# 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 Created on 2023-03-31 with reprex v2.0.2 |
The first problem is now tracked in #756. |
For the second problem, there are a lot of tests, and probably downstream packages, that rely on After having tinkered with it, I'd like to change the following in
We can also extend If we want to be backward-compatible, we could request numeric vertex IDs in the edges to be wrapped by |
It would be great to have the following functionality back:
In other words, using (parts of) output of
as_data_frame
ingraph_from_data_frame
directly. I recall it was possible before recent API changes. Above will work ifg
has vertexname
s, 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.g
andr
are notidentical_graphs
in# 1
. Both edge and vertex data frames are identical. Am I missing something?The text was updated successfully, but these errors were encountered: