rbbt-util 5.44.0 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbbt +67 -90
- data/etc/app.d/base.rb +3 -3
- data/etc/app.d/semaphores.rb +3 -3
- data/lib/rbbt/annotations/annotated_array.rb +207 -207
- data/lib/rbbt/annotations/refactor.rb +27 -0
- data/lib/rbbt/annotations/util.rb +282 -282
- data/lib/rbbt/annotations.rb +343 -320
- data/lib/rbbt/association/database.rb +200 -225
- data/lib/rbbt/association/index.rb +294 -291
- data/lib/rbbt/association/item.rb +227 -227
- data/lib/rbbt/association/open.rb +35 -34
- data/lib/rbbt/association/util.rb +0 -169
- data/lib/rbbt/association.rb +2 -4
- data/lib/rbbt/entity/identifiers.rb +119 -118
- data/lib/rbbt/entity/refactor.rb +12 -0
- data/lib/rbbt/entity.rb +319 -315
- data/lib/rbbt/hpc/batch.rb +72 -53
- data/lib/rbbt/hpc/lsf.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
- data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
- data/lib/rbbt/hpc/orchestrate.rb +19 -13
- data/lib/rbbt/hpc/slurm.rb +18 -18
- data/lib/rbbt/knowledge_base/entity.rb +13 -5
- data/lib/rbbt/knowledge_base/query.rb +2 -2
- data/lib/rbbt/knowledge_base/registry.rb +32 -31
- data/lib/rbbt/knowledge_base/traverse.rb +1 -1
- data/lib/rbbt/knowledge_base.rb +1 -1
- data/lib/rbbt/monitor.rb +36 -25
- data/lib/rbbt/persist/refactor.rb +166 -0
- data/lib/rbbt/persist/tsv/sharder.rb +1 -1
- data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
- data/lib/rbbt/persist/tsv.rb +187 -185
- data/lib/rbbt/persist.rb +556 -551
- data/lib/rbbt/refactor.rb +20 -0
- data/lib/rbbt/resource/path/refactor.rb +178 -0
- data/lib/rbbt/resource/path.rb +317 -497
- data/lib/rbbt/resource/util.rb +0 -48
- data/lib/rbbt/resource.rb +3 -390
- data/lib/rbbt/tsv/accessor.rb +2 -838
- data/lib/rbbt/tsv/attach.rb +303 -299
- data/lib/rbbt/tsv/change_id.rb +244 -245
- data/lib/rbbt/tsv/csv.rb +87 -85
- data/lib/rbbt/tsv/dumper.rb +2 -100
- data/lib/rbbt/tsv/excel.rb +26 -24
- data/lib/rbbt/tsv/field_index.rb +4 -1
- data/lib/rbbt/tsv/filter.rb +3 -2
- data/lib/rbbt/tsv/index.rb +2 -284
- data/lib/rbbt/tsv/manipulate.rb +750 -747
- data/lib/rbbt/tsv/marshal.rb +3 -3
- data/lib/rbbt/tsv/matrix.rb +2 -2
- data/lib/rbbt/tsv/parallel/through.rb +2 -1
- data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
- data/lib/rbbt/tsv/parser.rb +678 -678
- data/lib/rbbt/tsv/refactor.rb +195 -0
- data/lib/rbbt/tsv/stream.rb +253 -251
- data/lib/rbbt/tsv/util.rb +420 -420
- data/lib/rbbt/tsv.rb +210 -208
- data/lib/rbbt/util/R/eval.rb +4 -4
- data/lib/rbbt/util/R/plot.rb +62 -166
- data/lib/rbbt/util/R.rb +21 -18
- data/lib/rbbt/util/cmd.rb +2 -318
- data/lib/rbbt/util/color.rb +269 -269
- data/lib/rbbt/util/colorize.rb +89 -89
- data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
- data/lib/rbbt/util/concurrency/processes.rb +389 -386
- data/lib/rbbt/util/config.rb +169 -167
- data/lib/rbbt/util/iruby.rb +20 -0
- data/lib/rbbt/util/log/progress/report.rb +241 -241
- data/lib/rbbt/util/log/progress/util.rb +99 -99
- data/lib/rbbt/util/log/progress.rb +102 -102
- data/lib/rbbt/util/log/refactor.rb +49 -0
- data/lib/rbbt/util/log.rb +486 -532
- data/lib/rbbt/util/migrate.rb +1 -1
- data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
- data/lib/rbbt/util/misc/development.rb +12 -11
- data/lib/rbbt/util/misc/exceptions.rb +117 -112
- data/lib/rbbt/util/misc/format.rb +2 -230
- data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
- data/lib/rbbt/util/misc/inspect.rb +2 -476
- data/lib/rbbt/util/misc/lock.rb +109 -106
- data/lib/rbbt/util/misc/omics.rb +10 -1
- data/lib/rbbt/util/misc/pipes.rb +765 -793
- data/lib/rbbt/util/misc/refactor.rb +20 -0
- data/lib/rbbt/util/misc/ssw.rb +308 -0
- data/lib/rbbt/util/misc/system.rb +0 -15
- data/lib/rbbt/util/misc.rb +39 -20
- data/lib/rbbt/util/named_array/refactor.rb +4 -0
- data/lib/rbbt/util/named_array.rb +3 -220
- data/lib/rbbt/util/open/refactor.rb +7 -0
- data/lib/rbbt/util/open.rb +3 -857
- data/lib/rbbt/util/procpath.rb +6 -6
- data/lib/rbbt/util/python/paths.rb +27 -0
- data/lib/rbbt/util/python/run.rb +115 -0
- data/lib/rbbt/util/python/script.rb +110 -0
- data/lib/rbbt/util/python/util.rb +3 -3
- data/lib/rbbt/util/python.rb +22 -81
- data/lib/rbbt/util/semaphore.rb +152 -148
- data/lib/rbbt/util/simpleopt.rb +9 -8
- data/lib/rbbt/util/ssh/refactor.rb +19 -0
- data/lib/rbbt/util/ssh.rb +122 -118
- data/lib/rbbt/util/tar.rb +117 -115
- data/lib/rbbt/util/tmpfile.rb +69 -67
- data/lib/rbbt/util/version.rb +2 -0
- data/lib/rbbt/workflow/refactor/entity.rb +11 -0
- data/lib/rbbt/workflow/refactor/export.rb +66 -0
- data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
- data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
- data/lib/rbbt/workflow/refactor/task_info.rb +65 -0
- data/lib/rbbt/workflow/refactor.rb +153 -0
- data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
- data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
- data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
- data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
- data/lib/rbbt/workflow/remote_workflow.rb +6 -1
- data/lib/rbbt/workflow/step/info.rb +2 -2
- data/lib/rbbt/workflow/step/run.rb +766 -766
- data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
- data/lib/rbbt/workflow/step.rb +2 -362
- data/lib/rbbt/workflow/task.rb +118 -118
- data/lib/rbbt/workflow/usage.rb +289 -287
- data/lib/rbbt/workflow/util/archive.rb +6 -5
- data/lib/rbbt/workflow/util/data.rb +1 -1
- data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
- data/lib/rbbt/workflow/util/trace.rb +79 -44
- data/lib/rbbt/workflow.rb +4 -882
- data/lib/rbbt-util.rb +21 -13
- data/lib/rbbt.rb +16 -3
- data/python/rbbt/__init__.py +19 -1
- data/share/Rlib/plot.R +37 -37
- data/share/Rlib/svg.R +22 -5
- data/share/install/software/lib/install_helpers +1 -1
- data/share/rbbt_commands/hpc/list +2 -3
- data/share/rbbt_commands/hpc/orchestrate +4 -4
- data/share/rbbt_commands/hpc/tail +2 -0
- data/share/rbbt_commands/hpc/task +10 -7
- data/share/rbbt_commands/lsf/list +2 -3
- data/share/rbbt_commands/lsf/orchestrate +4 -4
- data/share/rbbt_commands/lsf/tail +2 -0
- data/share/rbbt_commands/lsf/task +10 -7
- data/share/rbbt_commands/migrate +1 -1
- data/share/rbbt_commands/pbs/list +2 -3
- data/share/rbbt_commands/pbs/orchestrate +4 -4
- data/share/rbbt_commands/pbs/tail +2 -0
- data/share/rbbt_commands/pbs/task +10 -7
- data/share/rbbt_commands/resource/produce +8 -1
- data/share/rbbt_commands/slurm/list +2 -3
- data/share/rbbt_commands/slurm/orchestrate +4 -4
- data/share/rbbt_commands/slurm/tail +2 -0
- data/share/rbbt_commands/slurm/task +10 -7
- data/share/rbbt_commands/system/clean +5 -5
- data/share/rbbt_commands/system/status +5 -5
- data/share/rbbt_commands/tsv/get +2 -3
- data/share/rbbt_commands/tsv/info +10 -13
- data/share/rbbt_commands/tsv/keys +18 -14
- data/share/rbbt_commands/tsv/slice +2 -2
- data/share/rbbt_commands/tsv/transpose +6 -2
- data/share/rbbt_commands/workflow/info +20 -24
- data/share/rbbt_commands/workflow/list +1 -1
- data/share/rbbt_commands/workflow/prov +20 -13
- data/share/rbbt_commands/workflow/server +16 -1
- data/share/rbbt_commands/workflow/task +76 -71
- data/share/rbbt_commands/workflow/write_info +26 -9
- data/share/software/opt/ssw/ssw.c +861 -0
- data/share/software/opt/ssw/ssw.h +130 -0
- data/share/workflow_config.ru +3 -3
- metadata +42 -3
data/lib/rbbt/util/R/plot.rb
CHANGED
@@ -1,4 +1,40 @@
|
|
1
1
|
module R
|
2
|
+
def self.field_classes(data)
|
3
|
+
field_samples = [nil] * data.fields.length
|
4
|
+
|
5
|
+
data.each do |k,vs|
|
6
|
+
vs = [vs] unless Array === vs
|
7
|
+
vs.each_with_index do |v,i|
|
8
|
+
if ! (v.nil? || v == "NA" || v == "")
|
9
|
+
field_samples[i] = v
|
10
|
+
end
|
11
|
+
end
|
12
|
+
break unless field_samples.include?(nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
field_samples.collect do |v|
|
16
|
+
v = v.first if Array === v
|
17
|
+
case v
|
18
|
+
when FalseClass, TrueClass
|
19
|
+
"'logical'"
|
20
|
+
when Numeric
|
21
|
+
"'numeric'"
|
22
|
+
when String
|
23
|
+
if v.strip =~ /^[-+]?[\d\.]+$/
|
24
|
+
"'numeric'"
|
25
|
+
else
|
26
|
+
"'character'"
|
27
|
+
end
|
28
|
+
when Time
|
29
|
+
"'Date'"
|
30
|
+
when Symbol
|
31
|
+
"'factor'"
|
32
|
+
else
|
33
|
+
"NA"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
2
38
|
module SVG
|
3
39
|
|
4
40
|
def self.plot(filename, data = nil, script = nil, width = nil, height = nil, options = {}, &block)
|
@@ -43,35 +79,11 @@ module R
|
|
43
79
|
script << "\n" << s.read
|
44
80
|
end
|
45
81
|
sources = [:plot, options[:source]].flatten.compact
|
46
|
-
|
82
|
+
|
83
|
+
field_classes = options[:field_classes]
|
84
|
+
|
47
85
|
if data
|
48
|
-
data
|
49
|
-
v = Array === v ? v : [v]
|
50
|
-
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
51
|
-
values = v
|
52
|
-
break
|
53
|
-
end
|
54
|
-
|
55
|
-
values = [values] unless values.nil? or Array === values
|
56
|
-
|
57
|
-
field_classes = values.collect do |v|
|
58
|
-
case v
|
59
|
-
when FalseClass, TrueClass
|
60
|
-
"'logical'"
|
61
|
-
when Numeric
|
62
|
-
"'numeric'"
|
63
|
-
when String
|
64
|
-
if v.strip =~ /^[-+]?[\d\.]+$/
|
65
|
-
"'numeric'"
|
66
|
-
else
|
67
|
-
"'character'"
|
68
|
-
end
|
69
|
-
when Symbol
|
70
|
-
"'factor'"
|
71
|
-
else
|
72
|
-
":NA"
|
73
|
-
end
|
74
|
-
end
|
86
|
+
field_classes = R.field_classes(data) if field_classes.nil?
|
75
87
|
|
76
88
|
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')' if field_classes.any?
|
77
89
|
|
@@ -91,8 +103,8 @@ module R
|
|
91
103
|
end
|
92
104
|
|
93
105
|
def self.ggplot(data, script = nil, width = nil, height = nil, options = {})
|
94
|
-
width ||=
|
95
|
-
height ||=
|
106
|
+
width ||= 2
|
107
|
+
height ||= 2
|
96
108
|
values = []
|
97
109
|
|
98
110
|
options = options.dup
|
@@ -100,6 +112,8 @@ module R
|
|
100
112
|
sources = [:plot, :svg, options[:source]].flatten.compact
|
101
113
|
options.delete :source
|
102
114
|
|
115
|
+
entity_geom = options.delete :entity_geom
|
116
|
+
|
103
117
|
field_classes = options[:field_classes]
|
104
118
|
|
105
119
|
fast = options[:fast]
|
@@ -111,35 +125,8 @@ module R
|
|
111
125
|
end
|
112
126
|
|
113
127
|
if data
|
114
|
-
|
115
|
-
|
116
|
-
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
117
|
-
values = v
|
118
|
-
break
|
119
|
-
end
|
120
|
-
values = [values] unless Array === values
|
121
|
-
|
122
|
-
field_classes = values.collect do |v|
|
123
|
-
v = v.first if Array === v
|
124
|
-
case v
|
125
|
-
when FalseClass, TrueClass
|
126
|
-
"'logical'"
|
127
|
-
when Numeric
|
128
|
-
"'numeric'"
|
129
|
-
when String
|
130
|
-
if v.strip =~ /^[-+]?[\d\.]+$/
|
131
|
-
"'numeric'"
|
132
|
-
else
|
133
|
-
"'character'"
|
134
|
-
end
|
135
|
-
when Time
|
136
|
-
"'Date'"
|
137
|
-
when Symbol
|
138
|
-
"'factor'"
|
139
|
-
else
|
140
|
-
":NA"
|
141
|
-
end
|
142
|
-
end if field_classes.nil?
|
128
|
+
|
129
|
+
field_classes = R.field_classes(data) if field_classes.nil?
|
143
130
|
|
144
131
|
if field_classes.any?
|
145
132
|
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')'
|
@@ -149,15 +136,22 @@ module R
|
|
149
136
|
|
150
137
|
TmpFile.with_file nil, true, :extension => 'svg' do |tmpfile|
|
151
138
|
|
152
|
-
|
139
|
+
if entity_geom
|
140
|
+
data.R <<-EOF, sources, options
|
141
|
+
plot = { #{script} }
|
142
|
+
#{save_method}('#{tmpfile}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height}, entity.geom=#{R.ruby2R(entity_geom)}, data=data)
|
143
|
+
data = NULL
|
144
|
+
EOF
|
145
|
+
else
|
146
|
+
data.R <<-EOF, sources, options
|
153
147
|
plot = { #{script} }
|
154
148
|
|
155
149
|
#{save_method}('#{tmpfile}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height})
|
156
150
|
data = NULL
|
157
|
-
|
151
|
+
EOF
|
152
|
+
end
|
158
153
|
|
159
154
|
Open.read(tmpfile).gsub(/(glyph\d+-\d+)/, '\1-' + File.basename(tmpfile))
|
160
|
-
|
161
155
|
end
|
162
156
|
else
|
163
157
|
|
@@ -201,31 +195,8 @@ module R
|
|
201
195
|
|
202
196
|
sources = [:plot, options[:source]].flatten.compact
|
203
197
|
|
204
|
-
data
|
205
|
-
|
206
|
-
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
207
|
-
values = v
|
208
|
-
break
|
209
|
-
end
|
210
|
-
values = [values] unless Array === values
|
211
|
-
field_classes = values.collect do |v|
|
212
|
-
case v
|
213
|
-
when FalseClass, TrueClass
|
214
|
-
"'logical'"
|
215
|
-
when Numeric
|
216
|
-
"'numeric'"
|
217
|
-
when String
|
218
|
-
if v.strip =~ /^[-+]?[\d\.]+$/
|
219
|
-
"'numeric'"
|
220
|
-
else
|
221
|
-
"'character'"
|
222
|
-
end
|
223
|
-
when Symbol
|
224
|
-
"'factor'"
|
225
|
-
else
|
226
|
-
":NA"
|
227
|
-
end
|
228
|
-
end
|
198
|
+
field_classes = R.field_classes(data) if field_classes.nil?
|
199
|
+
|
229
200
|
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')'
|
230
201
|
|
231
202
|
data.R <<-EOF, :plot, options
|
@@ -281,33 +252,7 @@ data = NULL
|
|
281
252
|
sources = [:plot, options[:source]].flatten.compact
|
282
253
|
|
283
254
|
if data
|
284
|
-
data
|
285
|
-
v = Array === v ? v : [v]
|
286
|
-
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
287
|
-
values = v
|
288
|
-
break
|
289
|
-
end
|
290
|
-
|
291
|
-
values = [values] unless values.nil? or Array === values
|
292
|
-
|
293
|
-
field_classes = values.collect do |v|
|
294
|
-
case v
|
295
|
-
when FalseClass, TrueClass
|
296
|
-
"'logical'"
|
297
|
-
when Numeric
|
298
|
-
"'numeric'"
|
299
|
-
when String
|
300
|
-
if v.strip =~ /^[-+]?[\d\.]+$/
|
301
|
-
"'numeric'"
|
302
|
-
else
|
303
|
-
"'character'"
|
304
|
-
end
|
305
|
-
when Symbol
|
306
|
-
"'factor'"
|
307
|
-
else
|
308
|
-
":NA"
|
309
|
-
end
|
310
|
-
end
|
255
|
+
field_classes = R.field_classes(data) if field_classes.nil?
|
311
256
|
|
312
257
|
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')' if field_classes.any?
|
313
258
|
|
@@ -347,31 +292,8 @@ data = NULL
|
|
347
292
|
|
348
293
|
sources = [:plot, options[:source]].flatten.compact
|
349
294
|
|
350
|
-
data
|
351
|
-
|
352
|
-
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
353
|
-
values = v
|
354
|
-
break
|
355
|
-
end
|
356
|
-
values = [values] unless Array === values
|
357
|
-
field_classes = values.collect do |v|
|
358
|
-
case v
|
359
|
-
when FalseClass, TrueClass
|
360
|
-
"'logical'"
|
361
|
-
when Numeric
|
362
|
-
"'numeric'"
|
363
|
-
when String
|
364
|
-
if v.strip =~ /^[-+]?[\d\.]+$/
|
365
|
-
"'numeric'"
|
366
|
-
else
|
367
|
-
"'character'"
|
368
|
-
end
|
369
|
-
when Symbol
|
370
|
-
"'factor'"
|
371
|
-
else
|
372
|
-
":NA"
|
373
|
-
end
|
374
|
-
end
|
295
|
+
field_classes = R.field_classes(data) if field_classes.nil?
|
296
|
+
|
375
297
|
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')'
|
376
298
|
|
377
299
|
delay = options[:delay]
|
@@ -445,33 +367,7 @@ data = NULL
|
|
445
367
|
frames = (1..frames).to_a if Integer === frames
|
446
368
|
|
447
369
|
if data
|
448
|
-
data
|
449
|
-
v = Array === v ? v : [v]
|
450
|
-
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
451
|
-
values = v
|
452
|
-
break
|
453
|
-
end
|
454
|
-
|
455
|
-
values = [values] unless values.nil? or Array === values
|
456
|
-
|
457
|
-
field_classes = values.collect do |v|
|
458
|
-
case v
|
459
|
-
when FalseClass, TrueClass
|
460
|
-
"'logical'"
|
461
|
-
when Numeric
|
462
|
-
"'numeric'"
|
463
|
-
when String
|
464
|
-
if v.strip =~ /^[-+]?[\d\.]+$/
|
465
|
-
"'numeric'"
|
466
|
-
else
|
467
|
-
"'character'"
|
468
|
-
end
|
469
|
-
when Symbol
|
470
|
-
"'factor'"
|
471
|
-
else
|
472
|
-
":NA"
|
473
|
-
end
|
474
|
-
end
|
370
|
+
field_classes = R.field_classes(data) if field_classes.nil?
|
475
371
|
|
476
372
|
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')' if field_classes.any?
|
477
373
|
|
data/lib/rbbt/util/R.rb
CHANGED
@@ -109,17 +109,17 @@ source(interactive.script.file)
|
|
109
109
|
begin
|
110
110
|
Process.waitpid pid
|
111
111
|
rescue Interrupt
|
112
|
-
if Misc.
|
112
|
+
if Misc.pid_alive? pid
|
113
113
|
Process.kill "INT", pid
|
114
114
|
retry
|
115
115
|
else
|
116
116
|
raise $!
|
117
117
|
end
|
118
118
|
rescue Exception
|
119
|
-
Process.kill 9, pid if Misc.
|
119
|
+
Process.kill 9, pid if Misc.pid_alive? pid
|
120
120
|
raise $!
|
121
121
|
ensure
|
122
|
-
Process.waitpid pid if Misc.
|
122
|
+
Process.waitpid pid if Misc.pid_alive? pid
|
123
123
|
end
|
124
124
|
|
125
125
|
end
|
@@ -138,6 +138,7 @@ source(interactive.script.file)
|
|
138
138
|
when Symbol
|
139
139
|
"#{ object }"
|
140
140
|
when String
|
141
|
+
object = object.dup if Path === object
|
141
142
|
object[0] == ":" ? object[1..-1] : "'#{ object }'"
|
142
143
|
when Numeric
|
143
144
|
object
|
@@ -161,8 +162,8 @@ source(interactive.script.file)
|
|
161
162
|
end
|
162
163
|
|
163
164
|
def self.tsv(file, options = {})
|
164
|
-
options =
|
165
|
-
key_field =
|
165
|
+
options = IndiferentHash.add_defaults :header_hash => '', :sep => / +/, :type => :list, :key_field => 'ID'
|
166
|
+
key_field = IndiferentHash.process_options options, :key_field
|
166
167
|
clean = CMD.cmd('grep -v WARNING', :in => file, :pipe => true)
|
167
168
|
TSV.open(clean, options).tap{|tsv| tsv.key_field = key_field }
|
168
169
|
end
|
@@ -170,10 +171,10 @@ end
|
|
170
171
|
|
171
172
|
module TSV
|
172
173
|
|
173
|
-
def R(script, source = nil,
|
174
|
-
|
174
|
+
def R(script, source = nil, options = {})
|
175
|
+
options, source = source, nil if Hash === source
|
175
176
|
|
176
|
-
source ||=
|
177
|
+
source ||= IndiferentHash.process_options options, :source
|
177
178
|
source = [source] unless Array === source
|
178
179
|
|
179
180
|
require_sources = source.collect{|source|
|
@@ -183,25 +184,27 @@ module TSV
|
|
183
184
|
|
184
185
|
script = require_sources + "\n\n" + script if require_sources
|
185
186
|
|
186
|
-
r_options =
|
187
|
+
r_options = IndiferentHash.pull_keys options, :R
|
188
|
+
open_options = IndiferentHash.pull_keys options, :open
|
187
189
|
|
188
|
-
r_options[:monitor] =
|
189
|
-
r_options[:method] =
|
190
|
-
r_options[:debug] =
|
190
|
+
r_options[:monitor] = options[:monitor] if options.include?(:monitor)
|
191
|
+
r_options[:method] = options[:method] if options.include?(:method)
|
192
|
+
r_options[:debug] = options[:debug] if options.include?(:debug)
|
193
|
+
r_options[:erase] = options.delete(:erase) if options.include?(:erase)
|
191
194
|
|
192
195
|
r_options[:debug] = true if r_options[:method] == :debug
|
193
196
|
if r_options.delete :debug
|
194
197
|
r_options[:monitor] = true
|
195
198
|
r_options[:method] = :shell
|
196
|
-
erase = false
|
199
|
+
erase = r_options.include?(:erase) ? r_options[:erase] : false
|
197
200
|
else
|
198
|
-
erase = true
|
201
|
+
erase = r_options.include?(:erase) ? r_options[:erase] : true
|
199
202
|
end
|
200
203
|
|
201
204
|
tsv_R_option_str = r_options.delete :open
|
202
205
|
tsv_R_option_str = ", " + tsv_R_option_str if String === tsv_R_option_str and not tsv_R_option_str.empty?
|
203
206
|
|
204
|
-
raw =
|
207
|
+
raw = options.delete :raw
|
205
208
|
TmpFile.with_file nil, erase do |f|
|
206
209
|
Open.write(f, self.to_s)
|
207
210
|
|
@@ -223,12 +226,12 @@ NULL
|
|
223
226
|
R.run script, r_options
|
224
227
|
end
|
225
228
|
|
226
|
-
open_options =
|
229
|
+
open_options = IndiferentHash.add_defaults open_options, :type => :list
|
227
230
|
if raw
|
228
231
|
Open.read(f)
|
229
232
|
else
|
230
|
-
tsv = TSV.open(f, open_options) unless
|
231
|
-
tsv.key_field =
|
233
|
+
tsv = TSV.open(f, open_options) unless options[:ignore_output]
|
234
|
+
tsv.key_field = options[:key] if options.include? :key
|
232
235
|
tsv.namespace ||= self.namespace if self.namespace
|
233
236
|
tsv
|
234
237
|
end
|