pyCall: Call a callable Python object from within R

Description Usage Arguments Details Value Examples

View source: R/PyCall.R

Description

Call a callable Python object from within R.

Usage

1
2
pyCall(callableObj, args = NULL, kwargs = NULL, autoTypecast = TRUE,
  simplify = TRUE)

Arguments

callableObj

a character string giving the name of the desired callable Python object.

args

an optional list of arguments passed to the callable.

kwargs

an optional list of named arguments passed to the callable.

autoTypecast

an optional logical value, default is TRUE, specifying if the return values should be automatically typecasted if possible.

simplify

an optional logical value, if TRUE, R converts Python lists into R vectors whenever possible, else it translates Python lists always to R lists.

Details

The args and kwargs are transformed to Python variables by the default conversion. More information about the type conversion can be found in the vignette.

Value

Returns the result of the function call, converted into an R object.

Examples

1
2
3
4
5
6
7
8
pyCall("sum", args=list(1:3))

## define a new function with the name fun
pyExec('
def fun(**kwargs):
    return([(key, value) for key, value in kwargs.items()])
')
pyCall("fun", kwargs=list(a=1, f=2, x=4))

PythonInR documentation built on July 1, 2020, 6:05 p.m.