Rserve::REXP::Logical

Constants

NA_internal
NA
TRUE
FALSE

Attributes

payload[R]

Public Class Methods

new(l,attr=nil) click to toggle source

l should be a value or array of 0 and 1.

# File lib/rserve/rexp/logical.rb, line 17
def initialize(l,attr=nil)
  super(attr)
  if l.is_a? Array
    @payload= l
  else
    @payload = [ l==NA ? NA : (l==1 ? TRUE : FALSE) ]
  end
end

Public Instance Methods

as_bytes() click to toggle source
# File lib/rserve/rexp/logical.rb, line 31
def as_bytes
  @payload
end
as_doubles() click to toggle source
# File lib/rserve/rexp/logical.rb, line 50
def as_doubles
  @payload.map {|v| v==NA ? REXP::Double::NA : ( v == FALSE ? 0.0 : 1.0 )}
end
as_integers() click to toggle source
# File lib/rserve/rexp/logical.rb, line 47
def as_integers
  @payload.map {|v| v==NA ? REXP::Integer::NA : ( v == FALSE ? 0 : 1 )}
end
as_strings() click to toggle source
# File lib/rserve/rexp/logical.rb, line 53
def as_strings
  @payload.map {|v| v==NA ? REXP::Double::NA : ( v == FALSE ? "FALSE" : "TRUE" )}
end
false?() click to toggle source
# File lib/rserve/rexp/logical.rb, line 59
def false?
  @payload.map {|v| v==FALSE}
end
length() click to toggle source
# File lib/rserve/rexp/logical.rb, line 25
def length
  @payload.length
end
logical?() click to toggle source
# File lib/rserve/rexp/logical.rb, line 28
def logical?
  true
end
na?(value=nil) click to toggle source
# File lib/rserve/rexp/logical.rb, line 9
def na?(value=nil)
  if value
    value==NA
  else
    @payload.map {|v| v==NA}
  end
end
to_a() click to toggle source

Retrieves values as Ruby array of true and false values NA will be replaced with nils

# File lib/rserve/rexp/logical.rb, line 37
def to_a
  @payload.map {|v|
    case v
    when NA then nil
    when TRUE then true
    when FALSE then false
    end
  }
end
to_ruby_internal() click to toggle source
# File lib/rserve/rexp/logical.rb, line 63
def to_ruby_internal
  if @payload.nil? or @payload.size==0
    nil
  elsif @payload.size==1
    @payload[0]==1 ? true : false
  else
    @payload.map {|v| na?(v) ? nil : (v==1 ? true : false)}
  end
end
true?() click to toggle source
# File lib/rserve/rexp/logical.rb, line 56
def true?
  @payload.map {|v| v==TRUE}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.