Skip to contents

These functions take a character vector of 'sparse6' symbols and return a list of other types of objects:

  • edgelist_from_sparse6() creates edgelist matrices

  • igraph_from_sparse6() creates 'igraph' objects. Requires package igraph to be installed.

  • network_from_sparse6() creates 'network' objects. Requires package network to be installed.

Usage

edgelist_from_sparse6(s6)

igraph_from_sparse6(s6)

network_from_sparse6(s6)

Arguments

s6

character vector of 'sparse6' symbols

Value

The returned object is:

  • for edgelist_from_sparse6(), a list of the same length as its input of two-column edgelist matrices. The matrix has a gorder attribute storing the number of vertices in the graph.

  • for igraph_from_sparse6(), a list of 'igraph' objects

  • for network_from_sparse6(), a list of 'network' objects

See also

as_sparse6() for encoding network data objects as 'sparse6' symbols.

Examples

elm <- structure(c(1, 1, 2, 2, 4, 4, 5, 6, 9, 10, 7, 8, 4, 8, 6, 8,  
  8, 5, 4, 6), .Dim = c(10L, 2L))
s6 <- as_sparse6(elm, n = 10)

# To edgelist matrix -------------------------------------------------------
edgelist_from_sparse6(s6)
#> $`:IeEgqO_CXHt`
#>       [,1] [,2]
#>  [1,]    2    4
#>  [2,]    4    6
#>  [3,]    5    6
#>  [4,]    1    7
#>  [5,]    1    8
#>  [6,]    2    8
#>  [7,]    4    8
#>  [8,]    5    8
#>  [9,]    4    9
#> [10,]    6   10
#> attr(,"gorder")
#> [1] 10
#> 

# To igraph object ---------------------------------------------------------
if(requireNamespace("igraph", quietly=TRUE)) {
  igraph_from_sparse6(s6)
}
#> $`:IeEgqO_CXHt`
#> IGRAPH 9c2aede U--- 10 10 -- 
#> + edges from 9c2aede:
#>  [1] 2-- 4 4-- 6 5-- 6 1-- 7 1-- 8 2-- 8 4-- 8 5-- 8 4-- 9 6--10
#> 

# To network object --------------------------------------------------------
if(requireNamespace("network", quietly=TRUE)) {
  network_from_sparse6(s6)
}
#> $`:IeEgqO_CXHt`
#>  Network attributes:
#>   vertices = 10 
#>   directed = FALSE 
#>   hyper = FALSE 
#>   loops = FALSE 
#>   multiple = FALSE 
#>   bipartite = FALSE 
#>   total edges= 10 
#>     missing edges= 0 
#>     non-missing edges= 10 
#> 
#>  Vertex attribute names: 
#>     vertex.names 
#> 
#> No edge attributes
#>