2017-03-16 60 views
2

如何使用包rPython从R输入参数到Python?如何使用rPython从R输入参数到Python?

下面是一个天真的尝试

在script.py:为

require(rPython)  
text = "Hello World" 
python.load("script.py", message=text) 

Error in python.load("script.py", message = text) : 
    unused argument (message = text) 

回答

3

每包的docs(第5-6页):

print message 

在script.R load方法:

该函数运行包含在文件中的Python代码。通常,这个 文件将包含要通过此包中的python.call或其他 函数调用的函数。

因此,不必在Python正在运行的脚本,但只定义的函数,返回的对象:

的Python(script.py)

def print_message(msg): 
    return msg 

ř(使用负载和呼叫)

require(rPython)  
text = "Hello World" 

python.load("script.py") 
python.call("print_message", text) 

#[1] "Hello World" 
相关问题