rinruby 0.99.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rinruby.rb +23 -22
  2. metadata +35 -35
@@ -55,37 +55,38 @@
55
55
  #++
56
56
  #
57
57
  #
58
- #The required files java and readline are used when present at functionality.
58
+ #The files "java" and "readline" are used when available to add functionality.
59
59
 
60
60
  class RinRuby
61
61
 
62
- VERSION = '0.99.3'
62
+ VERSION = '1.0.0'
63
63
 
64
64
  require 'socket'
65
65
 
66
66
  attr_reader :interactive
67
67
  attr_reader :readline
68
68
 
69
- #RinRuby is invoked within a Ruby script (or the interactive 'irb' prompt denoted >>) using:
69
+ #RinRuby is invoked within a Ruby script (or the interactive "irb" prompt denoted >>) using:
70
70
  #
71
71
  # >> require "rinruby"
72
72
  #
73
- #This reads the definition of the RinRuby class into the current Ruby interpreter and creates an instance of the RinRuby class named R. There is a second method for starting an instance of R which allows the user to use any name for the instance, in this case myr:
73
+ #The previous statement reads the definition of the RinRuby class into the current Ruby interpreter and creates an instance of the RinRuby class named R. There is a second method for starting an instance of R which allows the user to use any name for the instance, in this case myr:
74
74
  #
75
75
  # >> require "rinruby"
76
76
  # >> myr = RinRuby.new
77
77
  # >> myr.eval "rnorm(1)"
78
+ #
78
79
  #Any number of independent instances of R can be created in this way.
79
80
  #
80
- #<b>Parameters that can be passed to the new method</b>
81
+ #<b>Parameters that can be passed to the new method:</b>
81
82
  #
82
83
  #* 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.
83
- #* interactive: When interactive is false, R is run in non-interaction mode, resulting in plots without an explicit device being written to Rplots.pdf. Otherwise, when interactive is true, such plots are shown on the screen. The default is true.
84
- #* executable: The path of the R executable (which is R in Linux and Mac OSX, or Rterm.exe in Windows) can be set with the executable argument. The default is nil, which on Windows uses the registry keys to find the path, or on linux and Mac OS X uses the path defined by $PATH.
84
+ #* 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.
85
+ #* executable: The path of the R executable (which is "R" in Linux and Mac OSX, 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).
85
86
  #* 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.
86
- #* 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.
87
+ #* 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.
87
88
  #
88
- #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:
89
+ #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:
89
90
  #
90
91
  # >> require "rinruby"
91
92
  # >> R.quit
@@ -149,7 +150,7 @@ class RinRuby
149
150
  @socket = @server_socket.accept
150
151
  end
151
152
 
152
- #The method quit will gracefully close the bridge between Ruby and R, freeing up system resources. This method is automatically run when a Ruby script ends.
153
+ #The quit method will properly close the bridge between Ruby and R, freeing up system resources. This method does not need to be run when a Ruby script ends.
153
154
 
154
155
  def quit
155
156
  @writer.puts "q(save='no')"
@@ -175,6 +176,7 @@ class RinRuby
175
176
  # -1.88900 -0.84930 -0.45220 -0.49290 -0.06069 0.78160
176
177
  # [1] 0.7327981
177
178
  #This example used a string substitution to make the argument to first eval method equivalent to x <- rnorm(10). This example used three invocations of the eval method, but a single invoke is possible using a here document:
179
+ #
178
180
  # >> R.eval <<EOF
179
181
  # x <- rnorm(#{sample_size})
180
182
  # summary(x)
@@ -183,7 +185,7 @@ class RinRuby
183
185
  #
184
186
  #<b>Parameters that can be passed to the eval method</b>
185
187
  #
186
- #* string: The string parameter is the code which is to be passed to R, for example, string = "hist(gamma(1000,5,3))". The string can also span a large chunk of code by use of a here document, as shown:
188
+ #* string: The string parameter is the code which is to be passed to R, for example, string = "hist(gamma(1000,5,3))". The string can also span several lines of code by use of a here document, as shown:
187
189
  # R.eval <<EOF
188
190
  # x<-rgamma(1000,5,3)
189
191
  # hist(x)
@@ -230,7 +232,7 @@ class RinRuby
230
232
  true
231
233
  end
232
234
 
233
- #When using sending code to Ruby using an interactive prompt, this method will change the prompt to an R prompt. From the R prompt commands can be sent to R exactly as if the R program was actually running. When the user is ready to return to Ruby, then the command exit() will return the prompt to Ruby. This is the ideal situation for the explorative programmer who needs to run several lines of code in R, and see the results after each command. This is also an easy way to execute loops without the use of a here document. It should be noted that the prompt command does not work in a script, just Ruby's interaction irb.
235
+ #When sending code to Ruby using an interactive prompt, this method will change the prompt to an R prompt. From the R prompt commands can be sent to R exactly as if the R program was actually running. When the user is ready to return to Ruby, then the command exit() will return the prompt to Ruby. This is the ideal situation for the explorative programmer who needs to run several lines of code in R, and see the results after each command. This is also an easy way to execute loops without the use of a here document. It should be noted that the prompt command does not work in a script, just Ruby's interactive irb.
234
236
  #
235
237
  #<b>Parameters that can be passed to the prompt method:</b>
236
238
  #
@@ -274,23 +276,22 @@ class RinRuby
274
276
  true
275
277
  end
276
278
 
277
- #If a method is called which is not defined, then it is assumed that the user is attempting to either pull or assign a variable to R. This allows the user to do a simplified notation. When an undefined method is followed by an equals sign, then it is assumed to be an assignment. Thus
279
+ #If a method is called which is not defined, then it is assumed that the user is attempting to either pull or assign a variable to R. This allows for the short-hand equivalents to the pull and assign methods. For example:
278
280
  #
279
281
  # >> R.x = 2
280
282
  #
281
- #is the same as
283
+ #is the same as:
282
284
  #
283
285
  # >> R.assign("x",2)
284
286
  #
285
- #If an equals sign does not follow the method, then it is assumed to be a pull. Thus
287
+ #Also:
286
288
  #
287
289
  # >> n = R.x
288
290
  #
289
- #is the same as
291
+ #is the same as:
290
292
  #
291
293
  # >> n = R.pull("x")
292
294
  #
293
- #This is also the reason is it not recommended that any variables be named after a method already defined, since this simplified notation would not work for that variable.
294
295
  #The parameters passed to method_missing are those used for the pull or assign depending on the context.
295
296
 
296
297
  def method_missing(symbol, *args)
@@ -334,7 +335,7 @@ class RinRuby
334
335
  #
335
336
  # >> R.test = 144
336
337
  #
337
- #is the same as
338
+ #is the same as:
338
339
  #
339
340
  # >> R.assign("test",144)
340
341
  #
@@ -427,7 +428,7 @@ class RinRuby
427
428
  # >> summary_of_x = R.pull "as.numeric(summary(x))"
428
429
  # >> puts summary_of_x
429
430
  #
430
- #produces the following :
431
+ #produces the following:
431
432
  #
432
433
  # -1.889
433
434
  # -0.8493
@@ -444,11 +445,11 @@ class RinRuby
444
445
  #
445
446
  #* singletons: R represents a single number as a vector of length one, but in Ruby it is often more convenient to use a number rather than an array of length one. Setting singleton=false will cause the pull method to shed the array, while singletons=true will return the number of string within an array. The default is false.
446
447
  #
447
- #The pull method is an alternative to the simplified form where the parameters are automatically used, in other words:
448
+ #The pull method is an alternative to the simplified form where the parameters are automatically used. For example:
448
449
  #
449
450
  # >> puts R.test
450
451
  #
451
- #is the same as
452
+ #is the same as:
452
453
  #
453
454
  # >> puts R.pull("test")
454
455
 
@@ -515,7 +516,7 @@ class RinRuby
515
516
  result
516
517
  end
517
518
 
518
- #The eval method displays the output from R by default, but this can be turned off by using the echo method. This method is useful when the output behavior needs to be changed
519
+ #The echo method controls whether the eval method displays output from R.
519
520
  #
520
521
  #<b>Parameters that can be passed to the eval method</b>
521
522
  #
metadata CHANGED
@@ -1,47 +1,47 @@
1
- --- !ruby/object:Gem::Specification
2
- required_ruby_version: !ruby/object:Gem::Requirement
3
- requirements:
4
- - - '>='
5
- - !ruby/object:Gem::Version
6
- version: !str 0
7
- version:
8
- email: rinruby@ddahl.org
9
- cert_chain: []
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: rinruby
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2008-07-03 00:00:00 -05:00
10
8
  summary: Accessing the R interpreter from pure Ruby
11
- post_install_message:
12
- extra_rdoc_files: []
9
+ require_paths:
10
+ - lib
11
+ email: rinruby@ddahl.org
13
12
  homepage: http://rinruby.ddahl.org
14
- signing_key:
15
- name: rinruby
16
- rdoc_options: []
17
- autorequire:
18
13
  rubyforge_project: rinruby
19
- executables: []
20
14
  description:
21
- specification_version: 2
15
+ autorequire:
22
16
  default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - David B. Dahl
23
31
  files:
24
32
  - lib/rinruby.rb
25
33
  - README.txt
26
- required_rubygems_version: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - '>='
29
- - !ruby/object:Gem::Version
30
- version: !str 0
31
- version:
34
+ test_files: []
35
+
36
+ rdoc_options: []
37
+
38
+ extra_rdoc_files: []
39
+
40
+ executables: []
41
+
32
42
  extensions: []
33
- rubygems_version: 1.1.0
43
+
34
44
  requirements:
35
45
  - R (http://www.r-project.org), an environment for statistical computing and graphics
36
- authors:
37
- - David B. Dahl
38
- date: 2008-07-02 05:00:00 +00:00
39
- platform: ruby
40
- test_files: []
41
- version: !ruby/object:Gem::Version
42
- version: 0.99.3
43
- require_paths:
44
- - lib
45
46
  dependencies: []
46
- bindir: bin
47
- has_rdoc: true
47
+