2

Basically,

I managed to execute a python script within R. However, I have no idea how to return those values from the python script to R and store those values in R, especially when I have multiple functions in the python script.

What should I add to the python script to make this process possible ?

note: Suppose I pass in the arguments python test.py arg1 arg2 arg3 from R to python at the beginning.

This the test.py I have written below.

#!/usr/bin/python

import sys


jd = sys.argv
def testing(jd):
    print 'Number of arguments:', len(jd), 'arguments.'
    print 'Argument List:', str(jd)
    return jd

def testing2():
    return 123123


testing(jd)
testing2()
2
  • Can you add the R code you use to call this? Commented Jul 3, 2014 at 18:02
  • Is the R code relevant ? Commented Jul 3, 2014 at 18:05

2 Answers 2

1

Not very clear what you want. Capturing simple output is easy:

a = system('python -c "print \\"test\\""', intern = TRUE)
a
#[1] "test"
Sign up to request clarification or add additional context in comments.

Comments

0

I'd suggest checking out R/SPlus here: http://www.omegahat.org/RSPython/

It supports calling Python scripts and functions in modules etc. and returns values as an SEXP which is an R generic datatype.

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.