Open Pozdniakov opened 4 years ago
How could it be avoided so that the graph data can be exported to a data.frame?
One option is to temporarily remove the name
vertex attribute from the graph before the conversion to a data frame. We can probably add an option to as_data_frame()
that decides whether vertex names are to be used or not. The if (is_named(x))
condition in the code would have to be adjusted to if (use.names && is_named(x))
.
@ntamas I started to get the error described above in code which worked a couple of days ago. Updating all packages of R didn't help.
How to remove the name
vertex attribute? Trying this:
graph.tmp <- graph.all.ties
V(graph.tmp)$name <- NULL
graph.all.ties.largetable <- as_long_data_frame(graph.tmp)
but getting the error:
Error in `V<-`(`*tmp*`, value = 1:2111) : invalid indexing
Help would me much appreciated, as well as - in the longer run - adding a parameter something like row.names = FALSE to the the functions which export dataframes from igraph objects.
Can you use remove.vertex.attribute()
for now?
library(igraph, warn.conflicts = FALSE)
g <- make_ring(10)
V(g)$name <- paste0("v", 1:10)
g
#> IGRAPH a00972f UN-- 10 10 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c)
#> + edges from a00972f (vertex names):
#> [1] v1--v2 v2--v3 v3--v4 v4--v5 v5--v6 v6--v7 v7--v8 v8--v9 v9--v10
#> [10] v1--v10
remove.vertex.attribute(g, "name")
#> IGRAPH a00972f U--- 10 10 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l)
#> + edges from a00972f:
#> [1] 1-- 2 2-- 3 3-- 4 4-- 5 5-- 6 6-- 7 7-- 8 8-- 9 9--10 1--10
V(g)$name <- NULL
#> Error in `V<-`(`*tmp*`, value = structure(1:10, names = c("v1", "v2", : invalid indexing
Created on 2023-03-16 with reprex v2.0.2
Perhaps we introduced a regression with a recent update, I'll double-check.
Use the new name instead, delete_vertex_attr()
.
I'm seeing the following with igraph 1.3.5, unlikely to be a regression:
library(igraph, warn.conflicts = FALSE)
g <- make_ring(10)
V(g)$name <- paste0("v", 1:10)
V(g)$name <- NULL
#> Error in `V<-`(`*tmp*`, value = structure(1:10, names = c("v1", "v2", : invalid indexing
Created on 2023-03-16 with reprex v2.0.2
Thanks a lot.
BTW I now discovered the source of the trouble: I had a column named "name" (for first name of persons) in the dataframe from which I created the igraph object. It did create it, and only as_long_data_frame(g)
has shown the error.
So if somebody is struggling with this row.names error, check whether V(g)$name is really what you think it is.
Error in `.rowNamesDF<-`(x, value = value) : duplicate 'row.names' are not allowed Warning: non-unique values when setting 'row.names':
So, the first vertex feature is used as row names for exported data.frame. row.names are not allowed to be duplicates. If my first vertex feature is not unique, I need to create "dummy" feature or id and move this column to be the first one. Maybe
as_data_frame()
function can be modified to avoid exporting data.frame with row.names?P.S. I think that this issue is similar to #46