Methods for changing graph representations

coerceGraph(object, class)

graph_as(object, outtype, intype = NULL)

Arguments

object

A graph object

class

The desired output class

outtype

The desired output outtype

intype

The desired output outtype (only relevant if object is a list)

Details

coerceGraph is used in the book "Graphical models with R". A more generic approach is as().

Examples


g1 <- ug(~a:b+b:c)
as(g1, "igraph")
#> IGRAPH cb802aa UN-- 3 2 -- 
#> + attr: name (v/c)
#> + edges from cb802aa (vertex names):
#> [1] a--b b--c
as(g1, "matrix")
#>   a b c
#> a 0 1 0
#> b 1 0 1
#> c 0 1 0
as(g1, "Matrix")
#> 3 x 3 sparse Matrix of class "dsCMatrix"
#>   a b c
#> a . 1 .
#> b 1 . 1
#> c . 1 .
as(g1, "dgCMatrix")
#> 3 x 3 sparse Matrix of class "dgCMatrix"
#>   a b c
#> a . 1 .
#> b 1 . 1
#> c . 1 .

## graph_as(g1, "ugList") ## Fails
## getCliques(g1)         ## Works

l1 <- list(c("a" ,"b"), c("b", "c"))
graph_as(l1, "graphNEL", "ugList")