as_network {interplex}R Documentation

Coerce objects to class 'network'

Description

Coerce objects to 'network' objects, as implemented in the network package.

Usage

as_network(x, ...)

## Default S3 method:
as_network(x, index = NULL, ...)

## S3 method for class 'Rcpp_SimplexTree'
as_network(x, index = NULL, ...)

## S3 method for class 'gudhi.simplex_tree.SimplexTree'
as_network(x, index = NULL, ...)

## S3 method for class 'igraph'
as_network(x, ...)

## S3 method for class 'network'
as_network(x, ...)

Arguments

x

An R object to be coerced. See Details.

...

Additional arguments passed to methods.

index

Character string to be added as a vertex attribute containing 0-simplex indices. Ignored if NULL (the default).

Details

as_network() is a generic function with specific methods for different simplicial complex S3 classes. It returns a network object.

Value

An object of class 'network'.

Examples

if (requireNamespace("TDA", quietly = TRUE)) {
  # convert a TDA filtration object
  t <- 2 * pi * c(0, 1, 3, 6) / 7
  rf <- TDA::ripsFiltration(
    cbind(x = cos(t), y = sin(t)),
    maxdimension = 2L, maxscale = 1.7
  )
  print(rf$cmplx)
  nw_rf <- as_network(rf)
  print(nw_rf)
  nw_rf2 <- as_network(rf$cmplx)
  print(nw_rf2)
}

if (requireNamespace("simplextree", quietly = TRUE)) {
  # convert a simplextree object
  st <- simplextree::simplex_tree()
  st$insert(list(3:5, 5:6, 8))
  nw_st <- as_network(st)
  print(nw_st)
}

## Not run: 

if (requireNamespace("reticulate", quietly = TRUE)) {
  # convert a Python GUDHI simplex tree
  gd <- reticulate::import("gudhi")
  gd_st <- gd$SimplexTree()
  for (s in list(3:5, 5:6, 8)) gd_st$insert(as.list(s))
  nw_gd <- as_network(gd_st, index = "id")
  print(nw_gd)
}

## End(Not run)

if (requireNamespace("igraph", quietly = TRUE)) {
  # convert an igraph object
  ig <- igraph::graph(c(1,2, 2,3, 1,3, 3,4))
  print(ig)
  nw_ig <- as_network(ig)
  print(nw_ig)
}

[Package interplex version 0.1.2 Index]