Class: R::RSymbol

Inherits:
Object
  • Object
show all
Includes:
BinaryOperators, ExecBinOp, LogicalOperators
Defined in:
lib/R_interface/rsymbol.rb

Overview



Instance Method Summary collapse

Methods included from LogicalOperators

#&, #|

Methods included from ExecBinOp

#coerce

Methods included from BinaryOperators

#!=, #%, #*, #**, #+, #-, #/, #<, #<=, #>, #>=, #_, #eq, #int_div, #til

Instance Method Details

#^(other_object) ⇒ Object





100
101
102
# File 'lib/R_interface/rsymbol.rb', line 100

def ^(other_object)
  exec_bin_oper("`:`", other_object)
end

#classObject



35
36
37
# File 'lib/R_interface/rsymbol.rb', line 35

def class
  ::R::RSymbol
end

#exec_bin_oper(operator, other_object) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/R_interface/rsymbol.rb', line 59

def exec_bin_oper(operator, other_object)
  # Use infix notation: lhs operator rhs, but evaluate self
  op = operator.delete("`")
  
  var_name = ::R::Support.generate_var_name
  lhs = "eval(#{@r_interop})"
  
  # If other object is a symbol, evaluate it too
  rhs = if other_object.is_a?(::R::RSymbol)
          "eval(#{other_object.r_interop})"
        else
          ::R::Support.parse_arg(other_object)
        end
  
  ::R.bridge.eval_r("#{var_name} <- #{lhs} #{op} #{rhs}")
  ::R::Object.build(var_name)
end

#exec_uni_oper(operator) ⇒ Object



77
78
79
80
81
82
# File 'lib/R_interface/rsymbol.rb', line 77

def exec_uni_oper(operator)
  op = operator.delete("`").strip
  var_name = ::R::Support.generate_var_name
  ::R.bridge.eval_r("#{var_name} <- #{op}(eval(#{@r_interop}))")
  ::R::Object.build(var_name)
end

#rclassObject



39
40
41
42
43
# File 'lib/R_interface/rsymbol.rb', line 39

def rclass
  res = ::R::Support.exec_function("class", ::R::Support.exec_function("eval", self))
  val = res.respond_to?(:>>) ? (res >> nil) : res
  val.is_a?(::Array) ? val[0] : val
end

#to_sObject

Symbol name as string (e.g. "read.table") for call[[1]].to_s.



52
53
54
55
56
57
# File 'lib/R_interface/rsymbol.rb', line 52

def to_s
  return super unless ::R.bridge.ready?
  raw = ::R.bridge.eval_r("as.character(#{@r_interop})").to_s
  m = raw.match(/\[1\]\s*"([^"]*)"/)
  m ? m[1] : raw.strip
end

#typeofObject



45
46
47
48
49
# File 'lib/R_interface/rsymbol.rb', line 45

def typeof
  res = ::R::Support.exec_function("typeof", ::R::Support.exec_function("eval", self))
  val = res.respond_to?(:>>) ? (res >> nil) : res
  val.is_a?(::Array) ? val[0] : val
end