1
我想在PHP代码中使用Apache Web服务器执行R脚本(名为script.R)。 这里是我的R代码里面:我安装软件包,然后导入数据,那么我可以继续对数据的分类树:使用Apache服务器从PHP执行R脚本
library(lubridate)
library(plyr)
library(rpart)
library(sqldf)
library(survival)
library(randomForest)
library(rpart.plot)
data=read.table(file = "t.txt",header = T,sep = ";",stringsAsFactors = T)
input=read.table(file = "file.txt",header = T,sep = ";",stringsAsFactors = T)
tree=rpart(sat~.,data,method="class")
png("tree.png", width=1000, height=800, antialias="cleartype")
plot(tree, uniform=TRUE,
main="Classification Tree")
text(tree, use.n=TRUE, all=TRUE, cex=0.8)
dev.off()
我的PHP脚本必须执行该R脚本。它们被放置在 “C:\ Apache24 \ htdocs目录” 与 “file.txt的” 和 “t.txt”
所以我的PHP文件包含在:
<?php
exec("Rscript script.R", $results);
print_r($results);
?>
,但我得到 “阵列()”
有什么想法?
尝试使用'passthru()'获取所有输出。 'exec()'只返回最后一行:http://php.net/manual/en/function.passthru.php –
同样的结果!它返回“1”。我想这意味着执行工作,但我没有情节(“tree.png”)。 也许R没有安装在服务器上。我怎么能检查它是否? –