Skip to contents

The graphNEL class is defined in the graph package, it is another way to represent graphs. graph_from_graphnel() takes a graphNEL graph and converts it to an igraph graph. It handles all graph/vertex/edge attributes. If the graphNEL graph has a vertex attribute called ‘name’ it will be used as igraph vertex attribute ‘name’ and the graphNEL vertex names will be ignored.

Usage

graph_from_graphnel(graphNEL, name = TRUE, weight = TRUE, unlist.attrs = TRUE)

Arguments

graphNEL

The graphNEL graph.

name

Logical scalar, whether to add graphNEL vertex names as an igraph vertex attribute called ‘name’.

weight

Logical scalar, whether to add graphNEL edge weights as an igraph edge attribute called ‘weight’. (graphNEL graphs are always weighted.)

unlist.attrs

Logical scalar. graphNEL attribute query functions return the values of the attributes in R lists, if this argument is TRUE (the default) these will be converted to atomic vectors, whenever possible, before adding them to the igraph graph.

Value

graph_from_graphnel() returns an igraph graph object.

Details

Because graphNEL graphs poorly support multiple edges, the edge attributes of the multiple edges are lost: they are all replaced by the attributes of the first of the multiple edges.

Examples

## Undirected
g <- make_ring(10)
V(g)$name <- letters[1:10]
GNEL <- as_graphnel(g)
g2 <- graph_from_graphnel(GNEL)
g2
#> IGRAPH e5bee40 UNW- 10 10 -- Ring graph
#> + attr: name (g/c), mutual (g/l), circular (g/l), name (v/c), weight
#> | (e/n)
#> + edges from e5bee40 (vertex names):
#>  [1] a--b a--j b--c c--d d--e e--f f--g g--h h--i i--j

## Directed
g3 <- make_star(10, mode = "in")
V(g3)$name <- letters[1:10]
GNEL2 <- as_graphnel(g3)
g4 <- graph_from_graphnel(GNEL2)
g4
#> IGRAPH d58224d DNW- 10 9 -- In-star
#> + attr: name (g/c), mode (g/c), center (g/n), name (v/c), weight (e/n)
#> + edges from d58224d (vertex names):
#> [1] b->a c->a d->a e->a f->a g->a h->a i->a j->a