Build a Statistics::R bridge object connecting Perl and R. Available options
First, start() R if it is not yet running. Then, execute R commands passed
as a string and return the output as a string. If your commands failed to run
in R, an error message will be displayed.
If you intend on runnning many R commands, it may be convenient to pass a list of commands or put multiple commands in an here-doc:
Alternatively, to run commands from a file, use the run_from_file() method.
The return value you get from run() is a combination of what R would display on the standard output and the standard error, but the exact order may differ.
When loading modules, some may write numerous messages on standard error. You can disable this behavior using the following R command:
In this case, try to break down your R code into several smaller, more manageable statements. Alternatively, adding newline characters \n at strategic places in the R statements will work around the issue.
|run_from_file()||Similar to run() but reads the R commands from the specified file. Internally, this method converts the filename to a format compatible with R and then passes it to the R source() command to read the file and execute the commands.|
|result()||Get the results from the last R command.|
Set the value of an R variable (scalar or vector). Example:
Get the value of an R variable (scalar or vector). Example:
|start()||Explicitly start R. Most times, you do not need to do that because the first execution of run() or set() will automatically call start().|
|stop()||Stop a running instance of R. You need to call this method after running a shared bridge. For a simple bridge, you do not need to do this because stop() is automatically called when the Statistics::R object goes out of scope.|
|restart()||stop() and start() R.|
|bin()||Get or set the path to the R executable. Note that the path will be available only after start() has been called.|
|version()||Get the version number of R.|
|is_shared()||Was R started in shared mode?|
|is_started()||Is R running?|
|pid()||Return the PID of the running R process|
Since Statistics::R relies on R to work, you need to install R first. See this page for downloads, <http://www.r-project.org/>. If R is in your PATH environment variable, then it should be available from a terminal and be detected automatically by Statistics::R. This means that you dont have to do anything on Linux systems to get Statistics::R working. On Windows systems, in addition to the folders described in PATH, the usual suspects will be checked for the presence of the R binary, e.g. C:\Program Files\R. If Statistics::R does not find where R is installed, your last recourse is to specify its full path when calling new():
my $R = Statistics::R->new( bin => $fullpath );
You also need to have the following CPAN Perl modules installed:
IPC::Run Regexp::Common Text::Balanced (>= 1.97) Text::Wrap version (>= 0.77)
o Statistics::R::Win32 o Statistics::R::Legacy o The R-project web site: <http://www.r-project.org/> o Statistics::* modules for Perl: <http://search.cpan.org/search?query=Statistics&mode=module>
Florent Angly <firstname.lastname@example.org> (2011 rewrite)
Graciliano M. P. <email@example.com> (original code)
Florent Angly <firstname.lastname@example.org>
Brian Cassidy <email@example.com>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
All complex software has bugs lurking in it, and this program is no exception. If you find a bug, please report it on the CPAN Tracker of Statistics::R: <http://rt.cpan.org/Dist/Display.html?Name=Statistics-R>
Bug reports, suggestions and patches are welcome. The Statistics::R code is developed on Github (<http://github.com/bricas/statistics-r>) and is under Git revision control. To get the latest revision, run:
git clone git://github.com/bricas/statistics-r.git
|perl v5.20.3||STATISTICS::R (3)||2015-10-19|