pyCall: Call a callable Python object from within R

View source: R/PyCall.R

pyCallR Documentation

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.

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


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))

Sage-Bionetworks/PythonEmbedInR documentation built on April 17, 2023, 4:23 p.m.