Module: Rust

Defined in:
lib/rust-csv.rb,
lib/rust-core.rb,
lib/rust-calls.rb

Defined Under Namespace

Modules: Correlation, Descriptive, EffectSize, Plots, RBindings, StatisticalTests Classes: Arguments, CSV, DataFrame, Function, Matrix, Options, RustDatatype, Sequence, Variable

Constant Summary collapse

@@debugging =
false
@@in_client_mutex =
false

Class Method Summary collapse

Class Method Details

.[](variable, type = RustDatatype) ⇒ Object



44
45
46
# File 'lib/rust-core.rb', line 44

def self.[](variable, type=RustDatatype)
    return type.pull_variable(variable)
end

.[]=(variable, value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/rust-core.rb', line 33

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)
        R_ENGINE.assign(variable, value)
    else
        raise "Given #{value.class}, expected RustDatatype, String, Numeric, or Array"
    end
    
end

._eval(r_command, return_warnings = false) ⇒ Object



73
74
75
# File 'lib/rust-core.rb', line 73

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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rust-core.rb', line 48

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



69
70
71
# File 'lib/rust-core.rb', line 69

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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rust-core.rb', line 77

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
            return result, warnings.lines.map { |w| w.strip.chomp }
        else
            return result
        end
    end
end

.debugObject



19
20
21
# File 'lib/rust-core.rb', line 19

def self.debug
    @@debugging = true
end

.exclusiveObject



23
24
25
26
27
28
29
30
31
# File 'lib/rust-core.rb', line 23

def self.exclusive
    result = nil
    CLIENT_MUTEX.synchronize do
        @@in_client_mutex = true
        result = yield
        @@in_client_mutex = false
    end
    return result
end