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()
Not very clear what you want. Capturing simple output is easy:
a = system('python -c "print \\"test\\""', intern = TRUE)
a
#[1] "test"
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.