rserve-client 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.2.2 / 2010-06-24
2
+ * ¿Bug? fix: a R matrix with a 0 dims raise an error [clbustos]
3
+ * Bug fix on rexpfactory: typo on creation of S4
4
+ * Updated Spec: session doesn't tested on windows
5
+ * Updated README.txt
6
+
1
7
  === 0.2.1 / 2010-06-18
2
8
  * Added suport to assign ruby std lib Matrix. Bug fix on retrieving matrix
3
9
  * Fixed whitespace problem on README.txt
data/README.txt CHANGED
@@ -16,7 +16,6 @@ Follows closely the new Java client API, but maintains all Ruby conventions when
16
16
  * Requires Rserve installed on the server machine. On debian / ubuntu, you should use <tt>sudo apt-get install r-cran-rserve</tt>
17
17
  Pros:
18
18
  * Work with Ruby 1.8, 1.9 and JRuby 1.5.
19
- * Work on Windows. Rserve limitations on that plataform applies (single connection, crash on parse errors)
20
19
  * Retrieve and assign various R's datatypes: integer, doubles, chars, logical vectors, lists and raw data.
21
20
  * 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.
22
21
  * Ruby API follows closely the Java API, so any change on the server API could be adopted without much problem
@@ -27,6 +26,7 @@ Pros:
27
26
  * From Ruby side: Every REXP objects has a <tt>to_ruby</tt> 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 <tt>eval</tt> without problem
28
27
  Cons:
29
28
  * Requires Rserve
29
+ * 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.
30
30
 
31
31
  == RELATED LIBRARIES (Ruby / R)
32
32
 
@@ -36,6 +36,7 @@ Cons:
36
36
  * Uses TCP/IP Sockets to send and retrieve data
37
37
  * Pros:
38
38
  * Doesn't requires anything but R
39
+ * Works flawlessly on Windows
39
40
  * Work with Ruby 1.8, 1.9 and JRuby 1.5
40
41
  * All API tested
41
42
  * Cons:
@@ -1,4 +1,3 @@
1
- require 'rbconfig'
2
1
  module Rserve
3
2
  class Connection < Rserve::Engine
4
3
  @@connected_object=nil
@@ -80,7 +79,7 @@ module Rserve
80
79
  def connect
81
80
  # On windows, Rserve doesn't allows concurrent connections.
82
81
  # So, we must close the last open connection first
83
- if RbConfig::CONFIG['arch']=~/mswin/ and !@@connected_object.nil?
82
+ if ON_WINDOWS and !@@connected_object.nil?
84
83
  @@connected_object.close
85
84
  end
86
85
 
@@ -446,7 +446,7 @@ module Rserve
446
446
  end
447
447
 
448
448
  if (xt==XT_S4)
449
- @cont = new REXP::S4.new(get_attr)
449
+ @cont = REXP::S4.new(get_attr)
450
450
  o=eox
451
451
  return o;
452
452
  end
@@ -10,12 +10,10 @@ module Rserve
10
10
  module Protocol
11
11
  # Arch dependent Long Nil value
12
12
  case Config::CONFIG['arch']
13
- when 'i686-linux'
13
+ when /i686-linux|mswin|mingw/
14
14
  LONG_NA=9221120237041092514 # :nodoc:
15
- when /mswin/
16
- LONG_NA=9221120237041092514 # :nodoc:
17
15
  else
18
- LONG_NA=9218868437227407266 # :nodoc:
16
+ LONG_NA=9218868437227407266 # :nodoc:
19
17
  end
20
18
  # Defines from Rsrv.h
21
19
  CMD_RESP=0x010000 # all responses have this flag set
@@ -5,12 +5,10 @@ module Rserve
5
5
  attr_reader :payload
6
6
  # NA is arch dependent
7
7
  case Config::CONFIG['arch']
8
- when 'i686-linux'
9
- NA = 269653970229425383598692395468593241088322026492507901905402939417320933254485890939796955099302180188971623023005661539310855695935759376615857567599472873400528811349204333736152257830107446553333670133666606746438802800063353690283455789426038632208916715592554825644961573453826957827246636338344317943808
10
- when /mswin/
11
- NA = 269653970229425383598692395468593241088322026492507901905402939417320933254485890939796955099302180188971623023005661539310855695935759376615857567599472873400528811349204333736152257830107446553333670133666606746438802800063353690283455789426038632208916715592554825644961573453826957827246636338344317943808
12
- else
13
- NA = 0x100000000007a2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
8
+ when /i686-linux|mswin|mingw/
9
+ NA = 269653970229425383598692395468593241088322026492507901905402939417320933254485890939796955099302180188971623023005661539310855695935759376615857567599472873400528811349204333736152257830107446553333670133666606746438802800063353690283455789426038632208916715592554825644961573453826957827246636338344317943808
10
+ else
11
+ NA = 0x100000000007a2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
14
12
  end
15
13
 
16
14
  def initialize(data, attrs=nil)
data/lib/rserve/rexp.rb CHANGED
@@ -253,12 +253,12 @@ module Rserve
253
253
  #
254
254
  # @return [Array] an array of integers with corresponding dimensions or <code>nil</code> if the object has no dimension attribute
255
255
  def dim
256
- begin
257
- return has_attribute?("dim") ? @attr.as_list['dim'].as_integers : nil;
258
- rescue MismatchException
259
- # nothing to do
260
- end
261
- nil
256
+ begin
257
+ return has_attribute?("dim") ? @attr.as_list['dim'].as_integers : nil;
258
+ rescue MismatchException
259
+ # nothing to do
260
+ end
261
+ nil
262
262
  end
263
263
 
264
264
  # determines whether this object inherits from a given class in the same fashion as the <code>inherits()</code> function in R does (i.e. ignoring S4 inheritance).
@@ -332,6 +332,7 @@ module Rserve
332
332
  raise "Improper size ar:#{ar} , dims=#{dims[0]}" if ar.size!=dims[0]
333
333
  return ar
334
334
  elsif dims.size==2
335
+ return Array.new() if dims.any? {|v| v==0}
335
336
  dims.reverse!
336
337
  # should rearrange values as R do
337
338
  # dims[0]=cols, dims[1]=rows
data/lib/rserve.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'socket'
2
-
2
+ require 'rbconfig'
3
3
  module Rserve
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.2'
5
+ ON_WINDOWS=RbConfig::CONFIG['arch']=~/mswin|mingw/
5
6
  end
6
7
 
7
8
 
@@ -1,10 +1,9 @@
1
1
  require File.dirname(__FILE__)+"/spec_helper.rb"
2
- require 'rbconfig'
3
2
  describe "Rserve::Connection on unix" do
3
+ if !Rserve::ON_WINDOWS
4
4
  before do
5
5
  @r=Rserve::Connection.new
6
6
  end
7
- if RbConfig::CONFIG['arch']!~/mswin/
8
7
  it "method eval_void should raise an error with an incorrect expression" do
9
8
  lambda {@r.void_eval("x<-")}.should raise_exception(Rserve::Connection::EvalError) {|e| e.request_packet.stat.should==2}
10
9
  lambda {@r.void_eval("as.stt(c(1))")}.should raise_exception(Rserve::Connection::EvalError) {|e|
@@ -26,10 +25,30 @@ describe "Rserve::Connection on unix" do
26
25
  s.eval('a').to_i.should==2
27
26
  s.close
28
27
  end
28
+ it "should eval_void_detach correctly" do
29
+ s=@r.void_eval_detach("x<-c(TRUE,FALSE)")
30
+ @r.should_not be_connected
31
+ s.should be_instance_of(Rserve::Session)
32
+ s.host.should==@r.hostname
33
+ s.key.size.should==32
34
+ end
35
+ it "should detach correctly" do
36
+ x=rand(100)
37
+ @r.void_eval("x<-#{x}")
38
+ s=@r.detach
39
+ @r.should_not be_connected
40
+ s.should be_instance_of(Rserve::Session)
41
+ s.host.should==@r.hostname
42
+ s.key.size.should==32
43
+ r=s.attach
44
+ r.eval("x").to_ruby==x
45
+ end
29
46
  else
30
47
  it "shouldn't crash server with an incorrect expression as Windows version does"
31
48
  it "shouldn't raise ServerNotAvailable if started another instance on another port as Windows version does"
32
- it "shouldn create a different session. On Windows, every new connection closes previously open session"
49
+ it "shouldn't create a different session. On Windows, every new connection closes previously open session"
50
+ it "shouldn't eval_void_detach correctly"
51
+ it "shouldn't detach correctly"
33
52
  end
34
53
 
35
54
  end
@@ -38,24 +38,7 @@ describe Rserve::Connection do
38
38
  la.should be_instance_of(Rserve::REXP::Logical)
39
39
  la.true?.should==[true]
40
40
  end
41
- it "should eval_void_detach correctly" do
42
- s=@r.void_eval_detach("x<-c(TRUE,FALSE)")
43
- @r.should_not be_connected
44
- s.should be_instance_of(Rserve::Session)
45
- s.host.should==@r.hostname
46
- s.key.size.should==32
47
- end
48
- it "should detach correctly" do
49
- x=rand(100)
50
- @r.void_eval("x<-#{x}")
51
- s=@r.detach
52
- @r.should_not be_connected
53
- s.should be_instance_of(Rserve::Session)
54
- s.host.should==@r.hostname
55
- s.key.size.should==32
56
- r=s.attach
57
- r.eval("x").to_ruby==x
58
- end
41
+
59
42
 
60
43
  it "should eval_void and eval correctly" do
61
44
  @r.void_eval("x<-c(TRUE,FALSE)").should be_true
@@ -44,6 +44,10 @@ describe "Rserve::REXP#to_ruby" do
44
44
  @r.void_eval("a<-1:16; attr(a,'dim')<-c(2,2,2,2)")
45
45
  @r.eval("a").to_ruby.should==[[[[1.0, 3.0], [2.0, 4.0]], [[5.0, 7.0], [6.0, 8.0]]],
46
46
  [[[9.0, 11.0], [10.0, 12.0]], [[13.0, 15.0], [14.0, 16.0]]]]
47
+ end
48
+ it "should return an empty Matrix with a matrix with a 0 dim" do
49
+ @r.void_eval("a<-as.matrix(numeric(0))")
50
+ @r.eval("a").to_ruby.should==Matrix[]
47
51
 
48
52
  end
49
53
  it "should return a boolean with a logical with one element" do
@@ -1,27 +1,31 @@
1
1
  require File.dirname(__FILE__)+"/spec_helper.rb"
2
2
  describe Rserve::Session do
3
- before do
4
- @r=Rserve::Connection.new
5
- end
6
- it "should resume an detached session with void_eval_detach" do
7
- x2=10+rand(12)
8
- s=@r.void_eval_detach("x<-1:#{x2}")
9
- r=Rserve::Connection.new
10
- r.void_eval("x<-1")
11
- r.eval("x").to_ruby.should==1
12
- s.should be_instance_of(Rserve::Session)
13
- r2=s.attach
14
- r2.eval("x").to_ruby.should==(1..x2).to_a
3
+ if !Rserve::ON_WINDOWS
4
+ before do
5
+ @r=Rserve::Connection.new
15
6
  end
16
- it "should resume an detached session with detach" do
17
- x2=10+rand(12)
18
- @r.void_eval("x<-1:#{x2}")
19
- s=@r.detach
20
- r=Rserve::Connection.new
21
- r.void_eval("x<-1")
22
- r.eval("x").to_ruby.should==1
23
- s.should be_instance_of(Rserve::Session)
24
- r2=s.attach
25
- r2.eval("x").to_ruby.should==(1..x2).to_a
26
- end
7
+ it "should resume an detached session with void_eval_detach" do
8
+ x2=10+rand(12)
9
+ s=@r.void_eval_detach("x<-1:#{x2}")
10
+ r=Rserve::Connection.new
11
+ r.void_eval("x<-1")
12
+ r.eval("x").to_ruby.should==1
13
+ s.should be_instance_of(Rserve::Session)
14
+ r2=s.attach
15
+ r2.eval("x").to_ruby.should==(1..x2).to_a
16
+ end
17
+ it "should resume an detached session with detach" do
18
+ x2=10+rand(12)
19
+ @r.void_eval("x<-1:#{x2}")
20
+ s=@r.detach
21
+ r=Rserve::Connection.new
22
+ r.void_eval("x<-1")
23
+ r.eval("x").to_ruby.should==1
24
+ s.should be_instance_of(Rserve::Session)
25
+ r2=s.attach
26
+ r2.eval("x").to_ruby.should==(1..x2).to_a
27
+ end
28
+ else
29
+ it "shouldn't work with sessions on windows"
30
+ end
27
31
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Claudio Bustos
@@ -35,7 +35,7 @@ cert_chain:
35
35
  rpP0jjs0
36
36
  -----END CERTIFICATE-----
37
37
 
38
- date: 2010-06-18 00:00:00 -04:00
38
+ date: 2010-06-24 00:00:00 -04:00
39
39
  default_executable:
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file