Class: Rust::Sequence

Inherits:
RustDatatype show all
Defined in:
lib/rust/core/types/utils.rb

Overview

Represents a sequence of values in R (through a call to the seq function).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RustDatatype

pull_priority, pull_variable, #r_hash, #r_mirror, #r_mirror_to

Constructor Details

#initialize(min, max, step = 1) ⇒ Sequence

Creates a new sequence from min to max with a given step (default = 1).



19
20
21
22
23
# File 'lib/rust/core/types/utils.rb', line 19

def initialize(min, max, step=1)
    @min = min
    @max = max
    @step = step
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



10
11
12
# File 'lib/rust/core/types/utils.rb', line 10

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



9
10
11
# File 'lib/rust/core/types/utils.rb', line 9

def min
  @min
end

Class Method Details

.can_pull?(type, klass) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rust/core/types/utils.rb', line 12

def self.can_pull?(type, klass)
    return false
end

Instance Method Details

#eachObject



35
36
37
38
39
# File 'lib/rust/core/types/utils.rb', line 35

def each
    (@min..@max).step(@step) do |v|
        yield v
    end
end

#load_in_r_as(variable_name) ⇒ Object



53
54
55
# File 'lib/rust/core/types/utils.rb', line 53

def load_in_r_as(variable_name)
    Rust._eval("#{variable_name} <- #{self.to_R}")
end

#step=(step) ⇒ Object Also known as: step

Sets the step to step.



28
29
30
31
32
# File 'lib/rust/core/types/utils.rb', line 28

def step=(step)
    @step = step
    
    return self
end

#to_aObject



41
42
43
44
45
46
47
# File 'lib/rust/core/types/utils.rb', line 41

def to_a
    result = []
    self.each do |v|
        result << v
    end
    return result
end

#to_RObject



49
50
51
# File 'lib/rust/core/types/utils.rb', line 49

def to_R
    "seq(from=#@min, to=#@max, by=#@step)"
end