Skip to content

Obtain an edges vector in a form suitable for make_graph() #864

@szhorvat

Description

@szhorvat

What is the feature or improvement you would like to see?

There should be a function that retrieves an edge list in a form suitable for make_graph(), as well as suitable for the C function igraph_create().

as_edgelist() returns a matrix, not a vector, and converting to a vector gives the vertex IDs in the wrong order:

> g<-make_graph(c(1,2, 2,3, 3,4, 4,5))
> as.vector(as_edgelist(g, names=F))
[1] 1 2 3 4 2 3 4 5

Instead one must transpose the matrix first, which is inefficient:

> as.vector(t(as_edgelist(g, names=F)))
[1] 1 2 2 3 3 4 4 5

A more efficient way is

> .Call(igraph:::R_igraph_get_edgelist, g, F)
[1] 0 1 1 2 2 3 3 4

but this uses an internal function.

Use cases for the feature

For libraries that need to convert igraph graphs efficiently, such as leidenbase or leidenalg.

References

Metadata

Metadata

Assignees

Labels

AI 🤖For issues that can be handled by a coding agent. A scheduled workflow will look at those.wishlistFeature request that has not been chosen for implementation yet; vote or comment to prioritize it!

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions