| spmap | R Documentation |
These functions apply a function to each unique structure in a glycan structure vector along with corresponding elements from multiple other vectors, taking advantage of hash-based deduplication to avoid redundant computation. Similar to purrr pmap functions, but optimized for glycan structure vectors.
spmap(.l, .f, ...)
spmap_vec(.l, .f, ..., .ptype = NULL)
spmap_lgl(.l, .f, ...)
spmap_int(.l, .f, ...)
spmap_dbl(.l, .f, ...)
spmap_chr(.l, .f, ...)
spmap_structure(.l, .f, ...)
.l |
A list where the first element is a glycan structure vector (glyrepr_structure) and the remaining elements are vectors of the same length or length 1 (will be recycled). |
.f |
A function that takes an igraph object (from first element of |
... |
Additional arguments passed to |
.ptype |
A prototype for the return type (for |
These functions only compute .f once for each unique combination of structure and corresponding
values from other vectors, then map the results back to the original vector positions.
spmap_structure() reuses unchanged graphs and validates and canonicalizes
changed graphs returned by .f. A callback that changes vertex identities
or components of a floating structure must also update its floating_parts
and floating_substituents metadata.
NA Handling: NA elements in the first argument (glycan structure vector) are preserved in the output.
Time Complexity Performance:
Performance scales with unique combinations of all arguments rather than total vector length. When argument vectors are highly redundant, performance approaches O(unique_structures). Scaling factor shows time increase when vector size increases 20x.
Return Types:
spmap(): Returns a list with the same length as the input vectors
spmap_vec(): Returns an atomic vector with the same length as the input vectors
spmap_lgl(): Returns a logical vector
spmap_int(): Returns an integer vector
spmap_dbl(): Returns a double vector
spmap_chr(): Returns a character vector
spmap_structure(): Returns a new glycan structure vector (.f must return igraph objects)
spmap(): A list
spmap_vec(): An atomic vector of type specified by .ptype
spmap_lgl/int/dbl/chr(): Atomic vectors of the corresponding type
spmap_structure(): A new glyrepr_structure object
# Create structure vectors with duplicates
core1 <- o_glycan_core_1()
core2 <- n_glycan_core()
structures <- c(core1, core2, core1) # core1 appears twice
weights <- c(1.0, 2.0, 1.0) # corresponding weights
factors <- c(2, 3, 2) # corresponding factors
# Map a function that uses structure, weight, and factor
spmap_dbl(list(structures, weights, factors),
function(g, w, f) igraph::vcount(g) * w * f)
# Use purrr-style lambda functions
spmap_dbl(list(structures, weights, factors), ~ igraph::vcount(..1) * ..2 * ..3)
# Test with recycling
spmap_dbl(list(structures, 2.0, 3), ~ igraph::vcount(..1) * ..2 * ..3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.