Next: , Previous: R to Python, Up: Conversion system


4.2 Python to R

The conversion from Python objects to R objects is automatic. It is done when passing parameters in Robj objects. Normal Python objects are converted to R objects according to the table given in Basic conversion. A Robj object is converted to the R reference which it represents.

In addition, every Python object which defines a as_r() method, is converted to R as the result of calling that method.

If none of this apply, an exception is raised.

For example:

     >>> class Foo:
     ...     def as_r(self):
     ...             return 5
     ...
     >>> a = Foo()
     >>> dummy = r.print_(a)
     [1] 5
     >>>
     >>> r.print_(range)
     Traceback (most recent call last):
       File "<stdin>", line 1, in ?
     rpy.RException: cannot convert from type 'builtin_function_or_method'