rootapp-rinruby 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rinruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rootapp-rinruby"
8
+ spec.version = RinRuby::VERSION
9
+ spec.author = "ROOT devs"
10
+ spec.email = "devs@joinroot.com"
11
+ spec.summary = %q{RinRuby is a Ruby library that integrates the R interpreter in Ruby}
12
+ spec.description = <<-EOF
13
+ RinRuby is a Ruby library that integrates the R interpreter in Ruby, making
14
+ R's statistical routines and graphics available within Ruby. The library
15
+ consists of a single Ruby script that is simple to install and does not
16
+ require any special compilation or installation of R. Since the library is
17
+ 100% pure Ruby, it works on a variety of operating systems, Ruby
18
+ implementations, and versions of R. RinRuby's methods are simple, making for
19
+ readable code. The {website [rinruby.ddahl.org]}[http://rinruby.ddahl.org]
20
+ describes RinRuby usage, provides comprehensive documentation, gives several
21
+ examples, and discusses RinRuby's implementation.
22
+ EOF
23
+ spec.homepage = "https://github.com/Root-App/rinruby"
24
+ spec.license = "GPLv3"
25
+
26
+ spec.files = `git ls-files`.split($/)
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "rake"
32
+ spec.add_development_dependency "rspec"
33
+ end
@@ -0,0 +1,172 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ puts "RinRuby #{RinRuby::VERSION} specification"
3
+
4
+ R = RinRuby.new
5
+
6
+ describe RinRuby do
7
+ describe "VERSION" do
8
+ it "is set" do
9
+ expect(RinRuby::VERSION).to match(/\d+\.\d+\.\d+/)
10
+ end
11
+ end
12
+
13
+ describe "on init" do
14
+ it "should accept parameters as specified on Dahl & Crawford(2009)" do
15
+ r = RinRuby.new(false, "R", 38500, 1)
16
+
17
+ expect(r.echo_enabled).to be(false)
18
+ expect(r.executable).to eq("R")
19
+ expect(r.port_number).to eq(38500)
20
+ expect(r.port_width).to eq(1)
21
+ end
22
+
23
+ it "should accept :echo parameters" do
24
+ r = RinRuby.new(:echo => false)
25
+ expect(r.echo_enabled).to be(false)
26
+ end
27
+
28
+ it "should accept :port_number" do
29
+ port = 38442 + rand(3)
30
+ r = RinRuby.new(:port_number => port, :port_width => 1)
31
+ expect(r.port_number).to eq(port)
32
+ r.quit
33
+ end
34
+
35
+ it "should accept :port_width" do
36
+ port = 38442
37
+ port_width = rand(10) + 1
38
+ r = RinRuby.new(:port => port, :port_width => port_width)
39
+
40
+ expect(r.port_width).to eq(port_width)
41
+ expect(r.port_number).to satisfy { |v| v >= port && v < port + port_width }
42
+ end
43
+ end
44
+
45
+ before do
46
+ R.echo(false)
47
+ end
48
+
49
+ subject {R}
50
+
51
+ context "basic methods" do
52
+ it {should respond_to :eval}
53
+ it {should respond_to :quit}
54
+ it {should respond_to :assign}
55
+ it {should respond_to :pull}
56
+ it {should respond_to :quit}
57
+ it {should respond_to :echo}
58
+
59
+ it "return correct values for complete?" do
60
+ expect(R.eval("x <- 1")).to be(true)
61
+ end
62
+
63
+ it "return false for complete? for incorrect expressions" do
64
+ expect(R.complete?("x <-")).to be(false)
65
+ end
66
+
67
+ it "correct eval should return true" do
68
+ expect(R.complete?("x <- 1")).to be(true)
69
+ end
70
+
71
+ it "incorrect eval should raise an ParseError" do
72
+ expect do
73
+ R.eval("x <-")
74
+ end.to raise_error(RinRuby::ParseError)
75
+ end
76
+ end
77
+
78
+ context "on assign" do
79
+ it "should assign correctly" do
80
+ x = rand
81
+ R.assign("x", x)
82
+ expect(R.pull("x")).to eq(x)
83
+ end
84
+ end
85
+
86
+ context "on pull" do
87
+ it "should pull a String" do
88
+ R.eval("x <- 'Value'")
89
+ expect(R.pull("x")).to eq("Value")
90
+ end
91
+
92
+ it "should pull an Integer" do
93
+ R.eval("x <- 1")
94
+ expect(R.pull("x")).to eq(1)
95
+ end
96
+
97
+ it "should pull a Float" do
98
+ R.eval("x <- 1.5")
99
+ expect(R.pull("x")).to eq(1.5)
100
+ end
101
+
102
+ it "should pull an Array of Numeric" do
103
+ R.eval("x <- c(1,2.5,3)")
104
+ expect(R.pull("x")).to eq([1, 2.5, 3])
105
+ end
106
+
107
+ it "should pull an Array of strings" do
108
+ R.eval("x <- c('a', 'b')")
109
+ expect(R.pull("x")).to eq(["a", "b"])
110
+ end
111
+
112
+ it "should push a Matrix" do
113
+ matrix = Matrix[
114
+ [rand, rand, rand],
115
+ [rand, rand, rand]
116
+ ]
117
+
118
+ R.assign('x', matrix)
119
+ pulled_matrix = R.pull("x")
120
+
121
+ matrix.row_size.times do |i|
122
+ matrix.column_size.times do |j|
123
+ expect(matrix[i,j]).to be_within(1e-10).of(pulled_matrix[i,j])
124
+ end
125
+ end
126
+ end
127
+
128
+ it "raises UndefinedVariableError if pulling variable that is undefined" do
129
+ expect do
130
+ R.pull("miss")
131
+ end.to raise_error(RinRuby::UndefinedVariableError)
132
+ end
133
+
134
+ it "raises error message if trying to pull a type that cannot be sent over wire" do
135
+ expect do
136
+ R.pull("typeof")
137
+ end.to raise_error(RinRuby::UnsupportedTypeError, "Unsupported R data type 'function closure '")
138
+ end
139
+ end
140
+
141
+ context "on quit" do
142
+ before(:each) do
143
+ @r = RinRuby.new(:echo => false)
144
+ end
145
+
146
+ it "return true" do
147
+ expect(@r.quit).to be(true)
148
+ end
149
+
150
+ it "returns an error if used again" do
151
+ @r.quit
152
+ expect do
153
+ @r.eval("x = 1")
154
+ end.to raise_error(RinRuby::EngineClosed)
155
+ end
156
+ end
157
+
158
+ context "capture" do
159
+ around(:each) do |spec|
160
+ @r = RinRuby.new
161
+ spec.run
162
+ @r.quit
163
+ end
164
+
165
+ it "captures output from the process into a variable" do
166
+ output = @r.capture do
167
+ @r.eval("1 + 1")
168
+ end
169
+ expect(output).to eq("[1] 2\n")
170
+ end
171
+ end
172
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ -f s
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
2
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
3
+ require 'rspec'
4
+ require 'rinruby'
5
+
6
+ require 'matrix'
7
+
8
+ RSpec.configure do |config|
9
+ config.expect_with :rspec do |c|
10
+ c.syntax = [:should, :expect]
11
+ end
12
+
13
+ # Use color in STDOUT
14
+ config.color = true
15
+
16
+ # Use color not only in STDOUT but also in pagers and files
17
+ config.tty = true
18
+
19
+ # Use the specified formatter
20
+ config.formatter = :documentation # :progress, :html, :textmate
21
+ end
22
+
23
+
24
+ class String
25
+ def deindent
26
+ gsub /^[ \t]*/, ''
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rootapp-rinruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ROOT devs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: |2
42
+ RinRuby is a Ruby library that integrates the R interpreter in Ruby, making
43
+ R's statistical routines and graphics available within Ruby. The library
44
+ consists of a single Ruby script that is simple to install and does not
45
+ require any special compilation or installation of R. Since the library is
46
+ 100% pure Ruby, it works on a variety of operating systems, Ruby
47
+ implementations, and versions of R. RinRuby's methods are simple, making for
48
+ readable code. The {website [rinruby.ddahl.org]}[http://rinruby.ddahl.org]
49
+ describes RinRuby usage, provides comprehensive documentation, gives several
50
+ examples, and discusses RinRuby's implementation.
51
+ email: devs@joinroot.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - ".gitignore"
57
+ - ".travis.yml"
58
+ - Gemfile
59
+ - Gemfile.lock
60
+ - History.txt
61
+ - LICENSE.txt
62
+ - Manifest.txt
63
+ - README.md
64
+ - Rakefile
65
+ - lib/rinruby.rb
66
+ - lib/rinruby/version.rb
67
+ - rootapp-rinruby.gemspec
68
+ - spec/rinruby_spec.rb
69
+ - spec/spec.opts
70
+ - spec/spec_helper.rb
71
+ homepage: https://github.com/Root-App/rinruby
72
+ licenses:
73
+ - GPLv3
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.8
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: RinRuby is a Ruby library that integrates the R interpreter in Ruby
95
+ test_files:
96
+ - spec/rinruby_spec.rb
97
+ - spec/spec.opts
98
+ - spec/spec_helper.rb