【发布时间】:2015-03-05 00:04:10
【问题描述】:
我用 Python 编写脚本。我想用 R 绘制一些图表。
运行以下代码时出现错误
import sys
import argparse
import os
import subprocess
parser = argparse.ArgumentParser(description=messg, prog='parser.py',
usage='%(prog)s -m [file.txt]')
parser.add_argument('-m', required=True, help='file.txt', type=argparse.FileType('r'))
parser.add_argument('-o', required=True, help='Save output to file', type=argparse.FileType('w'))
args = parser.parse_args()
for ln in args.m:
prefix, proteins = ln.rstrip().split(':')
proteins = proteins.split()
args.o.write('%s\t' % prefix,)
args.o.write('\n')
subprocess.call("Rscript script.r"+args.o, shell=True)
我收到以下错误
Traceback (most recent call last):
File "parser.py", line 18, in <module>
subprocess.call("Rscript script.r"+args.o, shell=True)
TypeError: cannot concatenate 'str' and 'file' objects
但是当我从命令行运行它时它可以工作
Rscript script.r file.txt
谁能指出我哪里出错了?
谢谢。
【问题讨论】:
-
你知道RPy2吗?
-
感谢您的建议。这很棒。但我卡在 r 中的阅读表上。我想将上述脚本的输出文件用于 R。我在下面添加了代码。非常感谢。
标签: python r python-3.x