choose_format: Choose most efficient format heuristically

View source: R/choose_format.R

choose_formatR Documentation

Choose most efficient format heuristically

Description

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, ...)

Arguments

object

Igraph/network object or list thereof

...

other arguments, currently ignored

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.

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.

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)
}

# 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)
}

mbojan/rgraph6 documentation built on Sept. 25, 2024, 2:14 a.m.