NAME

Rserve - Supply object methods for Rserve communication

SYNOPSIS

use Rserve;

my $rserve = Rserve->new('someserver');
my $var = $rserve->eval('1 + 1');
print $var->to_perl;
$rserve->close;

DESCRIPTION

Rserve provides an object-oriented interface to communicate with the Rserve binary R server.

This allows Perl programs to access all facilities of R without the need to have a local install of R or link to an R library.

METHODS

CONSTRUCTOR

Rserve->new($server)

The single-argument constructor can be invoked with a scalar containing the host name of the Rserve server. The method will immediately open a socket connection to the server and perform the initial steps prescribed by the protocol. The method will raise an exception if the connection cannot be established or if the remote host does not appear to run the correct version of Rserve.

Rserv->new($handle)

The single-argument constructor can be invoked with an instance of IO::Handle containing the connection to the Rserve server, which becomes the 'fh' attribute. The caller is responsible for ensuring that the connection is established and ready for submitting client requests.

Rserve->new(ATTRIBUTE_HASH_OR_HASH_REF)

The constructor's arguments can also be given as a hash or hash reference, specifying values of the object attributes. The caller passing the handle is responsible for ensuring that the connection is established and ready for submitting client requests.

new

The no-argument constructor uses the default server name 'localhost' and port 6311 and immediately opens a socket connection to the server, performing the initial steps prescribed by the protocol. The method will raise an exception if the connection cannot be established or if the remote host does not appear to run the correct version of Rserve.

ACCESSORS

server

Name of the Rserve server.

port

Port of the Rserve server.

fh

A connection handle (stored as a reference to the IO::Handle) to the Rserve server.

METHODS

eval

$rserve->eval($rexpr)

Evaluates the R expression, given as text string in $rexpr, on an Rserve server and returns its result as a Rserve::REXP object.

try_eval

$rserve->try_eval($rexpr)

This is the same as eval except that $rexpr is guarded by the R try function. The result is returned as an REXP if no exceptions are raised.

get_file

$rserve->get_file($remote_file_name)

Transfers a file named $remote_file_name from the Rserve server to the local machine. Returns the contents of the file as a scalar.

close

Closes the object's filehandle. This method is automatically invoked when the object is destroyed if the connection was opened by the constructor, but not if it was passed in as a pre-opened handle.