Module: Renjin::RBSexp

Included in:
Array, MDArray, Range, Callback, RubySexp
Defined in:
lib/JRubyR/rbsexp.rb

Overview

Module to wrapp every Renjin SEXP.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrObject (readonly)

Returns the value of attribute attr.



42
43
44
# File 'lib/JRubyR/rbsexp.rb', line 42

def attr
  @attr
end

#rvarObject (readonly)

Returns the value of attribute rvar.



41
42
43
# File 'lib/JRubyR/rbsexp.rb', line 41

def rvar
  @rvar
end

#scopeObject

Returns the value of attribute scope.



43
44
45
# File 'lib/JRubyR/rbsexp.rb', line 43

def scope
  @scope
end

#sexpObject (readonly)

Returns the value of attribute sexp.



40
41
42
# File 'lib/JRubyR/rbsexp.rb', line 40

def sexp
  @sexp
end

Instance Method Details

#destroyObject





49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/JRubyR/rbsexp.rb', line 49

def destroy
  
  if (@rvar != nil)
    @sexp = R.direct_eval("#{@rvar}")
    # change value in the scope
    if (@scope)
      R.direct_eval("#{scope[0]}(#{scope[1].r}, \"#{scope[2]}\") = #{@rvar}")
      # @scope = nil
    end
    R.direct_eval("rm('#{@rvar}')")
    @rvar = nil
    
  end
  
end

#ppObject





137
138
139
# File 'lib/JRubyR/rbsexp.rb', line 137

def pp
  print
end




128
129
130
131
# File 'lib/JRubyR/rbsexp.rb', line 128

def print
  # Kernel.print(Java::OrgRenjinPrimitives::Print.doPrint(sexp))
  R.eval("print(#{r})")
end

#rObject


Push the object into the R evaluator. Check to see if this object already has an R value (rvar). The rvar is just a string of the form sc_xxxxxxxx. This string will be an R variable that holds the SEXP.




71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/JRubyR/rbsexp.rb', line 71

def r
  
  if (@rvar == nil)
    # create a new variable name to hold this object inside R
    @rvar = "sc_#{SecureRandom.hex(8)}"
    
    # if this object already has a sexp value then assign to @rvar the existing sexp,
    # otherwise, assign itself to @rvar.
    (@sexp == nil)? R.assign(@rvar, self) : R.assign(@rvar, @sexp)
    
    # Whenever a variable is injected in Renjin, it is also added to the Renjin stack.
    # After eval, every injected variable is removed from Renjin making sure that we
    # do not have memory leak.
    Renjin.stack << self
    
  end
  
  @rvar
  
end

#rclassObject





120
121
122
# File 'lib/JRubyR/rbsexp.rb', line 120

def rclass
  R.rclass(R.eval("#{r}"))
end

#sexp?Boolean


  • @return true if this RubySexp already points to a sexp in R environment


Returns:

  • (Boolean)


96
97
98
# File 'lib/JRubyR/rbsexp.rb', line 96

def sexp?
  sexp != nil
end

#typeofObject





112
113
114
# File 'lib/JRubyR/rbsexp.rb', line 112

def typeof
  R.typeof(R.eval("#{r}"))
end

#unbindObject


Scope is used for accessing attribute values for an R object.




104
105
106
# File 'lib/JRubyR/rbsexp.rb', line 104

def unbind
  @scope = nil
end