| as_cmplx {interplex} | R Documentation | 
Coerce objects to lists of simplices
Description
Coerce objects to lists of simplices, as used by the TDA package.
Usage
as_cmplx(x, ...)
## Default S3 method:
as_cmplx(x, ...)
## S3 method for class 'Rcpp_SimplexTree'
as_cmplx(x, ...)
## S3 method for class 'gudhi.simplex_tree.SimplexTree'
as_cmplx(x, ...)
## S3 method for class 'igraph'
as_cmplx(x, index = NULL, ...)
## S3 method for class 'network'
as_cmplx(x, index = NULL, ...)
Arguments
| x | An R object to be coerced. See Details. | 
| ... | Additional arguments passed to methods. | 
| index | Integer-valued vertex attribute to be used as 0-simplex indices.
Ignored if  | 
Details
as_cmplx() is a generic function with specific methods for different
simplicial complex S3 classes. It returns a list of integer vectors, each of
which represents a simplex, and all simplices are included in the list.
When a filtration is constructed using TDA::*Filtration(), the first named
element of the returned list, cmplx, is a list whose ith element
contains the vertices of the ith simplex.
Value
A list of integer vectors, each encoding one simplex.
Examples
if (requireNamespace("TDA", quietly = TRUE)) {
  # pick the simplicial complex from 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)
  cp_rf <- as_cmplx(rf)
  print(cp_rf)
}
if (requireNamespace("simplextree", quietly = TRUE)) {
  # convert a simplextree object
  st <- simplextree::simplex_tree()
  st$insert(list(3:5, 5:6, 8))
  cp_st <- as_cmplx(st)
  print(cp_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))
  cp_gd <- as_cmplx(gd_st)
  print(cp_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))
  set.seed(0L)
  ig <- igraph::set_vertex_attr(ig, "id", value = sample(igraph::vcount(ig)))
  print(ig)
  cp_ig <- as_cmplx(ig, index = "id")
  print(cp_ig)
}
if (requireNamespace("network", quietly = TRUE)) {
  # convert a network object
  el <- data.frame(tails = c(1, 2, 1, 3), heads = c(2, 3, 3, 4))
  nw <- network::network.edgelist(el, network::network.initialize(4))
  print(nw)
  cp_nw <- as_cmplx(nw)
  print(cp_nw)
}
[Package interplex version 0.1.2 Index]