Class: Symbol

Inherits:
Object
  • Object
show all
Includes:
R::BinaryOperators, R::ExpBinOp, R::LogicalOperators
Defined in:
lib/R_interface/ruby_extensions.rb

Overview

Instance Method Summary collapse

Methods included from R::LogicalOperators

#&, #|

Methods included from R::ExpBinOp

#coerce, #exec_bin_oper

Methods included from R::BinaryOperators

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object





169
170
171
172
173
# File 'lib/R_interface/ruby_extensions.rb', line 169

def method_missing(symbol, *args, &block)

  E.send(symbol.to_s, self, *args)
  
end

Instance Method Details

#+@Object


Unary ‘+’ converts a Ruby Symbol into an R Symbol




115
116
117
# File 'lib/R_interface/ruby_extensions.rb', line 115

def +@
  R.expr(self)
end

#_(*args) ⇒ Object


We use the following notation to access binary R functions such as %in%: R.vec_ “in”, list. arguments are the list of arguments for the function.


Parameters:

  • args (Array)

    The first element of the array is an R infix function, the other



142
143
144
145
146
147
# File 'lib/R_interface/ruby_extensions.rb', line 142

def _(*args)
  name = "%#{args.shift.to_s}%"
  args.unshift(self)
  rargs = R.exprs(name, *args)
  R.as__call(rargs)
end

#assign(expression) ⇒ Object





153
154
155
# File 'lib/R_interface/ruby_extensions.rb', line 153

def assign(expression)
  exec_bin_oper("`<-`", expression)
end

#assign2(expression) ⇒ Object





161
162
163
# File 'lib/R_interface/ruby_extensions.rb', line 161

def assign2(expression)
  exec_bin_oper("`=`", expression)
end

#inter(var2) ⇒ Object


Create an interaction between two variables in formulas




189
190
191
# File 'lib/R_interface/ruby_extensions.rb', line 189

def inter(var2)
  R::Support.exec_function(R::Support.range, self, var2)
end

#succObject





131
132
133
# File 'lib/R_interface/ruby_extensions.rb', line 131

def succ
  self.to_s.succ.to_sym
end

#to_aryObject


If method_missing is implemented, then we also need to implement method ‘to_ary’. This is because starting from ruby 1.9 the code for Array#flatten has changed, calling ‘to_ary’ blindly (even if the method is not implemented). This causes the method to be caught by ‘method_missing’ and here sending a ‘to_ary’ no found error. If we create to_ary, then no error is issued. @TODO: make sure that implementing ‘to_ary’ as bellow will not create problems




202
203
204
# File 'lib/R_interface/ruby_extensions.rb', line 202

def to_ary
  # [self.to_s]
end

#up_to(var2) ⇒ Object


Used when selecting column in a data frame, from the first column to the var2 column




180
181
182
# File 'lib/R_interface/ruby_extensions.rb', line 180

def up_to(var2)
  R::Support.exec_function(R::Support.range, self, var2)
end

#~@Object


Unary ‘~’ retrieves the values of the R symbol




123
124
125
# File 'lib/R_interface/ruby_extensions.rb', line 123

def ~@
  R::Object.build(R::Support.eval(to_s))
end