Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2009/01/29

Exercising futility ...

Run within R, it works. Run from test_R.pl, it doesn't. Why?



jacoby@oz:~/Desktop$ cat test_R.pl
#!/usr/bin/perl

use 5.010 ;
use strict ;
use warnings ;
use Carp ;
use Cwd ;
use File::Copy ;
use Statistics::R ;

my $cwd = getcwd ;

my $R = Statistics::R->new( ) ;
say 'starting R' ;
$R->startR ;

while ( ) {
chomp ;
my $line = $_ ;
next if $line =~ m{^q}mx ;
say $line ;
$R->send( $line ) ;
sleep 1;
}

$R->stopR() ;
say 'stopped R' ;


__DATA__
png(file="~/Desktop/plot.png")
plot(pressure)
postscript(file="~/Desktop/plot.ps")
plot(pressure)
jpeg(file="~/Desktop/plot.jpg")
plot(pressure)
q("no")
jacoby@oz:~/Desktop$ R

R version 2.7.1 (2008-06-23)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

>
> png(file="~/Desktop/plot.png")
> plot(pressure)
> postscript(file="~/Desktop/plot.ps")
> plot(pressure)
> jpeg(file="~/Desktop/plot.jpg")
> plot(pressure)
> q("no")
jacoby@oz:~/Desktop$ ./test_R.pl
starting R
png(file="~/Desktop/plot.png")
plot(pressure)
postscript(file="~/Desktop/plot.ps")
plot(pressure)
jpeg(file="~/Desktop/plot.jpg")
plot(pressure)
stopped R
jacoby@oz:~/Desktop$ ls plot.*
plot.jpg plot.png plot.ps
jacoby@oz:~/Desktop$ twitter.pl "It works from R but not via Statistics::R. It does not make sense."
It works from R but not via Statistics::R. It does not make sense.
OK
jacoby@oz:~/Desktop$

No comments:

Post a Comment