Node:Calling R objects, Next:Methods of Robj type, Previous:Robj type, Up:Robj type
An object of type Robj
is always callable. When it represents
a R function, that function is invoked; if it is not a R
function, an exception is raised (see R exceptions):
>>> callable(r.seq) 1 >>> callable(r.pi) 1 >>> r.pi() Traceback (most recent call last): File "<stdin>", line 1, in ? rpy.RException: Error: attempt to apply non-function
The arguments passed to the Robj
object can be any Python
object, including another Robj
object. When an object of a standard
Python type is passed, it is converted to a R type according to
the rules described in Python to R. When a Robj
object is passed, the R function receives the corresponding R
object unchanged. Usually, you don't need to think on these things,
because the conversion works as one expects.
A Robj
also supports keyword arguments, if the corresponding
R function does it. The names of the keyword arguments are also
under the name conversion rules described in R objects look up.
For example:
>>> r.seq(1, 3) [1, 2, 3] >>> r.seq(1, 3, by=0.5) [1.0, 1.5, 2.0, 2.5, 3.0] >>> r['options'](show_coef_Pvalues=0) {'show.coef.Pvalues': 1} >>> r.print_(r.seq) function (...) UseMethod("seq") <Robj object at 0x8acb010>
Return values of the call to a Robj
object are also converted
from R to Python. When no conversion is possible, an
Robj
object is returned, which holds a reference to the R
object. This behavior is completely customizable (see R to Python).