py.call: Call a Python callable

Description Usage Arguments Value Author(s) Examples

Description

py.call calls a Python callable - usually a function, built-in, method or a class object.

Usage

1
py.call(callable, ..., .ref = FALSE)

Arguments

callable

Reference to a Python object that is callable

...

arguments to pass to the object

.ref

logical, if TRUE the result is a Python reference, otherwise conversion to a native R type is attempted.

Value

Result of the call.

Author(s)

Simon Urbanek

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
py.init()

## create a simple class
py.eval("class foo:
   def __init__(self, value=0):
     self.x = value
   
   def f(self):
     self.x = self.x + 1
     return self.x")

## get the class object
foo = py.get("foo")
foo

## create an instance by calling it
i = py.call(foo)
i

i$f()
i$f()
i$x
i$x = 20
i$f()

## another instance with pre-set value
j = py.call(foo, 40)
j$x

s-u/rpython documentation built on May 28, 2019, 10:48 a.m.