【发布时间】:2019-09-14 10:23:13
【问题描述】:
我的问题似乎很基本,但即使在 rpy2 文档中我也找不到答案。 我有 *.R 脚本,它接受一个参数作为“file.txt”(我需要传递参数而不是从命令行)。我想在 python 脚本中调用 R 脚本。我的问题是: 如何将参数传递和恢复到 R 脚本? 我的解决方案是: 假设 R 脚本由这一行开始:
df <- read.table(args[1], header=FALSE)
"
here args[1] should be the file which is not passed from the command line
"
....
现在我在我的 python 脚本中编写一个函数:
from rpy2 import robjects as ro
def run_R(file):
r = ro.r
r.source("myR_script.R")
# how to pass the file argument to
# the R script and how to
# recuperate this argument in the R code?
【问题讨论】: