rust 0.3 → 0.9
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.
- checksums.yaml +4 -4
- data/bin/ruby-rust +3 -0
- data/lib/{rust-csv.rb → rust/core/csv.rb} +14 -4
- data/lib/rust/core/rust.rb +157 -0
- data/lib/rust/core/types/all.rb +4 -0
- data/lib/{rust-core.rb → rust/core/types/dataframe.rb} +183 -245
- data/lib/rust/core/types/datatype.rb +161 -0
- data/lib/rust/core/types/factor.rb +131 -0
- data/lib/rust/core/types/language.rb +166 -0
- data/lib/rust/core/types/list.rb +81 -0
- data/lib/rust/core/types/matrix.rb +132 -0
- data/lib/rust/core/types/s4class.rb +59 -0
- data/lib/rust/core/types/utils.rb +109 -0
- data/lib/rust/core.rb +7 -0
- data/lib/rust/models/all.rb +4 -0
- data/lib/rust/models/anova.rb +60 -0
- data/lib/rust/models/regression.rb +205 -0
- data/lib/rust/plots/all.rb +4 -0
- data/lib/rust/plots/basic-plots.rb +111 -0
- data/lib/{rust-plots.rb → rust/plots/core.rb} +64 -129
- data/lib/rust/plots/distribution-plots.rb +62 -0
- data/lib/rust/stats/all.rb +4 -0
- data/lib/{rust-basics.rb → rust/stats/correlation.rb} +11 -5
- data/lib/rust/stats/descriptive.rb +128 -0
- data/lib/{rust-effsize.rb → rust/stats/effsize.rb} +23 -21
- data/lib/rust/stats/probabilities.rb +248 -0
- data/lib/rust/stats/tests.rb +292 -0
- data/lib/rust.rb +4 -8
- metadata +31 -12
- data/lib/rust-calls.rb +0 -69
- data/lib/rust-descriptive.rb +0 -59
- data/lib/rust-tests.rb +0 -165
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaa404db11033ff42b529516ae4a3f3e252bdddf7677d082847ee06625144f8e
|
4
|
+
data.tar.gz: f72ebc2c95385b87a445f3fb8de3e517579b002e0606209903acd2327616befd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00567c9b6216f7e9dc1a4135dbea263eecae2178273851c023980233531729313e15147e1bec8e9521df2d4fee15e2c4c8bf9bd4a0e2d1475f1d383339a17c21
|
7
|
+
data.tar.gz: 89800fff95be559e6f6bbbc05b6b5f5b52b7d59c54c61cd76ef679876ce5de0c08b405d88eadf0b254c95306ad98f38120e5960a92ce8358fca19ed6cc5c181d
|
data/bin/ruby-rust
ADDED
@@ -1,9 +1,10 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../core'
|
2
|
+
require 'csv'
|
2
3
|
|
3
4
|
module Rust
|
4
5
|
class CSV
|
5
6
|
def self.read_all(pattern, **options)
|
6
|
-
result =
|
7
|
+
result = DataFrameHash.new
|
7
8
|
Dir.glob(pattern).each do |filename|
|
8
9
|
result[filename] = CSV.read(filename, **options)
|
9
10
|
end
|
@@ -49,10 +50,9 @@ module Rust
|
|
49
50
|
raise TypeError, "Expected Rust::DataFrame" unless dataframe.is_a?(Rust::DataFrame)
|
50
51
|
|
51
52
|
write_headers = options[:headers] != false
|
52
|
-
options[:headers] = dataframe.column_names
|
53
|
+
options[:headers] = dataframe.column_names unless options[:headers]
|
53
54
|
|
54
55
|
hash = {}
|
55
|
-
labels = nil
|
56
56
|
::CSV.open(filename, 'w', write_headers: write_headers, **options) do |csv|
|
57
57
|
dataframe.each do |row|
|
58
58
|
csv << row
|
@@ -93,3 +93,13 @@ module Rust
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
module Rust::RBindings
|
98
|
+
def read_csv(filename, **options)
|
99
|
+
Rust::CSV.read(filename, **options)
|
100
|
+
end
|
101
|
+
|
102
|
+
def write_csv(filename, dataframe, **options)
|
103
|
+
Rust::CSV.write(filename, dataframe, **options)
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'code-assertions'
|
2
|
+
require 'stringio'
|
3
|
+
require 'rinruby'
|
4
|
+
|
5
|
+
module Rust
|
6
|
+
CLIENT_MUTEX = Mutex.new
|
7
|
+
R_MUTEX = Mutex.new
|
8
|
+
|
9
|
+
R_ENGINE = RinRuby.new(echo: false)
|
10
|
+
|
11
|
+
private_constant :R_ENGINE
|
12
|
+
private_constant :R_MUTEX
|
13
|
+
private_constant :CLIENT_MUTEX
|
14
|
+
|
15
|
+
@@debugging = $RUST_DEBUG || false
|
16
|
+
@@in_client_mutex = false
|
17
|
+
|
18
|
+
def self.debug
|
19
|
+
@@debugging = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.debug?
|
23
|
+
return @@debugging
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.exclusive
|
27
|
+
result = nil
|
28
|
+
CLIENT_MUTEX.synchronize do
|
29
|
+
@@in_client_mutex = true
|
30
|
+
result = yield
|
31
|
+
@@in_client_mutex = false
|
32
|
+
end
|
33
|
+
return result
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.[]=(variable, value)
|
37
|
+
if value.is_a?(RustDatatype)
|
38
|
+
value.load_in_r_as(variable.to_s)
|
39
|
+
elsif value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(Array) || value.is_a?(::Matrix)
|
40
|
+
R_ENGINE.assign(variable, value)
|
41
|
+
else
|
42
|
+
raise "Trying to assign #{variable} with #{value.class}; expected RustDatatype, String, Numeric, or Array"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.[](variable)
|
48
|
+
return RustDatatype.pull_variable(variable)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self._eval_big(r_command, return_warnings = false)
|
52
|
+
r_command = r_command.join("\n") if r_command.is_a?(Array)
|
53
|
+
|
54
|
+
self._rexec(r_command, return_warnings) do |cmd|
|
55
|
+
result = true
|
56
|
+
instructions = cmd.lines
|
57
|
+
|
58
|
+
while instructions.size > 0
|
59
|
+
current_command = ""
|
60
|
+
|
61
|
+
while (instructions.size > 0) && (current_command.length + instructions.first.length < 10000)
|
62
|
+
current_command << instructions.shift
|
63
|
+
end
|
64
|
+
|
65
|
+
result &= R_ENGINE.eval(current_command)
|
66
|
+
end
|
67
|
+
|
68
|
+
result
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self._pull(r_command, return_warnings = false)
|
73
|
+
self._rexec(r_command, return_warnings) { |cmd| R_ENGINE.pull(cmd) }
|
74
|
+
end
|
75
|
+
|
76
|
+
def self._eval(r_command, return_warnings = false)
|
77
|
+
self._rexec(r_command, return_warnings) { |cmd| R_ENGINE.eval(cmd) }
|
78
|
+
end
|
79
|
+
|
80
|
+
def self._rexec(r_command, return_warnings = false)
|
81
|
+
puts "Calling _rexec with command: #{r_command}" if @@debugging
|
82
|
+
R_MUTEX.synchronize do
|
83
|
+
assert("This command must be executed in an exclusive block") { @@in_client_mutex }
|
84
|
+
|
85
|
+
result = nil
|
86
|
+
begin
|
87
|
+
$stdout = StringIO.new
|
88
|
+
if return_warnings
|
89
|
+
R_ENGINE.echo(true, true)
|
90
|
+
else
|
91
|
+
R_ENGINE.echo(false, false)
|
92
|
+
end
|
93
|
+
result = yield(r_command)
|
94
|
+
ensure
|
95
|
+
R_ENGINE.echo(false, false)
|
96
|
+
warnings = $stdout.string
|
97
|
+
$stdout = STDOUT
|
98
|
+
end
|
99
|
+
|
100
|
+
if return_warnings
|
101
|
+
puts " Got #{warnings.size} warnings, with result #{result.inspect[0...100]}" if @@debugging
|
102
|
+
return result, warnings.lines.map { |w| w.strip.chomp }
|
103
|
+
else
|
104
|
+
puts " Result: #{result.inspect[0...100]}" if @@debugging
|
105
|
+
return result
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.check_library(name)
|
111
|
+
self.exclusive do
|
112
|
+
result, _ = self._pull("require(\"#{name}\", character.only = TRUE)", true)
|
113
|
+
return result
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.load_library(name)
|
118
|
+
self.exclusive do
|
119
|
+
self._eval("library(\"#{name}\", character.only = TRUE)")
|
120
|
+
end
|
121
|
+
|
122
|
+
return nil
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.install_library(name)
|
126
|
+
self.exclusive do
|
127
|
+
self._eval("install.packages(\"#{name}\", dependencies = TRUE)")
|
128
|
+
end
|
129
|
+
|
130
|
+
return nil
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.prerequisite(library)
|
134
|
+
self.install_library(library) unless self.check_library(library)
|
135
|
+
self.load_library(library)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
module Rust::RBindings
|
140
|
+
def data_frame(*args)
|
141
|
+
Rust::DataFrame.new(*args)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
module Rust::TestCases
|
146
|
+
def self.sample_dataframe(columns, size=100)
|
147
|
+
result = Rust::DataFrame.new(columns)
|
148
|
+
size.times do |i|
|
149
|
+
result << columns.map { |c| yield i, c }
|
150
|
+
end
|
151
|
+
return result
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def bind_r!
|
156
|
+
include Rust::RBindings
|
157
|
+
end
|