我搜索了这个问题并找到了一些答案,但是它们都似乎不起作用。 这是我在Python中使用的脚本来运行我的R脚本。
import subprocess
retcode = subprocess.call("/usr/bin/Rscript --vanilla -e 'source(\"/pathto/MyrScript.r\")'", shell=True)
我遇到了这个错误:
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
no lines available in input
Calls: source ... withVisible -> eval -> eval -> read.csv -> read.table
Execution halted
以下是我的 R 脚本的内容(非常简单!)
data = read.csv('features.csv')
data1 = read.csv("BagofWords.csv")
merged = merge(data,data1)
write.table(merged, "merged.csv",quote=FALSE,sep=",",row.names=FALSE)
for (i in 1:length(merged$fileName))
{
fileConn<-file(paste("output/",toString(merged$fileName[i]),".txt",sep=""))
writeLines((toString(merged$BagofWord[i])),fileConn)
close(fileConn)
}
当我在r命令行中使用source('MyrScript.r')
时,r脚本正常工作。此外,当我尝试在命令行中使用传递给subprocess.call
函数的确切命令(即/usr/bin/Rscript --vanilla -e 'source("/pathto/MyrScript.r")'
)时,它也能正常工作,我真的不知道问题出在哪里。
strace
命令查看exec
调用之间的差异。 - Kevin Smyth