Module: Rust
- Defined in:
- lib/rust/core/csv.rb,
lib/rust/core/rust.rb,
lib/rust/models/anova.rb,
lib/rust/core/types/list.rb,
lib/rust/core/types/utils.rb,
lib/rust/core/types/factor.rb,
lib/rust/core/types/matrix.rb,
lib/rust/core/types/s4class.rb,
lib/rust/core/types/datatype.rb,
lib/rust/core/types/language.rb,
lib/rust/stats/probabilities.rb,
lib/rust/core/types/dataframe.rb
Defined Under Namespace
Modules: Correlation, Descriptive, EffectSize, Models, Plots, Probabilities, RBindings, StatisticalTests, TestCases
Classes: ANOVAModel, Arguments, CSV, Call, DataFrame, DataFrameArray, DataFrameHash, Environment, Factor, FactorValue, Formula, Function, List, MathArray, Matrix, Null, Options, RandomVariable, RandomVariableSlice, RustDatatype, S4Class, Sequence, SimpleFormula, UniformRandomVariable, Variable
Constant Summary
collapse
- @@debugging =
$RUST_DEBUG || false
- @@in_client_mutex =
false
Class Method Summary
collapse
Class Method Details
.[]=(variable, value) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rust/core/rust.rb', line 36
def self.[]=(variable, value)
if value.is_a?(RustDatatype)
value.load_in_r_as(variable.to_s)
elsif value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(Array) || value.is_a?(::Matrix)
R_ENGINE.assign(variable, value)
else
raise "Trying to assign #{variable} with #{value.class}; expected RustDatatype, String, Numeric, or Array"
end
end
|
._eval(r_command, return_warnings = false) ⇒ Object
76
77
78
|
# File 'lib/rust/core/rust.rb', line 76
def self._eval(r_command, return_warnings = false)
self._rexec(r_command, return_warnings) { |cmd| R_ENGINE.eval(cmd) }
end
|
._eval_big(r_command, return_warnings = false) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/rust/core/rust.rb', line 51
def self._eval_big(r_command, return_warnings = false)
r_command = r_command.join("\n") if r_command.is_a?(Array)
self._rexec(r_command, return_warnings) do |cmd|
result = true
instructions = cmd.lines
while instructions.size > 0
current_command = ""
while (instructions.size > 0) && (current_command.length + instructions.first.length < 10000)
current_command << instructions.shift
end
result &= R_ENGINE.eval(current_command)
end
result
end
end
|
._pull(r_command, return_warnings = false) ⇒ Object
72
73
74
|
# File 'lib/rust/core/rust.rb', line 72
def self._pull(r_command, return_warnings = false)
self._rexec(r_command, return_warnings) { |cmd| R_ENGINE.pull(cmd) }
end
|
._rexec(r_command, return_warnings = false) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/rust/core/rust.rb', line 80
def self._rexec(r_command, return_warnings = false)
puts "Calling _rexec with command: #{r_command}" if @@debugging
R_MUTEX.synchronize do
assert("This command must be executed in an exclusive block") { @@in_client_mutex }
result = nil
begin
$stdout = StringIO.new
if return_warnings
R_ENGINE.echo(true, true)
else
R_ENGINE.echo(false, false)
end
result = yield(r_command)
ensure
R_ENGINE.echo(false, false)
warnings = $stdout.string
$stdout = STDOUT
end
if return_warnings
puts " Got #{warnings.size} warnings, with result #{result.inspect[0...100]}" if @@debugging
return result, warnings.lines.map { |w| w.strip.chomp }
else
puts " Result: #{result.inspect[0...100]}" if @@debugging
return result
end
end
end
|
.check_library(name) ⇒ Object
110
111
112
113
114
115
|
# File 'lib/rust/core/rust.rb', line 110
def self.check_library(name)
self.exclusive do
result, _ = self._pull("require(\"#{name}\", character.only = TRUE)", true)
return result
end
end
|
18
19
20
|
# File 'lib/rust/core/rust.rb', line 18
def self.debug
@@debugging = true
end
|
.debug? ⇒ Boolean
22
23
24
|
# File 'lib/rust/core/rust.rb', line 22
def self.debug?
return @@debugging
end
|
.exclusive ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/rust/core/rust.rb', line 26
def self.exclusive
result = nil
CLIENT_MUTEX.synchronize do
@@in_client_mutex = true
result = yield
@@in_client_mutex = false
end
return result
end
|
.install_library(name) ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/rust/core/rust.rb', line 125
def self.install_library(name)
self.exclusive do
self._eval("install.packages(\"#{name}\", dependencies = TRUE)")
end
return nil
end
|
.load_library(name) ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/rust/core/rust.rb', line 117
def self.load_library(name)
self.exclusive do
self._eval("library(\"#{name}\", character.only = TRUE)")
end
return nil
end
|
.prerequisite(library) ⇒ Object
133
134
135
136
|
# File 'lib/rust/core/rust.rb', line 133
def self.prerequisite(library)
self.install_library(library) unless self.check_library(library)
self.load_library(library)
end
|