duplicate row.names makes exporting igraph to data.frame impossible.
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
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
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.2.2 (2022-10-31)
#> os macOS Ventura 13.2.1
#> system aarch64, darwin20
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Zurich
#> date 2023-03-16
#> pandoc 2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> cli 3.6.0 2023-01-09 [1] CRAN (R 4.2.0)
#> digest 0.6.31 2022-12-11 [1] CRAN (R 4.2.0)
#> evaluate 0.20 2023-01-17 [1] CRAN (R 4.2.0)
#> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.2.0)
#> fs 1.6.1 2023-02-06 [1] CRAN (R 4.2.0)
#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0)
#> htmltools 0.5.4 2022-12-07 [1] CRAN (R 4.2.0)
#> igraph * 1.3.5 2022-09-22 [1] Github (cran/igraph@602c738)
#> knitr 1.42 2023-01-25 [1] CRAN (R 4.2.0)
#> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0)
#> purrr 1.0.1 2023-01-10 [1] CRAN (R 4.2.0)
#> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.0)
#> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.0)
#> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.2.0)
#> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.2.0)
#> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.0)
#> rlang 1.1.0.9000 2023-03-14 [1] Github (r-lib/rlang@9b45027)
#> rmarkdown 2.20 2023-01-19 [1] CRAN (R 4.2.0)
#> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.2.0)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0)
#> styler 1.9.1 2023-03-04 [1] CRAN (R 4.2.0)
#> vctrs 0.5.2.9000 2023-03-14 [1] Github (r-lib/vctrs@0dea6ca)
#> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0)
#> xfun 0.37 2023-01-31 [1] CRAN (R 4.2.0)
#> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.2.0)
#>
#> [1] /Users/kirill/Library/R/arm64/4.2/library
#> [2] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
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.