php-r icon indicating copy to clipboard operation
php-r copied to clipboard

Import library

Open omarciovsena opened this issue 11 years ago • 3 comments

I'm in need import libraries in my R code, but is giving the following error.

$rOutputParser = new ROutputParser();
$rProcess = $r->createInteractiveProcess();
$rProcess->start();
$resultado = "a";
$rProcess->write(<<<EOF
   require("sm",lib.loc="/Library/Frameworks/R.framework/Resources/library/")
EOF
        );
var_dump($rProcess->getErrors());

Result:

array (1) {
   [0] =>
   object (Kachkaev \ PHPR \ RError) # 77 (4) {
     ["inputLineNumber": "Kachkaev \ PHPR \ RError": private] =>
     int (0)
     ["commandNumber": "Kachkaev \ PHPR \ RError": private] =>
     int (0)
     ["command", "Kachkaev \ PHPR \ RError": private] =>
     string (90) "require (" sm "lib.loc =" / Library / Frameworks / R.framework / Resources / library / ")"
     ["errorMessage": "Kachkaev \ PHPR \ RError": private] =>
     string (97) "Loading required package: sm
Package 'sm', version 2.2-5.4: type help (sm) is summary information "
   }
}

omarciovsena avatar Jan 18 '15 17:01 omarciovsena

Hi @marciovsena,

By default R outputs some messages into error output not to mix them with results of calculations etc. Here is what you can normally see in RStudio:

screen shot 2015-01-20 at 12 06 10

Red text is what you’d get in $rProcess->getErrors() if you used PHP-R. I’d recommend you to simply ignore these errors – they should not negatively influence any of your further commands. Also have a look at method getLastWriteErrors() – it might be reasonable to use it instead of getErrors() if you are interested only in recently occurred errors.

I’ll leave this issue open for now; maybe someone can recommend a good solution for differentiating between info messages and real errors in error output (I personally can’t see a universal one).

kachkaev avatar Jan 20 '15 12:01 kachkaev

Hi @marciovsena , did you use this pacage in windows now?How to do it?

kbvstmd avatar Jan 22 '15 07:01 kbvstmd

Hi @kbvstmd, I am using MAC OS

omarciovsena avatar Jan 22 '15 18:01 omarciovsena