Given a graph suggest the most efficient format out of 'graph6', 'sparse6' or 'digraph6'.
Usage
choose_format(object, ...)
# Default S3 method
choose_format(object, ...)
# S3 method for class 'list'
choose_format(object, ...)
Value
Character value out of 'graph6', 'sparse6' or 'digraph6'. If object
is a list, a vector of such values of the length equal to the length of
object
.
Details
If object
is directed, the suggested format is 'digraph6'. If
object
is undirected the function suggests 'sparse6' if density is less
than 0.15 and 'graph6' otherwise. This rule is approximate.
Examples
# From igraph ------------------------------------------------------
if(requireNamespace("igraph")) {
g <- igraph::graph.famous("Zachary")
choose_format(g)
set.seed(123)
glist <- list(
igraph::sample_gnp(n = 15, p = 0.1),
igraph::sample_gnp(n = 15, p = 0.2),
igraph::sample_gnp(n = 15, p = 0.3),
igraph::sample_gnp(n = 15, p = 0.15, directed = TRUE))
choose_format(glist)
}
#> [[1]]
#> [1] "sparse6"
#>
#> [[2]]
#> [1] "graph6"
#>
#> [[3]]
#> [1] "graph6"
#>
#> [[4]]
#> [1] "digraph6"
#>
# From network -----------------------------------------------------
if(requireNamespace("network")) {
m <- matrix(rbinom(25,1,.4),15,15)
diag(m) <- 0
g <- network::network(m, directed=FALSE)
choose_format(g)
}
#> [1] "graph6"