在 Mac OS 上的 Perl 中运行统计::R 模块 - 没有生成图像

发布于 2024-12-15 03:38:29 字数 656 浏览 0 评论 0原文

我想从 Perl 脚本中调用 R,但遇到问题,我认为这可能是 Mac 的问题,而不是 Perl / R 的问题(我有 Snow Leopard,R 在路径中,所以不存在 Perl 找不到的问题R)。我已经安装了Statistics::R 模块,但我认为图形没有被正确调用。我尝试过一个非常基本的脚本(这些命令在 R 中工作),但在 Perl 中似乎没有任何作用:-

use strict;     
use warnings;     
use Statistics::R;    
my $R = Statistics::R->new();     
$R->run(q`plot(c(1, 5, 10), type = "l")`);     
$R->run(q`dev.off()`);

注意 ' 实际上是反引号,但这里的论坛不会发布它们,因为它认为它们是代码示例。

这会在 R 中生成一个简单的线图,但在我运行 Perl 脚本时仅返回命令行提示符。 (这改编自 CPAN 模块页面 http://metacpan.org/pod/Statistics::R

希望有人能帮助我。

非常感谢

海伦

I would like to call R from within a Perl script but am having problems which I think may be a Mac thing rather than a Perl / R thing (I have Snow Leopard, and R is in the path, so no issue of Perl not finding R). I have installed the Statistics::R module but I don't think the graphics are being called properly. I have tried a very basic script (the commands work in R), but which appears to do nothing in Perl:-

use strict;     
use warnings;     
use Statistics::R;    
my $R = Statistics::R->new();     
$R->run(q`plot(c(1, 5, 10), type = "l")`);     
$R->run(q`dev.off()`);

NOTE the ' are really backticks but the forum here wont post them as it thinks they are a code sample.

This produces a simple line plot in R, but just returns the command line prompt when I run the Perl script. (This is adapted from the CPAN module page http://metacpan.org/pod/Statistics::R)

Hope someone can help me.

Many thanks

Helen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何处潇湘 2024-12-22 03:38:29

作为 MacR 的一员,我发现你的问题很有趣,并且对于你从文件图形设备 png() 获得输出,而不是从使用 plot() 获得输出并不感到惊讶。 code> 无需事先调用 dev.new() 。如果您输入 Mac 控制台图形设备 quartz(),则有可能(但绝不肯定)让 R 在监视器显示中打开交互式窗口。我无法从文档中判断 Perl 是否打开了交互式 R 会话。这段代码会产生什么:

use strict;     
use warnings;     
use Statistics::R;    
my $R = Statistics::R->new();
$R->run(q`quartz()`);
$R->run(q`plot(c(1, 5, 10), type = "l")`);     
$R->run(q`dev.off()`);

我还认为编写该代码的人会有兴趣了解您的进展。链接的网页要求提供反馈,如果您提供反馈,可能对其他 MacR 很有用。

I found your question intriguing, being a fellow MacR, and was not surprised that you got output from a file graphics device, png(), but not from the use of plot() without a prior call to dev.new(). It's possible, but by no means certain, that you could get R to open an interactive window in your monitor display if you entered the Mac console graphics device, quartz(). I wasn't able to tell from the documentation whether an interactive R session was being opened by Perl. What does this code produce:

use strict;     
use warnings;     
use Statistics::R;    
my $R = Statistics::R->new();
$R->run(q`quartz()`);
$R->run(q`plot(c(1, 5, 10), type = "l")`);     
$R->run(q`dev.off()`);

I also think the people who wrote that code would be interested in hearing about your progress. The linked webpages asked for feedback, and if you gave them such it might be useful to other MacRs down the line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文