rbbt-util 5.21.116 → 5.21.118

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rbbt/util/R.rb +46 -24
  3. data/share/Rlib/util.R +14 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77c923c4547ab8c088116d35a69d5963d69c9288
4
- data.tar.gz: 1d770671abe5b42e35e7466239f3a20d68c54615
3
+ metadata.gz: 2f8aee25daf09bf8fc2ba570b13a284360a24cd9
4
+ data.tar.gz: 9f2699ac7bd7a9865592415e261b9fb22a54482d
5
5
  SHA512:
6
- metadata.gz: 435ffaa1be1e204fd0e98c4c7e0f8d3df28dffb79ca1acd0102d32d6078ff2d64d8a27cff3158ec4fd7034b2168b70b44df1cd511be46b582feeb48e95ca08b4
7
- data.tar.gz: '08612a841a790fcbd898133e21c47188c905cee765aa8db675464cef651f0c842986249a65192014953451f9fa16cae4c3108360b18f8830c2b7951913b34056'
6
+ metadata.gz: 834d30431b1a6405ff8632784dc234f1bba5c5da740c69ce3cfc5761a31d05f1ef7049b44fbf98d9da002c5f49f507a2b393382cc29c8512ff8394e7c4e5203c
7
+ data.tar.gz: 32c632ba951d339aafd7221c68ee121a5657592b2381f9c3df14876143c073a05a5a9e21399da202321ace0b578d5e54d51f1b56f99df37092d9ea7083b7b0b4
data/lib/rbbt/util/R.rb CHANGED
@@ -55,21 +55,38 @@ source('#{UTIL}');
55
55
  end
56
56
  end
57
57
 
58
- def self.interactive(script, options = {})
59
- TmpFile.with_file do |init_file|
60
- Open.write(init_file) do |f|
61
- f.puts "# Loading basic rbbt environment"
62
- f.puts "library(utils, quietly=TRUE);\n"
63
- f.puts "interactive.script.file = '#{init_file}'"
58
+ def self.interactive(script, source = [], options = {})
59
+ TmpFile.with_file(script) do |script_file|
60
+ TmpFile.with_file do |init_file|
64
61
 
65
- f.puts "source('#{R::UTIL}');\n"
66
- f.puts "rbbt.require('readr')"
67
- f.puts "interactive.script = read_file(interactive.script.file)"
68
- f.puts "cat(interactive.script)"
69
- f.puts ""
70
- f.puts script
71
- end
62
+ cmd = <<-EOF
63
+ # Loading basic rbbt environment"
64
+ library(utils, quietly=TRUE);
65
+ library(grDevices,quietly=TRUE)
66
+ source('#{R::UTIL}');
67
+ EOF
68
+
69
+ require_sources = source.collect{|source|
70
+ source = R::LIB_DIR["#{source.to_s}.R"] if R::LIB_DIR["#{source.to_s}.R"].exists?
71
+ "source('#{source}')"
72
+ } * ";\n" if Array === source and source.any?
73
+
74
+ cmd << require_sources + "\n\n" if require_sources
75
+
76
+ cmd += <<-EOF
77
+
78
+ rbbt.require('readr')
79
+ interactive.script.file = '#{script_file}'
80
+ interactive.script = read_file(interactive.script.file)
81
+
82
+ cat(interactive.script)
83
+
84
+ source(interactive.script.file)
85
+ EOF
86
+
87
+ Open.write init_file, cmd
72
88
  CMD.cmd("env R_PROFILE='#{init_file}' xterm \"$R_HOME/bin/R\"")
89
+ end
73
90
  end
74
91
  end
75
92
 
@@ -193,7 +210,6 @@ if (! is.null(data)){ rbbt.tsv.write('#{f}', data); }
193
210
  NULL
194
211
  EOF
195
212
 
196
-
197
213
  case r_options.delete :method
198
214
  when :eval
199
215
  R.eval_run script
@@ -213,16 +229,22 @@ NULL
213
229
  end
214
230
  end
215
231
 
216
- def R_interactive(pre_script = nil, source = true)
217
- TmpFile.with_file do |f|
218
- Log.debug{"R Interactive:\n" << pre_script } if pre_script
219
- TmpFile.with_file(pre_script) do |script_file|
220
- Open.write(f, self.to_s)
221
- script = "data_file = '#{f}';\n"
222
- script << "script_file = '#{script_file}';\n" if pre_script
223
- script << "source(script_file);\n" if source
224
- R.interactive(script)
225
- end
232
+ def R_interactive(script = nil, source = [])
233
+ TmpFile.with_file do |data_file|
234
+ Open.write(data_file, self.to_s)
235
+
236
+ Log.debug{"R Interactive:\n" << script } if script
237
+
238
+ script =<<-EOF
239
+ # Loading data
240
+ data_file = '#{data_file}'
241
+ data = rbbt.tsv(data_file)
242
+
243
+ # Script
244
+ #{script}
245
+ EOF
246
+
247
+ R.interactive(script)
226
248
  end
227
249
  end
228
250
 
data/share/Rlib/util.R CHANGED
@@ -440,9 +440,20 @@ rbbt.model.inpute <- function(data, formula, ...){
440
440
  data
441
441
  }
442
442
 
443
- rbbt.tsv.melt <- function(tsv, key_field = 'ID'){
444
- tsv[key_field] = rownames(tsv)
445
- return(melt(tsv))
443
+ rbbt.tsv.melt <- function(tsv, variable = NULL, value = NULL, key.field = NULL){
444
+ if (is.null(key.field)){ key.field = attributes(data)$key.field;}
445
+ if (is.null(key.field)){ key.field = "ID" }
446
+
447
+ if (is.null(variable)){ variable = "variable" }
448
+ if (is.null(value)){ value = "value" }
449
+
450
+ tsv[key.field] = rownames(tsv)
451
+
452
+ m <- melt(tsv)
453
+
454
+ names(m) <- c(key.field, variable, value)
455
+
456
+ return(m)
446
457
  }
447
458
 
448
459
  rbbt.ranks <- function(x){
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.21.116
4
+ version: 5.21.118
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez