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

2024-09-28 23:13:49 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上

我设法在R内执行了一个python脚本。但是,我不知道如何将这些值从python脚本返回到R,并将这些值存储在R中,尤其是在python脚本中有多个函数时。在

为了使这个过程成为可能,我应该向python脚本中添加什么?在

注意:假设我在开始时将参数python test.py arg1 arg2 arg3从R传递给python。在

这是我写在下面的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()

Tags: 函数pytest脚本参数return过程def
2条回答

我建议您在这里查看R/SPlus:http://www.omegahat.org/RSPython/

它支持在模块等中调用Python脚本和函数,并以SEXP(一种R通用数据类型)的形式返回值。在

不太清楚你想要什么。捕获简单的输出很容易:

a = system('python -c "print \\"test\\""', intern = TRUE)
a
#[1] "test"

相关问题 更多 >