简体   繁体   English

将值从python脚本返回到R并将这些值存储在`R`中

[英]Return values from python script to R and storing those values in `R`

Basically, 基本上,

I managed to execute a python script within R . 我设法在R执行python脚本。 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. 但是,我不知道如何将这些值从python脚本返回到R并将这些值存储在R ,尤其是当我在python脚本中具有多个功能时。

What should I add to the python script to make this process possible ? 我应该在python脚本中添加些什么才能使此过程成为可能?

note: Suppose I pass in the arguments python test.py arg1 arg2 arg3 from R to python at the beginning. 注意:假设我在开始时将参数python test.py arg1 arg2 arg3从R传递给python。

This the test.py I have written below. 这是我在下面编写的test.py

#!/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/ 我建议您在此处检查R​​ / SPlus: 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. 它支持在模块等中调用Python脚本和函数,并以SEXP的形式返回值,该SEXP是R的通用数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM