使用PHP exec()函数时R包无法正常工作 [英] R package not working properly when using PHP exec() function

查看:122
本文介绍了使用PHP exec()函数时R包无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:已解决 我发现了问题.

使用.libPaths()函数,我可以确定在通过PHP运行Rscript时,HH软件包安装到的默认目录不是包含在库路径中,即使它是R在命令提示符下执行相同代码时出现.

Using the .libPaths() function, I was able to determine that the default directory that the HH package installed into was not included in the library paths when running Rscript through PHP, even though it was appearing when R was executing the same code through the command prompt.

我已通过单独调用.libPaths('new/file/path');解决了该问题.在我动态创建的语法中当我这样做时,请测试< -require('HH');测试;返回TRUE;

I've resolved the issue by include a separate call to .libPaths('new/file/path'); in my dynamically created syntax. When I do this, test <-require('HH'); test; returns TRUE;

感谢所有提供帮助的人.

Thanks to all who helped.

我正在创建一个PHP脚本,该脚本将在R中运行一些分析.此分析需要hov.bf()函数,该函数是

I'm in the process of creating a PHP script that will run some analyses in R. This analysis requires the hov.bf() function, which is a part of the HH package, but all R output (and presumably processes associated with R) stops from the line where the hov.bf() function is called. The same symptom occurs if I try loading the HH library via library('HH');. What's confusing me, the exact same R syntax code executes and outputs ALL print statements(base and HH functions) without error when run via the (Ubuntu) command prompt.

代码概述:

PHP创建R语法并将其写入文件Rsyntax.txt.以下某些行位于R语法文件中:

dir = '/var/www/someDirectory/';
setwd(dir);
sink('record.lis', append=FALSE, split=TRUE);

print('hello-1');
test <- hov.bf(Values,Grouping);
print('hello-2');

q();

语法文件生成后,PHP然后运行:

After syntax file is generated, PHP then runs:

exec("/usr/bin/Rscript /var/www/someDirectory/Rsyntax.txt --no-save", $output);

通过PHP运行时,输出文件将包含对hov.bf()的调用 above 创建的所有输出,但是在此调用之后似乎没有任何运行.也就是说,输出文件中存在"hello-1",但hov.bf()调用下方的"hello-2"和所有其他输出未写入该文件.但是,当我将确切的命令从PHP的exec()复制并粘贴到Ubuntu的命令提示符时,它运行 all R语法没有问题.我还尝试将.Rprofile设置为在加载R时默认将HH软件包加载,但这无法通过PHP解决问题.

When run through PHP, the output file will contain all output created above the call to hov.bf(), but nothing seems to run after this call. That is, "hello-1" is present in the output file, but "hello-2" and all other output below the hov.bf() call is not written to the file. However, when I copy and paste the exact command from PHP's exec() to Ubuntu's command prompt, it runs all R syntax without issue. I have also tried setting the .Rprofile to load the HH package as a default when R is loaded, but this did not resolve the issue through PHP.

如果有人有任何想法,我将不胜感激.我已经没有足够的想法了.

If anyone has any ideas, I would greatly appreciate them. I've run out of ideas for what it might be.

谢谢.

推荐答案

我发现了问题.

使用.libPaths()函数,即使通过PHP运行Rscript时,我也可以确定HH软件包安装到的默认目录包含在库路径中当R通过命令提示符执行相同的代码时.

Using the .libPaths() function, I was able to determine that the default directory that the HH package installed into was not included in the library paths when running Rscript through PHP, even though it was appearing when R was executing the same code through the command prompt.

我已经通过在动态创建的语法中包含对.libPaths('new/file/path');的单独调用解决了该问题.当我这样做时,

I've resolved the issue by include a separate call to .libPaths('new/file/path'); in my dynamically created syntax. When I do this,

test <-require('HH'); 
test; 
returns TRUE;

感谢所有提供帮助的人.

Thanks to all who helped.

这篇关于使用PHP exec()函数时R包无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆