使用R通过PHP [英] Using R through PHP
问题描述
我是R的新手,是Linux(Ubuntu)命令行的新手。我试图在PHP中写一个页面,其中包含一个命令,我想在R中执行,然后将结果返回,以便能够与他们合作。我尝试了下面的代码的变体,但我只得到R欢迎消息作为我的输出:
<?php
$ rQuery =\echo 3 + 1; \| / usr / bin / R --no-save;
exec($ rQuery,$ output);
print_r($ output);
?>
当我在命令行中手动键入$ rQuery时,结果是我想要的:[1] 4.
我知道我必须缺少一些东西,但我没有能够通过我自己的搜索找出来。
几点:
-
-slave 作为选项,它意味着
- no-save
并关闭问候语; 你真正想要的是Jeff Horner优秀的 R-inside-Apache >,请参阅这里了解详情。它可以使用模板框架,如 brew 。最重要的是,Jeff现在为您提供了一个.deb包:use -
如果您坚持使用php管道,请考虑 littler 脚本前端Jeff和我写道。它会比R更快启动。
deb http ://ppa.launchpad.net/jeffreyhorner/rapache/ubuntu lucid main
位于 /etc/apt/sources.list
中。
I'm relatively new to R and very new to the Linux (Ubuntu) command line. I'm trying to write a page in PHP that contains a command I would like to execute in R and then pass the results back to be able to work with them. I've tried variations of the code below, but I only get the R welcome message as my output:
<?php
$rQuery = "\"echo 3 + 1;\" | /usr/bin/R --no-save";
exec($rQuery, $output);
print_r($output);
?>
When I manually type $rQuery in the command line the result is what I would expect: [1] 4.
I know I must be missing something towards the end there, but I haven't been able to figure it out through my own searching.
Couple of points:
You want
--slave
as the option, it implies--no-save
and turns the greeting off; see the manual for more.What you really want is Jeff Horner's excellent R-inside-Apache, see here for more. It can use templating frameworks like brew as well. Best of all, Jeff now provides a .deb package for you: use
deb http://ppa.launchpad.net/jeffreyhorner/rapache/ubuntu lucid main
in/etc/apt/sources.list
.If you insist on piping from php, consider the littler scripting frontend Jeff and I wrote. It will start faster than R.
这篇关于使用R通过PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!