png=$png ; $this->path_r=$path ;$this->input=$input ; $this->output=$output ; $this->hinput=fopen($this->input,"w") ; if ($this->png) { fputs($this->hinput,"dev.off.wrap <- function(){\r\ndev.off()\r\ninvisible()\r\n}\r\n"); fputs($this->hinput,"png(file = \"". $this->output ."\", bg=\"". $bgcolor ."\")\r\n"); } } function cmd($linia) { fputs($this->hinput,$linia . "\r\n"); } function run() { import PHPRuntime ; $PR=new PHPRuntime(); if ($this->png) $this->cmd('dev.off.wrap()'); fclose($this->hinput); //$cmd = "echo 'argv <- \"". $this->input ."\"; source(argv)' | " . $this->path_r ." --vanilla --slave"; if ($this->png) { $cmd="\"". $this->path_r ."\" --vanilla --slave -f ". $this->input ; } else { $cmd="\"". $this->path_r ."\" --vanilla --slave -f ". $this->input ." > " . $this->output ; } $err=$PR->system($cmd); if (!$this->png) { $this->houtput=fopen($this->output,"r");$this->ret=fread($this->houtput,filesize($this->output)); fclose($this->houtput); } return $err; } function getOutput() { if ($this->png) return $this->output ; return $this->ret ; } function c($arr) { $out="c(" ;$sep=""; foreach($arr as $el) { $out.=$sep .$el ;$sep=","; } $out.=")" ; return $out ; } } ?>