Skip to content
Advertisement

Is there any way to call base python function in r using reticulate?

I got a “generator object” from a python function. However, I tried many ways but failed to read the “generator object” in r using reticulate. I know python base function list() can convert “generator object” to “json“, which I can then read in r. I wonder how to use base python function in r? (I would not prefer to use py_run_file)

For example:

JavaScript

Advertisement

Answer

You could use iterate or iter_next.

As an example, consider a python generator firstn.py:

JavaScript

You can traverse the generator either with iterate :

JavaScript

or with iter_next:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement