Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Statistics::R module in Perl on Mac OS - no image being produced

Tags:

macos

r

perl

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

like image 732
Helen Wright Avatar asked Dec 22 '25 02:12

Helen Wright


1 Answers

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.

like image 133
IRTFM Avatar answered Dec 24 '25 16:12

IRTFM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!