Giter Site home page Giter Site logo

rserve-php's Introduction

Rserve-php

php5 client for Rserve http://www.rforge.net/Rserve/ (a TCP/IP server for R statistical software)

NEW:

New version of this project with new features, namespace is available on 2.0 branch of this project. It will be released soon. For a new project prefer this new branch.

Maturity

The library provide several way to parse R structures ($parser parameter in evalString)

  • native php array : you get only the results in nested php array (without R attributes). It's a good way to handle simple R results. This feature is in beta and has unit tests

  • wrapped native php array : you get the results in a simple object (RNative) with results as php array and you can access to R object attributes.

  • Debug : full description of the Rserve protocol results

  • REXP: All R structures are wrapped in an REXP_* class This feature is in alpha: not very documented, tests in progress. Only low level R structures are handled (data.frame is a GenericVector, etc..)

Tests

You can run tests using phpunit

  • 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 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

Usage

The use of the library is simple

  1. create an instance of Rserve_Connection

$cnx = new Rserve_Connection('myserverhost');

  1. Send R commands and get the results as Php array

$result = $cnx->evalString('x ="Hello world !"; x');

// Get results as a REXP object tree $result = $cnx->evalString('x="Toto is my Hero"', Rserve_Connection::PARSER_REXP);

// Get as wrapped native array (object with array behaviour and attributes) $result = $cnx->evalString('x="Toto is my Hero"', Rserve_Connection::PARSER_NATIVE_WRAPPED);

This will produce a php array containing R results (using native array parser). Others parsers could be used by using $parser parameters (@see Rserve_Connection)

Using Login Authorization

Usage is the same as the vanilla usage, except for the constructor $cnx = new Rserve_Connection('myserverhost',serverport,array('username'=>username,'password'=>password))

Async Mode

Several functions allow to use connection in async mode

  • 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

Files Description

  • Connection.php : main class Rserve_Connection, you only need to manipulate an instance of this class (evalString method for now)
  • helpers.php : helpers function librairies
  • Parser.php : Parser class used to Parse Rserve binary packets to php structures (native array or REXP children)
  • RNative.php : an array wrapper used to catch attributes (experimental, usefull ?)
  • REXP/*.php : R expression classes

Contacts

Clément Turbelin, [email protected] http://www.sentiweb.fr Université Pierre et Marie Curie - Paris 6, France

rserve-php's People

Contributors

cturbelin avatar rathivivek avatar shadiakiki1986 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.