Rserve-php
php5 client for Rserve http://www.rforge.net/Rserve/ (a TCP/IP server for R statistical software), (*1)
Changes from 1.0 version
- All classes are declared under Sentiweb\Rserve namespace allowing PSR-4 autoloading
- Parsers are now individualized into classes
- A Parser instance can be directly used as second argument of evalString() to replace default parser (see example)
Tests
You can run tests using phpunit, (*2)
- Create a file config.php in the "tests" directory (copy config.php.sample)
- define the constant RSERVE_HOST with the address of your Rserve server (custom port not supported yet)
- run tests
. phpunit --bootstrap=src/autoload.php tests/ParserNativeTest.php
. phpunit tests\SessionTest.php
. phpunit tests\REXPTest.php
- define the constants RSERVE_PORT, RSERVE_USER, RSERVE_PASS to config.php (along with RSERVE_HOST)
- run test
. phpunit tests\LoginTest.php
Installation
Using without composer :
include src/autoload.php in your project, (*3)
Using with composer:
composer require cturbelin/rserve-php, (*4)
Some usage examples are provided in example/ directory, (*5)
Using Login Authorization
Usage is the same as the vanilla usage, except for the constructor
$cnx = new Connection('myserverhost', serverport, array('username'=>username,'password'=>password)), (*6)
Parsers
Results provided by R could be handled using several parsers, (*7)
-
NativeArray
Translates R structure into php simple arrays. It is useful to get simple values from R, (*8)
-
Wrapped array
Using NativeArray with parameter ["wrapper"=>true] in contructor returns object
with attributes of R objects.
The result object can be used as an array and provides methods to access R object attributes, (*9)
-
Debug
Translates R response to structure useful for debugging, (*10)
-
REXP
Translates R response into REXP classes, (*11)
Async Mode
Several functions allow to use connection in async mode, (*12)
- getSocket() to get the socket an set some options
- setAsync() allow to set the async mode
- getResults($parser) : get and parse the results after a call to evalString() in async mode
Clément Turbelin, clement.turbelin@gmail.com
http://www.sentiweb.fr
Université Pierre et Marie Curie - Paris 6, France, (*13)