-
Notifications
You must be signed in to change notification settings - Fork 41
can not start #7
Comments
replace /usr/bin/R with /path/to/R to avoid confusion like in #7
Hi @AhmedAly90, It looks like PHP can't locate R. Default path "'/usr/bin/R" usually works for linux/unix, but is not likely to be the same on Windows. You should change this according to where R is installed in your system (php-r is not a replacement of R, it's just a bridge to it). Whatever path to R interpreter you define, the command should work in the console outside PHP. When you enter "/path/to/R" in the console, you should be able to start typing native R commands and instantly get the result (this is similar to what happens after you enter "mysql" in the console). Could you please let me know what path worked? I'll update it in the readme file. |
i give the path on my windows but it doesnot work error given |
I just did a couple of experiments on a virtual windows machine (which does not have R) and concluded that the issue actually might be related to a problem in library code. Could you please try opening php-r/src/Kachkaev/PHPR/Process/CommandLineRProcess.php and replace line 28?
If this solves the issue, I'll update the code. |
Hi @kachkaev, Very cool library. Thank you for sharing it. I used your library yesterday and got to a point where I tried your solution on Windows. It solves the problem of not being able to find R on a Windows filesystem. After that though, my command hangs on line 37 for the following: $errorOutput = fgets($this->pipes[2]); I don't know if you want to create a new issue for that issue or not. If I find a solution, I'll make a pull request. |
Hi @jackdp, Unfortunately I currently don’t have enough resources to investigate PHP-R problems on Windows, so if you could run your own little investigation, that would be really great! Looking forward for your thoughts or pull requests. |
On line 36 of php-r/src/Kachkaev/PHPR/Process/CommandLineRProcess.php, stream_set_blocking is returning false. From what I found on http://php.net/manual/en/function.stream-set-blocking.php and other sources, that function doesn't work on Windows. When I had $pipes[2] errors write to a error.log file, I was able to successfully use R . What are your thoughts on writing files to a error log vs reading them from console? Pending your opinion, I'll make the necessary changes and create a pull request. |
I tried writing errors to a log instead of reading them using the pipe. It isn't the correct solution in my opinion. I went ahead made a pull request for your update above, if you want to merge: #8. |
@drazik No, it addresses the first issue of not being to run the command on the Windows command line. The second issue still persists though where it hangs when it tries to read errors. |
@jackdp, thanks for your PR, I merged it. I agree that writing to a file instead of a pipe is a slightly odd solution, but I would not reject it right away just because it does not look ideal at first glance. Anyway I think it's pretty important to understand what's exactly going on with the pipe windows before making any changes. Please let me know if you find any clues. |
Fine, I will investigate too. |
@drazik, can you try my fork of php-r from https://github.com/jackdp/php-r and tell me if you have any problems? |
I can't try it right now but i'll let you know asap. |
Hello @jackdp , I'm sorry to have let 7 days pass before testing your fork. I have just installed it and tried the first example of the documentation : <?php
require_once 'vendor/autoload.php';
use Kachkaev\PHPR\RCore;
use Kachkaev\PHPR\Engine\CommandLineREngine;
$r = new RCore(new CommandLineREngine('C:\\Program Files\\R\\R-3.2.0\\bin\\R.exe'));
$result = $r->run(<<<EOF
x = 1
y = 2
x + y
x + z
x - y
EOF
);
echo $result; Here is the error I get :
Let me know if I have done something wrong ;) |
Try this something like this. Make sure you have a file to write errors to. <?php
require_once 'vendor/autoload.php';
use Kachkaev\PHPR\RCore;
use Kachkaev\PHPR\Engine\CommandLineREngine;
$args = array();
$args['pathToErrorFile'] = 'C:/path/to/errors.txt';
$r = new RCore(new CommandLineREngine('C:/Program Files/R/R-3.1.2/bin/R.exe', $args));
$result = $r->run(<<<EOF
x = 1
y = 2
x + y
x + z
x - y
EOF
);
echo $result; |
I tried it, I get an error un errors.txt :
I don't know what the english version of the error is, but it means "'C:/Program' is not an internal or external command, an executable program or a command file". I tried to replace $r = new RCore(new CommandLineREngine('C:/"Program Files"/R/R-3.1.2/bin/R.exe', $args)); It solved the problem (no more error in errors.txt), but still no result in the browser. The PHP server output this error :
Then I tried with a max execution time of 120 seconds, but the result (may I say "the error") is the same. I also checked that the path I give to |
@drazik Using your updated CommandLineREnigne constructor still works for me. The problem you are facing that CommandLineREnigne can't find R.exe. In your original posting, you had R-3.2.0 vs the R-3.1.3, which I'm using and you switched to for some reason. Can you update your most recent attempt to use R-3.2.0 like you did in your original posting? Something like this: <?php
require_once 'vendor/autoload.php';
use Kachkaev\PHPR\RCore;
use Kachkaev\PHPR\Engine\CommandLineREngine;
$args = array();
$args['pathToErrorFile'] = 'C:/your/path/to/errors.txt';
$r = new RCore(new CommandLineREngine('C:/"Program Files"/R/R-3.2.0/bin/R.exe', $args));
$result = $r->run(<<<EOF
x = 1
y = 2
x + y
x + z
x - y
EOF
);
echo $result; |
@jackdp I've always been using 3.2.0 but I forgot to change the version number during a copy/paste to my github comment ;) I'm doing exactly what you told me in your last comment and still reach max execution time. I don't think that the problem is that CommandLineREngine can't find R.exe. I fails on src\Kachkaev\PHPR\Process\CommandLine\AbstractCommandLineRProcess.php line 54 everytime. It does not seem that this line is related to finding R.exe. |
@drazik If it's related to not to finding R.exe, I'm not sure how to reproduce the problem. While I look for another way to reproduce the problem, can you try two things for me? 1.) Check your errors.txt after you get the error related to reaching max execution time. It may hold some clues. If it says anything, please report it. 2.) Can you put this for the constructor for Kachkaev\PHPR\Engine\CommandLineREngine? I don't want to be a broken record but this is just to triple check for R.exe. public function __construct($rCommand, array $args = null)
{
if (!file_exists($rCommand)) {
throw new \Exception($rCommand . " can't be found. Make sure you have the correct location for R.exe.");
}
$this->rCommand = $rCommand;
$this->args = $args;
} |
Hi, i run the code in laravel 5.2 but only works sometimes, What could be the error? |
i use php-r but it give me an error
Fatal error: Uncaught exception 'Kachkaev\PHPR\Exception\RProcessException' with message '''' is not recognized as an internal or external command, ' in C:\xampp\htdocs\R\src\Kachkaev\PHPR\Process\CommandLineRProcess.php:31 Stack trace: #0 C:\xampp\htdocs\R\src\Kachkaev\PHPR\Process\AbstractRProcess.php(37): Kachkaev\PHPR\Process\CommandLineRProcess->doStart() #1 C:\xampp\htdocs\R\poorman.php(15): Kachkaev\PHPR\Process\AbstractRProcess->start() #2 {main} thrown in C:\xampp\htdocs\R\src\Kachkaev\PHPR\Process\CommandLineRProcess.php on line 31
and my code is to simple
";use Kachkaev\PHPR\RCore;
use Kachkaev\PHPR\Engine\CommandLineREngine;
echo "
echo "Number values to generate: ";
echo "Number values to generate: ";
echo "";
echo "";
require('src\Kachkaev\PHPR\RCore.php');
require('src\Kachkaev\PHPR\Engine\CommandLineREngine.php');
require_once('src\Kachkaev\PHPR\Engine\AbstractREngine.php');
$r = new RCore(new CommandLineREngine('/usr/bin/R'));
$rProcess = $r->createInteractiveProcess();
+$rProcess->start();
$rProcess->write('x=10');
$rProcess->write('N=10');
$rProcess->write('png(filename="temp.png", width=500, height=500)');
$rProcess->write(' hist(x, col="lightblue")');
$rProcess->write('plot(x,N)');
$rProcess->write('dev.off()');
echo("
");
The text was updated successfully, but these errors were encountered: