rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

as_long_data_frame() fails or has bad column names

Open richierocks opened this issue 7 years ago • 0 comments

Using some of the built-in graphs types, I see an error

library(igraph)
tetra <- make_graph("Tetrahedron")
as_long_data_frame(tetra)
#> Error in names(ver) <- paste0("from_", names(ver)): 'names' attribute [1] must be the same length as the vector [0]

ring <- make_ring(10)
as_long_data_frame(ring)
#> Error in names(ver) <- paste0("from_", names(ver)): 'names' attribute [1] must be the same length as the vector [0]

Making my own graph from graph_from_data_frame(), I see incorrect column names. The last two columns ought to be called from_name and to_name.

vertices <- data.frame(
  id = 1:10,
  name = letters[1:10]
)
edges <- data.frame(
  a = sample(10),
  b = sample(10),
  score = runif(10)
)
g <- graph_from_data_frame(edges, vertices = vertices)
as_long_data_frame(g)
#>    from to     score ver[el[, 1], ] ver2[el[, 2], ]
#> 1     4  5 0.2277997              d               e
#> 2     2  4 0.1393521              b               d
#> 3     1  8 0.4443383              a               h
#> 4     7  7 0.4660912              g               g
#> 5     9 10 0.9414583              i               j
#> 6     2  6 0.1375254              b               f
#> 7     8  9 0.5932517              h               i
#> 8     3  5 0.4985059              c               e
#> 9     1 10 0.5559388              a               j
#> 10    3  6 0.7224063              c               f

richierocks avatar Sep 14 '18 00:09 richierocks