• Stars
    star
    126
  • Rank 275,803 (Top 6 %)
  • Language
    Ruby
  • Created about 14 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

rserve-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: as_integers, as_doubles, 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 <tt>Rserve::REXP</tt> object

x=con.eval('x<-rnorm(1)')
=> #<Rserve::REXP::Double:0x000000010a81f0 @payload=[(4807469545488851/9007199254740992)], @attr=nil>

# 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 <tt>to_ruby</tt>
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
=> #<Array:19590368 [#<Array:19590116 [[(2/1), (3/1)]] 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]))
=> #<Rserve::Packet:0x0000000136b068 @cmd=65537, @cont=nil>
con.eval("x")
=> #<Rserve::REXP::Double:0x0000000134e770 @payload=[(3/2), (2589569785738035/1125899906842624), (5/1)], @attr=nil>

# 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"]])

=> #<Rserve::REXP::GenericVector:0x000000010c81d0 @attr=nil, @payload=#<Rserve::Rlist:0x000000010c8278 @names=nil, @data=[#<Rserve::REXP::String:0x000000010c86d8 @payload=["a"], @attr=nil>, #<Rserve::REXP::String:0x000000010c85c0 @payload=["b"], @attr=nil>, #<Rserve::REXP::String:0x000000010c82e8 @payload=["c", "d"], @attr=nil>]>>

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

More Repositories

1

statsample

A suite for basic and advanced statistics on Ruby.
Ruby
401
star
2

rubyvis

Ruby version of Protovis, a visualization toolkit.
Ruby
236
star
3

rinruby

Ruby library that integrates the R interpreter in Ruby, making R's statistical routines and graphics available within Ruby.
Ruby
152
star
4

distribution

Statistical Distributions multi library wrapper. Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
Ruby
141
star
5

PHP_Beautifier

This program reformat and beautify PHP 4 and PHP 5 source code files automatically. The program is Open Source and distributed under the terms of PHP Licence. It is written in PHP 5 and has a command line tool.
PHP
106
star
6

extendmatrix

Cosmin Bonchis's enhancements to the Ruby "Vector" and "Matrix" module and includes: LU and QR (Householder, Givens, Gram Schmidt, Hessenberg) decompositions, bidiagonalization, eigenvalue and eigenvector calculations. Work on Ruby 1.8.7, 1.9.1 and 1.9.2 (SVN version)
Ruby
33
star
7

buhos

Web based systematic literature review software
Ruby
27
star
8

dominanceAnalysis

Dominance Analysis (Azen and Bodescu), for multiple regression models: OLS (univariate, multivariate), beta regression, Dynamic Linear Models, GLM and HLM
R
21
star
9

minimization

Minimization algorithms on pure Ruby
Ruby
19
star
10

integration

Integration methods, based on original work by Beng
Ruby
15
star
11

svg-graph

SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph, although the internal code no longer resembles the Perl original at all.
Ruby
13
star
12

reportbuilder

Ruby report abstract interface. Creates text, html and rtf output, based on a common framework.
JavaScript
11
star
13

web-plotter3d

A web based 3d plotter, using canvas and JS
JavaScript
6
star
14

analisis_covid19_chile

Ejemplo de analisis de serie de tiempo sobre casos Covid-19. Se presenta un reporte comparativo de Chile con otros países, así como por regiones.
HTML
6
star
15

statsample-optimization

Extension for statsample, that speed some methods.
C
5
star
16

gsl_narray_stdlib_comparison

Compare perfomance of GSL, Narray and stdlib Matrix on matrix and vectors operations
Ruby
4
star
17

statsample-sem

Structural Equation Modeling on Ruby, using statsample and R
Ruby
4
star
18

exner

Create structural summary for Rorschach Comprehensive System. Works with Znudic method for Zulliger test, based on Exner's RCS.
Ruby
3
star
19

analisis_constitucion

Análisis de contenido de las diferencias entre la versión de 1980 y la versión de 2005 de la Constitución Chilena
Ruby
3
star
20

coolcat-r

Clustering algorithm Coolcat(Barbará, Couto, Li) implemented on R
R
3
star
21

buhos-windows-tk

Windows toolkit to build Buhos installer
HTML
2
star
22

dirty-memoize

Like Memoize, but designed for mutable and parametizable objects
Ruby
2
star
23

rcebn

Just some random methods I use on R. Mainly mplus interfaces and some utilities
R
1
star
24

statsample-bivariate-extension

Polychoric and Tetrachoric support for statsample
Ruby
1
star