kachkaev/php-r-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Symfony2 bundle for integration with php-r library that provides ability to run R scripts from PHP

Installs: 1 994

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 2

Open Issues: 0

Type:symfony-bundle

v2.1.0 2017-06-15 07:35 UTC

This package is not auto-updated.

Last update: 2021-11-27 00:35:25 UTC


README

Symfony2/Symfony3 bundle for the php-r library

Installation

Composer

Add the following dependency to your project’s composer.json file:

    "require": {
        // ...
        "kachkaev/php-r-bundle": "dev-master"
        // ...
    }

Now tell composer to download the bundle by running the command:

$ php composer.phar update kachkaev/php-r-bundle

Composer will install the bundle to vendor/kachkaev directory.

Adding bundle to your application kernel

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Kachkaev\PHPRBundle\KachkaevPHPRBundle(),
        // ...
    );
}

Configuration

Here is the default configuration for the bundle:

kachkaev_phpr:
    default_engine: command_line     # default R engine (command_line is the only one currently implemented)  
    engines:
        command_line:
            path_to_r: /usr/bin/R    # path to R interpreter

In most cases custom configuration is not needed, so simply add the following line to your app/config/config.yml:

kachkaev_phpr: ~

Usage

$r = $container->get('kachkaev_phpr.core');
$rResult = $r->run('x = 10
x * x');

// --- or ---

$r = $container->get('kachkaev_phpr.core');
$rProcess = $r->createInteractiveProcess();
$rProcess->write('x = 10');
$rProcess->write('x * x');
$rResult = $rProcess->getAllResult();

$rResult contains the following string:

> x = 10
> x * x
[1] 100

For detailed feature description of R core and R process see documentation to php-r library.

An instance of ROutputParser is also registered as a service:

$rOutputParser = $container->get('kachkaev_phpr.output_parser');

$rProcess->write('21 + 21');
var_dump($rProcess->getLastWriteOutput());
// string(6) "[1] 42"
var_dump($rOutputParser->singleNumber($rProcess->getLastWriteOutput()));
// int(42)

License

MIT. See LICENSE.