r_to_py.iteror {iterors} | R Documentation |
Wrap an iteror to appear as a Python iterator or vice versa.
Description
This requires the reticulate
package to be installed.
Usage
## S3 method for class 'iteror'
r_to_py(x, convert = FALSE, ...)
## S3 method for class 'python.builtin.object'
iteror(obj, ...)
Arguments
x |
An iterable object. |
convert |
does nothing. |
... |
Passed along to |
obj |
A Python object (as viewed by package |
Value
r_to_py(it)
returns a Python iterator.
Method iteror.python.builtin.object
returns an iteror.
Examples
pit <- reticulate::r_to_py(iseq(2, 11, 5))
reticulate::iter_next(pit, NULL)
reticulate::iter_next(pit, NULL)
reticulate::iter_next(pit, NULL)
# create an R iterator and ask Python to sum it
triangulars <- icount() |> i_accum() |> i_limit(10)
builtins <- reticulate::import_builtins()
builtins$sum(triangulars) # r_to_py is called automatically
# create a generator in Python and sum it in R
pit <- reticulate::py_eval("(n for n in range(1, 25) if n % 3 == 0)")
sum(iteror(pit))
[Package iterors version 1.0 Index]