2

How to input arguments from R to Python with the package rPython?

Below is a naive attempt

In script.py:

print message

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

1 Answer 1

4

Per the package's docs (page 5-6) for the load method:

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.

Hence, do not have a running script in Python but only defined functions with return objects:

Python (script.py)

def print_message(msg):
   return msg

R (using load and call)

require(rPython)    
text = "Hello World"

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

#[1] "Hello World"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.