kachkaev / php-r-bundle
此包已被弃用且不再维护。未建议替代包。
Symfony2 包,用于与提供从 PHP 运行 R 脚本功能的 php-r 库集成
v2.1.0
2017-06-15 07:35 UTC
Requires
- php: >=5.3
- kachkaev/php-r: ^1.0
- symfony/framework-bundle: ~2.3|~3.0
This package is not auto-updated.
Last update: 2021-11-27 00:35:25 UTC
README
Symfony2/Symfony3 包,用于 php-r 库
安装
Composer
将以下依赖项添加到项目的 composer.json 文件中
"require": { // ... "kachkaev/php-r-bundle": "dev-master" // ... }
现在通过运行以下命令让 composer 下载该包
$ php composer.phar update kachkaev/php-r-bundle
Composer 将包安装到 vendor/kachkaev
目录。
将包添加到您的应用程序内核
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Kachkaev\PHPRBundle\KachkaevPHPRBundle(), // ... ); }
配置
以下是包的默认配置
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
在大多数情况下不需要自定义配置,因此只需将以下行添加到您的 app/config/config.yml
kachkaev_phpr: ~
使用方法
$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
包含以下字符串
> x = 10
> x * x
[1] 100
有关 R 内核和 R 进程的详细功能描述,请参阅 php-r 库 的文档。
还注册了一个 ROutputParser
实例作为服务
$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)
许可证
MIT。请参阅 LICENSE。