【发布时间】:2021-07-14 08:30:59
【问题描述】:
我有下面发布的 R 代码,我想从 python 代码传递参数n并显示结果。也就是说,如果我通过了 4,那么 16 必须在屏幕上打印出来。
请让我知道如何从 python 将 argumnets 传递给 R-script
R 代码:
Square <- function(n) {
return(n^2)
}
Python 代码:
command ='Rscript'
path2Func1Script ='/var/www/aw/Rcodes/func-1.R'
args = [3]
cmd = [command, path2Func1Script]
output = None
try:
x = subprocess.call(cmd + args, shell=True)
print("x: ", x)
except subprocess.CalledProcessError as e:
output = e.output
print("output: ", output)
【问题讨论】:
-
您可以在问题中添加您正在使用的python版本吗?
-
嗨@Letsamrit,我已经进行了进一步的测试和研究,并确保我的答案能回答所有问题,希望对您有所帮助