traverse: traverse

Description Usage Arguments Details Value Examples

View source: R/simplex_tree.R

Description

Traverses specific subsets of a simplicial complex.

Usage

1
2
3
4
5
traverse(traversal, f, ...)

straverse(traversal, f, ...)

ltraverse(traversal, f, ...)

Arguments

traversal

the type of traversal.

f

the function to apply to each simplex.

...

unused.

Details

traverse allows for traversing ordered subsets of the simplex tree. The specific subset and order are determined by the choice of traversal: examples include the preorder traversal, the cofaces traversal, etc. See the links below. Each simplex in the traversal is passed as the first and only argument to f, one per simplex in the traversal. traverse does nothing with the result; if you want to collect the results of applying f to each simplex into a list, use ltraverse (or straverse), which are meant to be used like lapply and sapply, respectively.

Value

NULL; for list or vector-valued returns, use ltraverse and straverse respectively.

Examples

1
2
3
4
5
6
7
8
9
## Starter example complex 
st <- simplex_tree()
st %>% insert(list(1:3, 2:5))

## Print out complex using depth-first traversal. 
st %>% preorder() %>% traverse(print)

## Collect the last labels of each simplex in the tree. 
last_labels <- st %>% preorder() %>% straverse(function(simplex){ tail(simplex, 1) })

simplextree documentation built on Sept. 13, 2020, 5:06 p.m.