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?

  1. jacoby@oz:~/Desktop$ cat test_R.pl   
  2. #!/usr/bin/perl  
  3.   
  4. use 5.010 ;  
  5. use strict ;  
  6. use warnings ;  
  7. use Carp ;  
  8. use Cwd ;  
  9. use File::Copy ;  
  10. use Statistics::R ;  
  11.   
  12. my $cwd = getcwd ;  
  13.   
  14. my $R = Statistics::R->new( ) ;  
  15. say 'starting R' ;  
  16. $R->startR ;  
  17.   
  18. while ( <data> ) {  
  19.     chomp ;  
  20.     my $line = $_ ;  
  21.     next if $line =~ m{^q}mx ;  
  22.     say $line ;  
  23.     $R->send$line ) ;  
  24.     sleep 1;  
  25.     }  
  26.   
  27. $R->stopR() ;  
  28. say 'stopped R' ;  
  29.   
  30.   
  31. __DATA__  
  32. png(file="~/Desktop/plot.png")  
  33. plot(pressure)  
  34. postscript(file="~/Desktop/plot.ps")  
  35. plot(pressure)  
  36. jpeg(file="~/Desktop/plot.jpg")  
  37. plot(pressure)  
  38. q("no")  
  39. jacoby@oz:~/Desktop$ R  
  40.   
  41. R version 2.7.1 (2008-06-23)  
  42. Copyright (C) 2008 The R Foundation for Statistical Computing  
  43. ISBN 3-900051-07-0  
  44.   
  45. R is free software and comes with ABSOLUTELY NO WARRANTY.  
  46. You are welcome to redistribute it under certain conditions.  
  47. Type 'license()' or 'licence()' for distribution details.  
  48.   
  49.   Natural language support but running in an English locale  
  50.   
  51. R is a collaborative project with many contributors.  
  52. Type 'contributors()' for more information and  
  53. 'citation()' on how to cite R or R packages in publications.  
  54.   
  55. Type 'demo()' for some demos, 'help()' for on-line help, or  
  56. 'help.start()' for an HTML browser interface to help.  
  57. Type 'q()' to quit R.  
  58.   
  59. >   
  60. > png(file="~/Desktop/plot.png")  
  61. > plot(pressure)  
  62. > postscript(file="~/Desktop/plot.ps")  
  63. > plot(pressure)  
  64. > jpeg(file="~/Desktop/plot.jpg")  
  65. > plot(pressure)  
  66. q("no")  
  67. jacoby@oz:~/Desktop$ ./test_R.pl   
  68. starting R  
  69. png(file="~/Desktop/plot.png")  
  70. plot(pressure)  
  71. postscript(file="~/Desktop/plot.ps")  
  72. plot(pressure)  
  73. jpeg(file="~/Desktop/plot.jpg")  
  74. plot(pressure)  
  75. stopped R  
  76. jacoby@oz:~/Desktop$ ls plot.*  
  77. plot.jpg  plot.png  plot.ps  
  78. jacoby@oz:~/Desktop$ twitter.pl "It works from R but not via Statistics::R. It does not make sense."  
  79. It works from R but not via Statistics::R. It does not make sense.  
  80. OK  
  81. jacoby@oz:~/Desktop$   
  82.   
  83. </data>  

No comments:

Post a Comment