Learn R Programming

PythonInR (version 0.1-12)

pyCall: Call a callable Python object from within R

Description

Call a callable Python object from within R.

Usage

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.

Value

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

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.

Examples

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataLab