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

How to input arguments from R to Python with rPython?

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

以下是幼稚的尝试

在script.py中:

print message

在script.R中:

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

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

根据 load 方法的包 docs(第 5-6 页):

This function runs Python code contained in a file. Typically, this file would contain functions to be called via python.call or other functions in this package.

因此,Python 中没有 运行 脚本,而只定义了具有 return 个对象的函数:

Python (script.py)

def print_message(msg):
   return msg

R (使用加载和调用)

require(rPython)    
text = "Hello World"

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

#[1] "Hello World"