Rserve::REXP::Double

Constants

NA
NA_ARRAY

Attributes

payload[R]

Public Class Methods

new(data, attrs=nil) click to toggle source
# File lib/rserve/rexp/double.rb, line 16
def initialize(data, attrs=nil)
  @payload=case data
    when Numeric
      [data.to_f]
    when Array
      data
    else
      raise ArgumentError, "Should be Numeric or Array"
  end
  super(attrs)
end

Public Instance Methods

as_doubles() click to toggle source
# File lib/rserve/rexp/double.rb, line 41
def as_doubles
  @payload.map do |v|
    na?(v) ? nil : v.to_f
  end
end
as_integers() click to toggle source
# File lib/rserve/rexp/double.rb, line 36
def as_integers
  @payload.map do |v|
    na?(v) ? nil : v.to_i
  end
end
as_strings() click to toggle source
# File lib/rserve/rexp/double.rb, line 46
def as_strings
  @payload.map {|v| v.to_f.to_s}
end
integer?() click to toggle source
# File lib/rserve/rexp/double.rb, line 30
def integer?
  true
end
length() click to toggle source
# File lib/rserve/rexp/double.rb, line 27
def length
  payload.length
end
na?(value=nil) click to toggle source
# File lib/rserve/rexp/double.rb, line 50
def na?(value=nil)
  #if value.nil?
  #  @payload.map {|v| v.respond_to? :nan and v.nan?}
  #else  
  #  value.respond_to? :nan? and value.nan?
  #end
  return ((value.is_a? Float and value.nan?) or value.to_i==NA) unless value.nil?
  @payload.map {|v| ((v.is_a? Float and v.nan?) or v.to_i==NA)}
end
numeric?() click to toggle source
# File lib/rserve/rexp/double.rb, line 33
def numeric?
  true
end
to_debug_string() click to toggle source
# File lib/rserve/rexp/double.rb, line 59
def to_debug_string
  t=super
  t << "{"  << @payload.map(&:to_s).join(",") << "}"
end
to_ruby_internal() click to toggle source
# File lib/rserve/rexp/double.rb, line 63
def to_ruby_internal
  if dim 
    if dim.size==2
      as_matrix
    else
      as_nested_array
    end
  else
    super
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.