class R::RubyCallback

Attributes

object[R]

The Ruby Proc, Method (or Object?) to be called back

r_function[R]

The R function that will call back on the object

Public Class Methods

build(object) click to toggle source
# File lib/R_interface/ruby_callback.rb, line 36
def self.build(object)
  RubyCallback.new(object).r_function
end
new(object) click to toggle source
# File lib/R_interface/ruby_callback.rb, line 47
def initialize(object)
  @object = object
  
  # ruby_callback_method is a method that returns an R function that returns an R
  # function that calls back this object callback method (look at callback bellow)
  @r_function = R::Support.ruby_callback_method.call(method(:callback))
end

Public Instance Methods

callback(*args) click to toggle source
# File lib/R_interface/ruby_callback.rb, line 67
def callback(*args)

  # converts every arg into a R::Object (Ruby object that wraps an R Interop)
  args.map! { |arg| R::Object.build(arg) }
  
  # calls the callback method and convert the result back to an R object
  # method parse_arg was developed to parse the arguments to an R function
  # but in a callback the return value needs to be converted.  In this case
  # the name parse_arg is misleading
  R::Support.parse_arg(@object.call(*args))
  
end
method_missing(symbol, *args) click to toggle source
# File lib/R_interface/ruby_callback.rb, line 59
def method_missing(symbol, *args)
  p "in ruby_callback.rb method missing with #{symbol} #{args}"
end