r_to_py.iteror | R Documentation |
This requires the reticulate
package to be installed.
## S3 method for class 'iteror'
r_to_py(x, convert = FALSE, ...)
## S3 method for class 'python.builtin.object'
iteror(obj, ...)
x |
An iterable object. |
convert |
does nothing. |
... |
Passed along to |
obj |
A Python object (as viewed by package |
r_to_py(it)
returns a Python iterator.
Method iteror.python.builtin.object
returns an iteror.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.