Need help with Rserve-Ruby-client?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

clbustos
123 Stars 26 Forks 173 Commits 11 Opened issues

Description

Pure Ruby client for Rserve. Based on 'new' Java client provided with server, but with modifications to adhere to POLS

Services available

!
?

Need anything else?

Contributors list

# 185,222
imputat...
Ruby
treemap
TeX
122 commits
# 274,962
Ruby
HTML
mongoid
rspec-m...
15 commits
# 356,039
JavaScr...
Shell
HTML
excel
5 commits
# 221,561
HTML
CSS
Rails
dsl
3 commits
# 454,484
C
Shell
CSS
1 commit
# 229,948
CSS
HTML
auth
iam
1 commit
# 31,055
Objecti...
Swift
sql-bui...
SQLite
1 commit
# 564,396
HTML
Perl
Shell
1 commit
# 207,025
CSS
React
statsd
Redux
1 commit
# 360,081
HTML
CSS
Shell
1 commit
# 553,174
Ruby
cookboo...
Apache ...
chef-co...
1 commit

rserve-client

  • http://github.com/clbustos/Rserve-Ruby-client

Build Status

DESCRIPTION:

Ruby client for Rserve, a Binary R server (http://www.rforge.net/Rserve/).

Follows closely the new Java client API, but maintains all Ruby conventions when possible.

FEATURES / LIMITATIONS

  • 100% ruby
  • Uses TCP/IP sockets to interchange data and commands
  • Requires Rserve installed on the server machine. On debian / ubuntu, you should use sudo apt-get install r-cran-rserve Pros:
  • Work with Ruby 1.9.3, 2.0.0, 2.1.1, 2.3.1 (tested on Travis) and and JRuby 1.5.
  • Retrieve and assign various R's datatypes: integer, doubles, chars, logical vectors, lists and raw data.
  • Session allows to process data asynchronously. You start a command, detach the process and retrieve result later. You can marshall the session, store on file or database and use it when you need it.
  • Ruby API follows closely the Java API, so any change on the server API could be adopted without much problem
  • Fast: 5-10 times faster than RinRuby.
  • Easy management of differences between R and Ruby, or "You can have your cake and eat it, too!"
    • From R side: The evaluation of expression retrieves REXP object, with a lot of information from original variables on R. You can construct your REXP objects and assign them to variables on R fast using binary TCP/IP port or send complex expression without lost of time using void_eval
    • Between R and Ruby: Every REXP object implements methods to convert to specific Ruby type: asintegers, asdoubles, as_strings
    • From Ruby side: Every REXP objects has a to_ruby method, which automagicly converts every R type on equivalent Ruby type. So, a vector of size 1 is converted to an integer or double, a vector of size>1 returns an array, a named list returns a hash and so on. If you need to create a complex expression, you could always use method eval without problem Cons:
  • Requires Rserve
  • Limited features on Windows, caused by limitations on Rserve on this platform: single concurrent connection allowed, server crash on parse errors and can't spawn sessions.

RELATED LIBRARIES (Ruby / R)

  • Rinruby [http://rinruby.ddahl.org/]
    • 100% ruby
    • Uses pipes to send commands and evals
    • Uses TCP/IP Sockets to send and retrieve data
    • Pros:
    • Doesn't requires anything but R
    • Works flawlessly on Windows
    • Work with Ruby 1.8, 1.9 and JRuby 1.5
    • All API tested
    • Cons:
    • VERY SLOW on assignation
    • Very limited datatypes: Only vector and Matrix
  • RSRuby
    • C Extension for Ruby, linked to R's shared library
    • Pros:
    • Blazing speed! 5-10 times faster than Rserve and 100-1000 than RinRuby.
    • Seamless integration with ruby. Every method and object is treated like a Ruby one
    • Cons:
    • Transformation between R and Ruby types aren't trivial
    • Dependent on operating system, Ruby implementation and R version
    • Ocassionaly crash
    • Not available for alternative implementations of Ruby (JRuby, IronRuby and Rubinius)

TODO

Implements

  • Original test

Spec

  • Test suite on Rserve Java new API
  • First tutorial on R

SYNOPSIS:

require 'rserve'
con=Rserve::Connection.new

Evaluation retrieves a Rserve::REXP object

x=con.eval('x #<:rexp::double:0x000000010a81f0>

You could use specific methods to retrieve ruby objects

x.as_doubles => [0.533736337958596] x.as_strings => ["0.533736337958596"]

Every Rserve::REXP could be converted to Ruby objects using

method to_ruby

x.to_ruby => (4807469545488851/9007199254740992)

The API could manage complex recursive list

x=con.eval('list(l1=list(c(2,3)),l2=c(1,2,3))').to_ruby => #<19590368 names:nil>, [(1/1), (2/1), (3/1)]] names:["l1", "l2"]>

You could assign a REXP to R variables

con.assign("x", Rserve::REXP::Double.new([1.5,2.3,5])) => #<:packet:0x0000000136b068> con.eval("x") => #<:rexp::double:0x0000000134e770>

Rserve::REXP::Wrapper.wrap allows you to transform Ruby object to

REXP, could be assigned to R variables

Rserve::REXP::Wrapper.wrap(["a","b",["c","d"]])

=> #<:rexp::genericvector:0x000000010c81d0>, #<:rexp::string:0x000000010c85c0>, #<:rexp::string:0x000000010c82e8>]>> </:rexp::string:0x000000010c82e8></:rexp::string:0x000000010c85c0></:rexp::genericvector:0x000000010c81d0></:rexp::double:0x0000000134e770></:packet:0x0000000136b068></19590368></:rexp::double:0x000000010a81f0>

REQUIREMENTS:

  • R
  • Rserve

INSTALL:

sudo gem install rserve-client

LICENSE:

REngine - Java interface to R Copyright (C) 2004,5,6,7 Simon Urbanek Copyrigth (C) 2010-2017 Claudio Bustos (Ruby version)

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.