Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

iterate

Traverse a Python iterator or generator


Description

Traverse a Python iterator or generator

Usage

iterate(it, f = base::identity, simplify = TRUE)

iter_next(it, completed = NULL)

as_iterator(x)

Arguments

it

Python iterator or generator

f

Function to apply to each item. By default applies the identity function which just reflects back the value of the item.

simplify

Should the result be simplified to a vector if possible?

completed

Sentinel value to return from iter_next() if the iteration completes (defaults to NULL but can be any R value you specify).

x

Python iterator or iterable

Details

Simplification is only attempted all elements are length 1 vectors of type "character", "complex", "double", "integer", or "logical".

Value

For iterate(), A list or vector containing the results of calling f on each item in x (invisibly); For iter_next(), the next value in the iteration (or the sentinel completed value if the iteration is complete).


reticulate

Interface to 'Python'

v1.20
Apache License 2.0
Authors
Kevin Ushey [aut, cre], JJ Allaire [aut], RStudio [cph, fnd], Yuan Tang [aut, cph] (<https://orcid.org/0000-0001-5243-233X>), Dirk Eddelbuettel [ctb, cph], Bryan Lewis [ctb, cph], Sigrid Keydana [ctb], Ryan Hafen [ctb, cph], Marcus Geelnard [ctb, cph] (TinyThread library, http://tinythreadpp.bitsnbites.eu/)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.