Class: Rserve::REXP::Vector

Inherits:
Rserve::REXP show all
Defined in:
lib/rserve/rexp/vector.rb

Direct Known Subclasses

Double, GenericVector, Integer, List, Logical, Raw, String, Symbol

Constant Summary

Constants inherited from Rserve::REXP

MaxDebugItems, MismatchError

Instance Attribute Summary collapse

Attributes inherited from Rserve::REXP

#attr

Instance Method Summary collapse

Methods inherited from Rserve::REXP

#as_bytes, #as_double, #as_double_matrix, #as_doubles, #as_factor, #as_float, #as_floats, #as_integer, #as_integers, #as_list, #as_matrix, #as_nested_array, #as_string, #as_strings, #complex?, create_data_frame, #dim, #environment?, #expression?, #factor?, #get_attribute, #has_attribute?, #inherits?, #initialize, #integer?, #language?, #list?, #logical?, #null?, #numeric?, #pair_list?, #raw?, #recursive?, #reference?, #split_array, #string?, #symbol?, #to_debug_string, #to_f, #to_i, #to_ruby

Constructor Details

This class inherits a constructor from Rserve::REXP

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



4
5
6
# File 'lib/rserve/rexp/vector.rb', line 4

def payload
  @payload
end

Instance Method Details

#==(o) ⇒ Object



5
6
7
8
# File 'lib/rserve/rexp/vector.rb', line 5

def ==(o)
  #p "Comparing #{self.inspect} with #{o.inspect} gives #{self.payload==o.payload and self.attr==o.attr}"
  self.class==o.class and self.payload==o.payload and self.attr==o.attr
end

#lengthObject

returns the length of the vector (i.e. the number of elements)

Returns:

  • length of the vector



12
13
# File 'lib/rserve/rexp/vector.rb', line 12

def length
end

#na?Boolean

returns a boolean vector of the same length as this vector with true for NA values and false for any other values

Returns:

  • (Boolean)

    a boolean vector of the same length as this vector with true for NA values and false for any other values */



19
20
# File 'lib/rserve/rexp/vector.rb', line 19

def na?
end

#to_aObject

Retrieves values as Ruby array NA will be replaced with nils



24
25
26
# File 'lib/rserve/rexp/vector.rb', line 24

def to_a
  @payload.map {|v| na?(v) ? nil : v }
end

#to_ruby_internalObject



27
28
29
30
31
32
33
34
35
# File 'lib/rserve/rexp/vector.rb', line 27

def to_ruby_internal
  if @payload.nil? or @payload.size==0
    nil
  elsif @payload.size==1
    @payload[0]
  else
    @payload.map {|v| na?(v) ? nil : v}
  end
end

#vector?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rserve/rexp/vector.rb', line 14

def vector?
  true
end