ichunk: Create a chunking iterator

Description Usage Arguments See Also Examples

View source: R/ichunk.R

Description

Create an iterator that issues lists of values from the underlying iterable. This is useful for manually “chunking” values from an iterable.

Usage

1
ichunk(iterable, chunkSize, mode='list')

Arguments

iterable

Iterable to iterate over.

chunkSize

Maximum number of values from iterable to return in each value issued by the resulting iterator.

mode

Mode of the objects returned by the iterator.

See Also

isplitVector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Split the vector 1:10 into "chunks" with a maximum length of three
it <- ihasNext(ichunk(1:10, 3))
while (hasNext(it)) {
  print(unlist(nextElem(it)))
}

# Same as previous, but return integer vectors rather than lists
it <- ihasNext(ichunk(1:10, 3, mode='integer'))
while (hasNext(it)) {
  print(nextElem(it))
}


itertools documentation built on May 21, 2017, 3:52 a.m.
Search within the itertools package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.