Skip to contents

Basic methods

  • is.iteror – Check whether a function has class ‘iteror’.
  • iteror – Generic function to convert a given object into an iteror.
  • nextOr – Obtain the next element from an iteror.
  • r_to_py.iteror – Make an iteror act as a Python iterator (requires package reticulate)

Consuming / summarizing an iteror

Most of these functions are S3 generic.

  • as.character, as.numeric, as.logical, as.list – Collect all an iteror’s values into a vector.
  • as.vector – Collect values into a specified type of vector.
  • concat – Paste an iteror’s values end-to-end in one vector.
  • consume – Take all or some of an iteror’s elements and discard them.
  • count – Compute all elements, discard them and return their count.
  • dotproduct – Sum of products of corresponding elements of two iterors.
  • nth – Compute and discard the first \(n-1\) elements and return the \(n\)th.
  • prod.iteror – Product of all an iteror’s values (i.e. reduce using *.)
  • quantify – Consume an iteror and return how many elements were TRUE.
  • record – Write an iteror’s elements to a file.
  • reduce – Combine all of iteror’s values using a binary function, returning the final value.
  • sum.iteror – Sum all values of an iteror (i.e. reduce using +.)
  • take – Take some number of elements and return them in a vector.

Iterate over given data

By convention, functions in this package that construct an iterator in terms of basic data or other objects have names beginning with “i”.

Counting or other mathematically defined processes

  • icombinations – Enumerate all combinations of \(m\) elements of a given vector, with or without replacement.
  • icount – Produce an integer sequence starting with 1.
  • icountn – Enumerate multiple indices, in either row-major or col-major order.
  • idiv – Return a sequence of \(n\) integers that add up to a given total.
  • igrid – Produce a sequence over the Cartesian product of the given vectors.
  • ipermutations – A sequence containing all permutations of a given vector.
  • iseq – Generate arithmetic sequences with specific step size and origin.
  • iseq_along – Counting sequence parallel to a given vector.

Random number generation

Random number iterators can be made reproducible by specifying independent=TRUE and specifying a seed value, though this has a performance cost.

Iterators dealing with files or functions

  • iread.table – Reads row-wise from delimited text files.
  • ireadBin – Read binary data from file connections.
  • ireadLines – Read lines from text connections.
  • ireaddf – Read rows from several files in parallel (one per column).
  • ireplay – reads back values from a data file created with record
  • itabulate – Evaluate a function over an arithmetic sequence.
  • record – Write values from an iterator to a file.

Custom iterators

Higher order iterator functions

By convention, in this package, functions that transform iterators – creating a new iterator based on one or more underlying iterables – begin with “i_”, with an underscore.

Iterators as sequences – Looping, repeating, indexing

  • i_chunk – Collect \(n\) adjacent values from an iterable and return a list.
  • i_pad – After a given iterator ends, return a padding value indefinitely.
  • i_recycle – Record the values emitted by the underlying iterator and replay them.
  • i_rep – Repeat each element of an iterable a given number of times.
  • i_slice – Return elements based on a starting point ans stride.
  • i_window – Return adjacent elements from the underlying iteror in a sliding window.

Operating on data within iterators

  • i_accum – Apply a 2-argument function between an iteror’s elements, and return a sequence of partial totals.
  • i_apply – Apply a given function to each element.
  • i_enumerate – Return an index along with each element.
  • i_star, i_starmap, i_map – Apply a multiple-argument function to multiple parallel iterators.

Selection, filtering, limiting

  • i_break – Return elements only while the given (no-argument) function evaluates to TRUE.
  • i_dedup – Discard elements that are identical the immediately preceding element.
  • i_drop – Discard elements for which a criterion function returns TRUE.
  • i_dropwhile – Discard elements from an iterator until the criterion function evaluates FALSE.
  • i_keep – Keep only elements for which an applied criterion function returns TRUE.
  • i_keepwhile – Keep elements only until an applied criterion returns FALSE.
  • i_limit – Keep only the first \(n\) elements from the given iteror.
  • i_mask – Return elements for which a parallel iterator is TRUE.
  • i_rle – Compress runs of identical adjacent elements, returning one value and a run length.
  • i_rleinv – Inverse transform of i_rle.
  • i_timeout – Return elements only until the timeout is reached.
  • i_unique – Pass along only unique elements of an iterator, using a hash table.

Combining / splitting multiple iterators

  • i_chain – String all values from each iterable argument together.
  • i_concat – String an iterable of iterables together.
  • i_roundrobin – Return one element at a time from each of a series of iterors in rotation.
  • i_tee – Split an iterator into multiple iterators yielding the same sequence.
  • i_zip – Combine corresponding elements of parallel iterators into a list.
  • i_zip_longesti_zip but pad any iterators that end early.