Statistics::R - Controls the R (R-project) interpreter through Perl.
This will permit the control of the the R (R-project) interpreter through Perl in different architectures and OS.
You can for example, start only one instance of the R interpreter and have different Perl process accessing it.
use Statistics::R ; my $R = Statistics::R->new() ; $R->startR ; $R->send(q`postscript("file.ps" , horizontal=FALSE , width=500 , height=500 , pointsize=1)`) ; $R->send(q`plot(c(1, 5, 10), type = "l")`) ; $R->send(qq`x = 123 \n print(x)`) ; my $ret = $R->read ; $R->stopR() ;
When creating the R bridje object (Statistics::R), you can set some options:
The directory where the bridge between R and Perl will be created.
R and Perl need to have read and write access to the directory!
By dafault it will be created at %TMP_DIR%/Statistics-R.
The path to the R binary.
By default the path will be searched in the default installation path of R in the OS.
The directory of R.
A temporary directory.
By default the temporary directory of the OS will be used/searched.
Start R and the communication bridge.
Start R or use an already running communication bridge.
Stop R and the bridge.
stop() and start() R.
Return the path to the R binary (executable).
Send some command to be executed inside R. Note that $CMD will be loaded by R with source()
Read the output of R for the last group of commands sent to R by send().
Lock the bridge for your PID.
Unlock the bridge if your PID have locked it.
Return TRUE if the bridge is blocked for your PID.
In other words, returns TRUE if other process has lock()ed the bridge.
Return TRUE if the R interpreter is started, or still started.
Clean up the enverioment, removing all the objects.
Return the last error message.
To install this package you need to install R in your OS first, since Statistics::R need to find R path to work fine.
A standart installation of R on Win32 and Linux will work fine and detected automatically by Statistics::R.
Download page of R: http://cran.r-project.org/banner.shtml
Or go to the R web site: http://www.r-project.org/
The main pourpose of Statistics::R is to start a single R interpreter that hear multiple Perl process.
Note that to do that R and Perl need to be running with the same user/group level.
To start the Statistics::R bridge you can use the script statistics-r.pl:
$> statistics-r.pl start
From your script you need to use the start_sharedR() option:
use Statistics::R ; my $R = Statistics::R->new() ; $R->start_sharedR ; $R->send('x = 123') ; exit;
Note that in the example above the method stopR() wasn't called, sine it will close the bridge.
The R-project web site: http://www.r-project.org/
Statistics:: modules for Perl: http://search.cpan.org/search?query=Statistics&mode=module
Graciliano M. P. <email@example.com>
I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.