itertools2: Functions creating iterators for efficient looping

A port of Python's excellent itertools module to R for efficient looping.


The R package itertools2 is a port of Python's excellent itertools module to R for efficient looping and is a replacement for the existing itertools R package.

Installation

You can install the stable version on CRAN:

install.packages('itertools2', dependencies=TRUE)

If you prefer to download the latest version, instead run the following after installing devtools:

devtools::install_github('ramhiser/itertools2')

License

The itertools2 R package is licensed under the MIT License. However, this package depends on the iterators R package, which is licensed under the Apache License, Version 2.0. Both packages are freely available for commercial and non-commerical usage. Please consult the licensing terms for more details.

News

itertools 0.1.1

Iterators

  • ichunk(): Iterator that returns elements in fixed-length chunks. If the length of the iterator is not divisible by chunk_size, the remainder of the last block is filled with the value specified in fill.

  • ipad(): Iterator that returns an object followed indefinitely by a fill value.

  • ipairwise(): Iterator that returns elements of an object in pairs.

  • iroundrobin(): Iterator that traverses each given iterable in a roundrobin order.

  • itabulate(): Iterator that maps a function to a sequence of numeric values.

  • iunique(): Iterator that extracts the unique elements from an iterable object. This function is an iterator analogue to base::unique.

  • iunique_justseen(): Iterator that extracts the just-seen unique elements from an iterable object. Only the element just seen is remembered for determining uniqueness.

Utilities

  • consume(): Consumes the first n elements of an iterator.

  • dotproduct(): Computes the dot product of two iterable objects.

  • iter_deepcopy(): Performs a deep copy of an iterator.

  • nth(): Returns the nth item of an iterator, skipping the iterator ahead during the process. If the iterator is entirely consumed, a default value is returned.

  • quantify(): Count the number of times an iterable object is TRUE.

  • take(): Return the first n elements of an iterable object as a list.

Miscellaneous

  • Fixed a rare issue where ichain() was throwing an uncaught exception.

  • Resolved an issue with itee() when applied to an iterator. Shallow copies were being made, such that each shared a common state. The introduction of iter_deepcopy() resolved this issue, closing Issue #36.

itertools 0.1

Iterators

  • ichain(): Chains multiple arguments together into a single iterator. Generates an iterator that returns elements from the first argument until it is exhausted. Then generates an iterator from the next argument and returns elements from it. This process continues until all arguments are exhausted. Chaining is useful for treating consecutive sequences as a single sequence.

  • icompress(): Iterator that filters elements where corresponding selector is false. Returns only those elements for which the corresponding 'selector' is TRUE.

  • icount(): Neverending numeric sequence with initial value and step size.

  • icycle(): Iterator that cycles indefinitely through an iterable object

  • idropwhile(): Iterator that drops elements until the predicate function returns FALSE.

  • ienum(): Alias to ienumerate() to save a few keystrokes.

  • ienumerate(): Iterator that returns the elements of an object along with their indices. This function is intended to follow the convention used in Python's enumerate function.

  • ifilter(): Iterator that filters elements not satisfying a predicate function. Returns only those elements for which the predicate function is TRUE.

  • ifilterfalse(): Iterator that filters elements not satisfying a predicate function. Returns only those elements for which the predicate function is FALSE.

  • imap(): Iterator that applies a given function to several iterables concurrently.

  • iproduct(): Iterator that returns the Cartesian product of the arguments. Similar to base::expand.grid().

  • irep(): Iterator that replicates elements of an iterable object. Follows the base::rep() function.

  • irep_len(): Iterator that replicates elements of an iterable object with a desired length. Follows the base::rep_len() function.

  • irepeat(): Iterator that returns an object indefinitely unless a specified number of times is given.

  • iseq(): Iterator for sequence generation. Follows the base seq() function.

  • iseq_along(): Iterators for sequence generation of length equal to an object. Follows the base::seq_along() function.

  • iseq_len(): Iterators for sequence generation of a fixed length. Follows the base::seq_len() function.

  • islice(): Iterator that returns selected elements from an iterable.

  • istar(): Alias to istarmap() to save a few keystrokes.

  • istarmap(): Iterator that applies a given function to the elements of an iterable.

  • itakewhile(): Iterator that returns elements while a predicate function returns TRUE.

  • itee(): Returns a list of n independent iterators from a single iterable object.

  • izip(): Iterator that iterates through several iterables concurrently.

  • izip_longest(): Iterator that iterates through several iterables concurrently. Missing values are replaced with the value given in fill if the iterables are of uneven length.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("itertools2")

0.1.1 by John A. Ramey, 5 years ago


https://github.com/ramhiser/itertools2, http://ramhiser.com


Browse source code at https://github.com/cran/itertools2


Authors: John A. Ramey <[email protected]> , Kayla Schaefer <[email protected]>


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports iterators

Suggests testthat


See at CRAN