simpler 0.0.3 → 0.0.4
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.
- data/VERSION +1 -1
- data/lib/simpler.rb +22 -1
- data/spec/simpler_spec.rb +11 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/simpler.rb
CHANGED
@@ -55,17 +55,35 @@ class Simpler
|
|
55
55
|
reply
|
56
56
|
end
|
57
57
|
|
58
|
+
def error_message(error_string, r_code)
|
59
|
+
error_message = ""
|
60
|
+
error_message << "\n"
|
61
|
+
error_message << "*************************** Error inside R *****************************\n"
|
62
|
+
error_message << error_string
|
63
|
+
error_message << "------------------------- [R code submitted] ---------------------------\n"
|
64
|
+
error_message << r_code
|
65
|
+
error_message << "------------------------------------------------------------------------\n"
|
66
|
+
error_message
|
67
|
+
end
|
68
|
+
|
69
|
+
|
58
70
|
# pushes string onto command array (if given), executes all commands, and
|
59
71
|
# clears the command array.
|
60
72
|
def run!(string=nil)
|
61
73
|
@commands.push(string) if string
|
62
74
|
reply = nil
|
75
|
+
error = nil
|
76
|
+
cmds_to_run = @commands.map {|v| v + "\n"}.join
|
63
77
|
Open3.popen3("Rscript -") do |stdin, stdout, stderr|
|
64
|
-
stdin.puts
|
78
|
+
stdin.puts cmds_to_run
|
65
79
|
stdin.close_write
|
80
|
+
error = stderr.read
|
66
81
|
reply = stdout.read
|
67
82
|
end
|
68
83
|
@commands.clear
|
84
|
+
if error.size > 0
|
85
|
+
raise Simpler::RError, error_message(error, cmds_to_run)
|
86
|
+
end
|
69
87
|
Simpler::Reply.new(reply)
|
70
88
|
end
|
71
89
|
|
@@ -88,4 +106,7 @@ class Simpler
|
|
88
106
|
|
89
107
|
alias_method :go!, :run_with!
|
90
108
|
|
109
|
+
class RError < StandardError
|
110
|
+
end
|
111
|
+
|
91
112
|
end
|
data/spec/simpler_spec.rb
CHANGED
@@ -20,6 +20,17 @@ describe "Simpler" do
|
|
20
20
|
reply.chomp.is "[1] 1.25"
|
21
21
|
end
|
22
22
|
|
23
|
+
it 'raises a useful Simpler::RError on an R error and shows the submitted R code' do
|
24
|
+
code_matches = { "mean(unnamed_variable)" => %r{Error in mean.*: object .* not found},
|
25
|
+
"plsdf()" => %r{could not find function},
|
26
|
+
"plot(c(1,2), c(2))" => %r{'x' and 'y' lengths differ},
|
27
|
+
}
|
28
|
+
code_matches.each do |code, matches|
|
29
|
+
message = lambda { @r.run!(code) }.should.raise(Simpler::RError).message
|
30
|
+
message.should.match(matches)
|
31
|
+
message.should.include code
|
32
|
+
end
|
33
|
+
end
|
23
34
|
end
|
24
35
|
|
25
36
|
describe 'making data frames' do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Prince
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-13 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|