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.
- checksums.yaml +4 -4
- data/lib/rbbt/util/R.rb +46 -24
- data/share/Rlib/util.R +14 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f8aee25daf09bf8fc2ba570b13a284360a24cd9
|
4
|
+
data.tar.gz: 9f2699ac7bd7a9865592415e261b9fb22a54482d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 |
|
60
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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(
|
217
|
-
TmpFile.with_file do |
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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,
|
444
|
-
|
445
|
-
|
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){
|