Class: R::Language

Inherits:
Object show all
Includes:
BinaryOperators, ExpBinOp, IndexedObject, LogicalOperators
Defined in:
lib/R_interface/rlanguage.rb

Instance Attribute Summary collapse

Attributes inherited from Object

#r_interop, #statement

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IndexedObject

#[], #[]=, #size

Methods included from ExpBinOp

#coerce, #exec_bin_oper

Methods included from LogicalOperators

#&, #|

Methods included from BinaryOperators

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

Methods inherited from Object

#==, #_, #attr=, #comment, #comment=, #dim, #dim=, #dimnames, #dimnames=, #eql, #initialize, #method_missing, #names, #names=, #pp, #pretty_print, #rclass, #rclass=, #row__names, #row__names=, #setR, #setR_name, #to_s, #tsp, #tsp=

Constructor Details

This class inherits a constructor from R::Object

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class R::Object

Instance Attribute Details

#expressionObject

Returns the value of attribute expression.



32
33
34
# File 'lib/R_interface/rlanguage.rb', line 32

def expression
  @expression
end

Class Method Details

.build(function_name, *args) ⇒ Object


Builds a call functions with the given arguments.


Parameters:

  • function_name (String)

    name of the function to apply: ex: ‘+’

  • args (Array)

    two elements array for the binary function: ex [:a, :b]

Returns:

  • call expression. With the above paramenters the result would be: .Primitive(“+”)(a, b)



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/R_interface/rlanguage.rb', line 50

def self.build(function_name, *args)
  
  res = R::Language.new(
    R::Support.eval("as.call").
      call(R::Support.parse2list(
             R::Support.eval(function_name), *args)
          ))
  res.expression = "#{Language.to_expression(args[0])} #{function_name.delete("`")} #{Language.to_expression(args[1])}"
  res
  
end

.to_expression(obj) ⇒ Object





38
39
40
# File 'lib/R_interface/rlanguage.rb', line 38

def self.to_expression(obj)
  obj.respond_to?(:expression) ? obj.expression : obj.to_s
end

Instance Method Details

#assign(expression) ⇒ Object





66
67
68
# File 'lib/R_interface/rlanguage.rb', line 66

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

#iObject





74
75
76
# File 'lib/R_interface/rlanguage.rb', line 74

def i
  "I(#{@expression})"
end