I want to execute a R script (named script.R) within PHP code with an Apache Web Server. Here is my R code : I install packages then import data then I can proceed a classification tree on the data:
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()
My php script must execute this R script. They are placed in "C:\Apache24\htdocs" with "file.txt" and "t.txt"
So my php file consists in :
<?php
exec("Rscript script.R", $results);
print_r($results);
?>
But I get "Array()"
Any idea?
passthru()to get all of the output.exec()only returns the last line: php.net/manual/en/function.passthru.php