knitr::opts_chunk$set(comment=NA)

Build Status AppVeyor Build Status

Iterate lists getting a window argument list to your callback.

[octostep]

[mergeLists]

octostep

octostep::octostep(x, func,  # x and func are required
                   pad=1L, use.names=TRUE, transform.previous=FALSE)

Return

List

Examples

# see arguments evolve
octo <- octostep::octostep(as.list(1L:3L), function(pre, cur, nxt) {
  c(pre=if (is.null(pre)) NA else pre, 
    cur=cur, 
    nxt=if (is.null(nxt)) NA else nxt)
})

print(octo)
# increased padding
paddle <- octostep::octostep(as.list(1L:5L), 
                             function(pre1, pre2, cur, nxt1, nxt2) {
                               c(pre1=if (is.null(pre1)) NA else pre1, 
                                 pre2=if (is.null(pre2)) NA else pre2, 
                                 cur=cur, 
                                 nxt1=if (is.null(nxt1)) NA else nxt1,
                                 nxt2=if (is.null(nxt2)) NA else nxt2)
                             }, pad=2L)

print(paddle)
# cool input
fable <- list(x=4L, y=1L, z=9L, a=0L, b=0L)

# transform previous items while iterating
transformer <- octostep::octostep(fable, function(pre, cur, nxt) {
  if (!octostep::any.null(pre, nxt)) sum(pre, cur, nxt) else cur
}, pad=1L, use.names=TRUE, transform.previous=TRUE)  # transformers

print(transformer)

mergeLists

octostep::mergeLists(x, func,  # x and func are required
                     which.names=NULL, 
                     from=c('left', 'right')[1],
                     allow.ragged=FALSE, 
                     warn=if (allow.ragged) TRUE else FALSE)

Return

List

Examples

# new input
listoflists <- list(list('A', 'B', 'C'), list(1L, 2L, 3L))

# allows reducing from left ...
octostep::mergeLists(listoflists, function(a, b) {
  paste0(a, as.character(b))
}, from='left')
# or from right ...
octostep::mergeLists(listoflists, function(a, b) {
  paste0(a, as.character(b))
}, from='right')
# and even lists of unequal length
octostep::mergeLists(list(list(), list(1L)), function(a, b) {
  if (is.null(a)) b else a
}, allow.ragged=TRUE)


chiefBiiko/octostep documentation built on May 20, 2019, 3:34 p.m.