Download the PHP package kachkaev/php-r without Composer
On this page you can find all versions of the php package kachkaev/php-r. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kachkaev/php-r
More information about kachkaev/php-r
Files in kachkaev/php-r
Package php-r
Short Description Provides ability to run R scripts from PHP
License MIT
Homepage https://github.com/kachkaev/php-r
Informations about the package php-r
php-r
PHPR (or php-r) is a library that provides ability to run R scripts from PHP. Composer package: kachkaev/php-r.
Optionally, the library is available as a bundle for Symfony2 users.
The idea is based on invoking a command-line version of R and exchanging messages with this external process. Integration with server-based implementation of R can be easily implemented on demand as the library architecture supports that.
It is possible to both run all R code in one batch and interactively exchange commands with R interpreter.
Usage
Option 1: all R code in one batch
PHP output:
Method is always called in a clean scope of R variables, i.e. the following usage will result an R error:
PHP output:
Option 2: interactive exchange of data
To exchange commands with a single R process interactively, another approach should be used:
PHP output:
The process is synchronous, i.e. if R code sent to implies some complex computations, PHP will wait until they are finished.
Multiple commands can be passed to R inside one ; they can be multi-line too:
It is strictly necessary to keep commands complete. The following example will result a critical error, and R process will be terminated.
Separate access to input / output / errors for each R command
To avoid manual splitting of a mix of R input, output and errors, the result of script execution can be accessed separately:
Passing to splits strings into arrays, where each element corresponds to a single command:
Sensitivity to R errors
If it is necessary to make sure that a sequence of R commands is running with no errors, and calling after each is unreasonable, the process can be made sensible to errors. will be thrown on :
This is the same as:
R-related errors and the exception thrown are not critical; the same instance of R process can be still used after they occur. If last input contains multiple commands, and several of them cause errors, will have the complete list. In any case all commands passed to will be attempted by R interpreter.
Parsing R output
To ease parsing of R output, can be used:
See PHPdoc annotations to classes for more details.
License
MIT. See LICENSE.