rinruby 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,6 @@
1
+ === 2.0.0 / 2010-05-26
2
+ * Changed RinRuby initialize, with option Hash instead of ordered parameters.
3
+
1
4
  === 1.2.0 / 2010-05-23
2
5
 
3
6
  * Fixed to works on Ruby 1.9
@@ -34,14 +34,14 @@
34
34
  #
35
35
  #Coded by:: David B. Dahl
36
36
  #Documented by:: David B. Dahl & Scott Crawford
37
- #Copyright:: 2005-2008
37
+ #Copyright:: 2005-2009
38
38
  #Web page:: http://rinruby.ddahl.org
39
39
  #E-mail:: mailto:rinruby@ddahl.org
40
- #License:: GNU General Public License (GPL), version 3 or later
40
+ #License:: GNU Lesser General Public License (LGPL), version 3 or later
41
41
  #
42
42
  #--
43
43
  # This program is free software: you can redistribute it and/or modify
44
- # it under the terms of the GNU General Public License as published by
44
+ # it under the terms of the GNU Lesser General Public License as published by
45
45
  # the Free Software Foundation, either version 3 of the License, or
46
46
  # (at your option) any later version.
47
47
  #
@@ -50,7 +50,7 @@
50
50
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51
51
  # GNU General Public License for more details.
52
52
  #
53
- # You should have received a copy of the GNU General Public License
53
+ # You should have received a copy of the GNU Lesser General Public License
54
54
  # along with this program. If not, see <http://www.gnu.org/licenses/>
55
55
  #++
56
56
  #
@@ -62,7 +62,7 @@ class RinRuby
62
62
  require 'socket'
63
63
 
64
64
 
65
- VERSION = '1.2.0'
65
+ VERSION = '2.0.0'
66
66
 
67
67
 
68
68
  attr_reader :interactive
@@ -85,33 +85,43 @@ class RinRuby
85
85
  #
86
86
  #Any number of independent instances of R can be created in this way.
87
87
  #
88
- #<b>Parameters that can be passed to the new method:</b>
88
+ #<b>Parameters that can be passed to the new method using a Hash:</b>
89
89
  #
90
- #* echo: By setting the echo to false, output from R is suppressed, although warnings are still printed. This option can be changed later by using the echo method. The default is true.
91
- #* interactive: When interactive is false, R is run in non-interactive mode, resulting in plots without an explicit device being written to Rplots.pdf. Otherwise (i.e., interactive is true), plots are shown on the screen. The default is true.
92
- #* executable: The path of the R executable (which is "R" in Linux and Mac OS X, or "Rterm.exe" in Windows) can be set with the executable argument. The default is nil which makes RinRuby use the registry keys to find the path (on Windows) or use the path defined by $PATH (on Linux and Mac OS X).
93
- #* port_number: This is the smallest port number on the local host that could be used to pass data between Ruby and R. The actual port number used depends on port_width.
94
- #* port_width: RinRuby will randomly select a uniform number between port_number and port_number + port_width - 1 (inclusive) to pass data between Ruby and R. If the randomly selected port is not available, RinRuby will continue selecting random ports until it finds one that is available. By setting port_width to 1, RinRuby will wait until port_number is available. The default port_width is 1000.
90
+ #* :echo: By setting the echo to false, output from R is suppressed, although warnings are still printed. This option can be changed later by using the echo method. The default is true.
91
+ #* :interactive: When interactive is false, R is run in non-interactive mode, resulting in plots without an explicit device being written to Rplots.pdf. Otherwise (i.e., interactive is true), plots are shown on the screen. The default is true.
92
+ #* :executable: The path of the R executable (which is "R" in Linux and Mac OS X, or "Rterm.exe" in Windows) can be set with the executable argument. The default is nil which makes RinRuby use the registry keys to find the path (on Windows) or use the path defined by $PATH (on Linux and Mac OS X).
93
+ #* :port_number: This is the smallest port number on the local host that could be used to pass data between Ruby and R. The actual port number used depends on port_width.
94
+ #* :port_width: RinRuby will randomly select a uniform number between port_number and port_number + port_width - 1 (inclusive) to pass data between Ruby and R. If the randomly selected port is not available, RinRuby will continue selecting random ports until it finds one that is available. By setting port_width to 1, RinRuby will wait until port_number is available. The default port_width is 1000.
95
95
  #
96
96
  #It may be desirable to change the parameters to the instance of R, but still call it by the name of R. In that case the old instance of R which was created with the 'require "rinruby"' statement should be closed first using the quit method which is explained below. Unless the previous instance is killed, it will continue to use system resources until exiting Ruby. The following shows an example by changing the parameter echo:
97
97
  #
98
98
  # >> require "rinruby"
99
99
  # >> R.quit
100
100
  # >> R = RinRuby.new(false)
101
-
102
- def initialize(echo=true, interactive=true, executable=nil, port_number=38442, port_width=1000)
101
+ attr_reader :echo_enabled
102
+ attr_reader :executable
103
+ attr_reader :port_number
104
+ attr_reader :port_width
105
+ attr_reader :hostname
106
+ def initialize(opts=Hash.new())
107
+ default_opts= {:echo=>true, :interactive=>true, :executable=>nil, :port_number=>38442, :port_width=>1000, :hostname=>'127.0.0.1'}
108
+
109
+ @opts=default_opts.merge(opts)
110
+ @port_width=@opts[:port_width]
111
+ @executable=@opts[:executable]
112
+ @hostname=@opts[:hostname]
103
113
  while true
104
114
  begin
105
- @port_number = port_number + rand(port_width)
106
- @server_socket = TCPServer::new("127.0.0.1", @port_number)
115
+ @port_number = @opts[:port_number] + rand(port_width)
116
+ @server_socket = TCPServer::new(@hostname, @port_number)
107
117
  break
108
118
  rescue Errno::EADDRINUSE
109
119
  sleep 0.5 if port_width == 1
110
120
  end
111
121
  end
112
- @echo_enabled = echo
122
+ @echo_enabled = @opts[:echo]
113
123
  @echo_stderr = false
114
- @interactive = interactive
124
+ @interactive = @opts[:interactive]
115
125
  @platform = case RUBY_PLATFORM
116
126
  when /mswin/ then 'windows'
117
127
  when /mingw/ then 'windows'
@@ -126,8 +136,8 @@ class RinRuby
126
136
  end
127
137
  else 'default'
128
138
  end
129
- if executable == nil
130
- executable = ( @platform =~ /windows/ ) ? find_R_on_windows(@platform =~ /cygwin/) : 'R'
139
+ if @executable == nil
140
+ @executable = ( @platform =~ /windows/ ) ? find_R_on_windows(@platform =~ /cygwin/) : 'R'
131
141
  end
132
142
  platform_options = []
133
143
  if ( @interactive )
@@ -148,7 +158,7 @@ class RinRuby
148
158
  @writer.puts <<-EOF
149
159
  #{RinRuby_KeepTrying_Variable} <- TRUE
150
160
  while ( #{RinRuby_KeepTrying_Variable} ) {
151
- #{RinRuby_Socket} <- try(suppressWarnings(socketConnection("127.0.0.1", #{@port_number}, blocking=TRUE, open="rb")),TRUE)
161
+ #{RinRuby_Socket} <- try(suppressWarnings(socketConnection("#{@hostname}", #{@port_number}, blocking=TRUE, open="rb")),TRUE)
152
162
  if ( inherits(#{RinRuby_Socket},"try-error") ) {
153
163
  Sys.sleep(0.1)
154
164
  } else {
@@ -224,7 +234,7 @@ class RinRuby
224
234
  @writer.puts "warning('#{RinRuby_Stderr_Flag}',immediate.=TRUE)" if @echo_stderr
225
235
  @writer.puts "print('#{RinRuby_Eval_Flag}')"
226
236
  else
227
- raise ParseError, "Parse error on eval"
237
+ raise ParseError, "Parse error on eval:#{string}"
228
238
  end
229
239
  Signal.trap('INT') do
230
240
  @writer.print ''
@@ -260,7 +270,7 @@ class RinRuby
260
270
  return false if line == RinRuby_Exit_Flag
261
271
  if echo_enabled && echo_eligible
262
272
  puts line
263
- $stdout.flush
273
+ $stdout.flush if @platform !~ /windows/
264
274
  end
265
275
  end
266
276
  Signal.trap('INT') do
@@ -1,6 +1,22 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ puts "RinRuby #{RinRuby::VERSION} specification"
2
3
 
3
4
  describe RinRuby do
5
+ describe "on init" do
6
+ it "should accept :port_number" do
7
+ port=38442+rand(3)
8
+ r=RinRuby.new(:port_number=>port,:port_width=>1)
9
+ r.port_number.should==port
10
+ r.quit
11
+ end
12
+ it "should accept :port_width" do
13
+ port=38442
14
+ port_width=rand(10)
15
+ r=RinRuby.new(:port=>port, :port_width=>port_width)
16
+ r.port_width.should==port_width
17
+ r.port_number.should satisfy {|v| v>=port and v < port+port_width}
18
+ end
19
+ end
4
20
  before do
5
21
  R.echo(false)
6
22
  end
@@ -90,7 +106,7 @@ describe RinRuby do
90
106
 
91
107
  context "on quit" do
92
108
  before(:each) do
93
- @r=RinRuby.new(false)
109
+ @r=RinRuby.new(:echo=>false)
94
110
  end
95
111
  it "return true" do
96
112
  @r.quit.should be_true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rinruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Dahl
metadata.gz.sig CHANGED
Binary file