scicom 0.3.0-java → 0.4.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +239 -55
- data/Rakefile +58 -5
- data/config.rb +34 -2
- data/doc/Array.html +153 -0
- data/doc/Java/OrgRenjinSexp/LogicalArrayVector.html +120 -0
- data/doc/Java/OrgRenjinSexp/StringArrayVector.html +133 -0
- data/doc/Java/RbScicom/MDDoubleVector.html +133 -0
- data/doc/MDArray.html +153 -0
- data/doc/MergeObservable.html +347 -0
- data/doc/NegRange.html +166 -0
- data/doc/PackageManager.html +823 -0
- data/doc/PackageManager/ParseXML.html +595 -0
- data/doc/Range.html +243 -0
- data/doc/Renjin.html +2210 -0
- data/doc/Renjin/Attributes.html +401 -0
- data/doc/Renjin/Closure.html +181 -0
- data/doc/Renjin/ComplexVector.html +557 -0
- data/doc/Renjin/DataFrame.html +258 -0
- data/doc/Renjin/Environment.html +279 -0
- data/doc/Renjin/Function.html +243 -0
- data/doc/Renjin/Index.html +628 -0
- data/doc/Renjin/List.html +398 -0
- data/doc/Renjin/Logical.html +352 -0
- data/doc/Renjin/Primitive.html +181 -0
- data/doc/Renjin/RBSexp.html +1151 -0
- data/doc/Renjin/RubySexp.html +498 -0
- data/doc/Renjin/Vector.html +3163 -0
- data/doc/RinRuby.html +2079 -0
- data/doc/_index.html +365 -0
- data/doc/class_list.html +58 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +159 -0
- data/doc/file_list.html +60 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +159 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +181 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +939 -0
- data/doc/top-level-namespace.html +679 -0
- data/lib/JRubyR/attributes.rb +5 -2
- data/lib/JRubyR/callback.rb +115 -0
- data/lib/JRubyR/environment.rb +0 -1
- data/lib/JRubyR/indexed.rb +139 -0
- data/lib/JRubyR/list.rb +0 -16
- data/lib/JRubyR/logical_value.rb +0 -1
- data/lib/JRubyR/rbsexp.rb +20 -131
- data/lib/JRubyR/renjin.rb +201 -71
- data/lib/JRubyR/vector.rb +16 -15
- data/lib/scicom.rb +1 -3
- data/target/helper.jar +0 -0
- data/test/test_R_interface.rb +1 -1
- data/test/test_array.rb +1 -1
- data/test/test_assign_mdarray.rb +1 -1
- data/test/test_assign_mdarray_2d.rb +1 -1
- data/test/test_assign_mdarray_3d.rb +1 -1
- data/test/test_attributes.rb +1 -1
- data/test/test_basic.rb +7 -5
- data/test/test_callback.rb +176 -0
- data/test/test_complete.rb +1 -1
- data/test/test_creation.rb +29 -5
- data/test/test_dataframe.rb +1 -1
- data/test/test_factor.rb +1 -1
- data/test/test_functions.rb +13 -10
- data/test/test_linear_model.rb +1 -1
- data/test/test_list.rb +49 -10
- data/test/test_matrix.rb +6 -6
- data/test/test_operators.rb +1 -1
- data/test/test_package.rb +5 -5
- data/test/test_vector.rb +13 -7
- data/vendor/aether-api-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-connector-basic-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-impl-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-spi-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-transport-file-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-transport-http-1.0.2.v20150114.jar +0 -0
- data/vendor/aether-util-1.0.2.v20150114.jar +0 -0
- data/vendor/aopalliance-1.0.jar +0 -0
- data/vendor/asm-3.3.1.jar +0 -0
- data/vendor/asm-5.0.4.jar +0 -0
- data/vendor/asm-commons-5.0.4.jar +0 -0
- data/vendor/asm-tree-5.0.4.jar +0 -0
- data/vendor/asm-util-5.0.4.jar +0 -0
- data/vendor/blas-0.8.jar +0 -0
- data/vendor/cdi-api-1.0.jar +0 -0
- data/vendor/codemodel-2.6.jar +0 -0
- data/vendor/collections-generic-4.01.jar +0 -0
- data/vendor/commons-codec-1.6.jar +0 -0
- data/vendor/commons-compress-1.4.1.jar +0 -0
- data/vendor/commons-logging-1.1.1.jar +0 -0
- data/vendor/commons-math-2.2.jar +0 -0
- data/vendor/commons-vfs2-2.0.jar +0 -0
- data/vendor/datasets-0.8.1891.jar +0 -0
- data/vendor/f2jutil-0.8.jar +0 -0
- data/vendor/gcc-runtime-0.8.1891.jar +0 -0
- data/vendor/grDevices-0.8.1891.jar +0 -0
- data/vendor/graphics-0.8.1891.jar +0 -0
- data/vendor/guava-17.0.jar +0 -0
- data/vendor/httpclient-4.2.6.jar +0 -0
- data/vendor/httpcore-4.2.5.jar +0 -0
- data/vendor/javax.inject-1.jar +0 -0
- data/vendor/jcl-over-slf4j-1.6.2.jar +0 -0
- data/vendor/joda-time-2.0.jar +0 -0
- data/vendor/jsr250-api-1.0.jar +0 -0
- data/vendor/jtransforms-2.4.jar +0 -0
- data/vendor/jung-api-2.0.1.jar +0 -0
- data/vendor/jung-graph-impl-2.0.1.jar +0 -0
- data/vendor/lapack-0.8.jar +0 -0
- data/vendor/maven-aether-provider-3.1.0.jar +0 -0
- data/vendor/maven-model-3.1.0.jar +0 -0
- data/vendor/maven-model-builder-3.1.0.jar +0 -0
- data/vendor/maven-repository-metadata-3.1.0.jar +0 -0
- data/vendor/maven-scm-api-1.4.jar +0 -0
- data/vendor/maven-scm-provider-svn-commons-1.4.jar +0 -0
- data/vendor/maven-scm-provider-svnexe-1.4.jar +0 -0
- data/vendor/maven-settings-3.1.0.jar +0 -0
- data/vendor/maven-settings-builder-3.1.0.jar +0 -0
- data/vendor/methods-0.8.1891.jar +0 -0
- data/vendor/netlib-java-0.9.3-renjin-patched-2.jar +0 -0
- data/vendor/org.eclipse.sisu.inject-0.0.0.M2a.jar +0 -0
- data/vendor/org.eclipse.sisu.plexus-0.0.0.M2a.jar +0 -0
- data/vendor/plexus-cipher-1.4.jar +0 -0
- data/vendor/plexus-classworlds-2.4.jar +0 -0
- data/vendor/plexus-component-annotations-1.5.5.jar +0 -0
- data/vendor/plexus-interpolation-1.16.jar +0 -0
- data/vendor/plexus-sec-dispatcher-1.3.jar +0 -0
- data/vendor/plexus-utils-1.5.6.jar +0 -0
- data/vendor/plexus-utils-3.0.10.jar +0 -0
- data/vendor/regexp-1.3.jar +0 -0
- data/vendor/renjin-aether-package-loader-0.8.1891.jar +0 -0
- data/vendor/renjin-appl-0.8.1891.jar +0 -0
- data/vendor/renjin-core-0.8.1891.jar +0 -0
- data/vendor/renjin-gnur-runtime-0.8.1891.jar +0 -0
- data/vendor/renjin-script-engine-0.8.1891.jar +0 -0
- data/vendor/sisu-guice-3.1.0-no_aop.jar +0 -0
- data/vendor/slf4j-api-1.6.2.jar +0 -0
- data/vendor/stats-0.8.1891.jar +0 -0
- data/vendor/utils-0.8.1891.jar +0 -0
- data/vendor/xerbla-0.8.jar +0 -0
- data/vendor/xz-1.0.jar +0 -0
- data/version.rb +1 -1
- metadata +229 -127
- data/cran/AppliedPredictiveModeling.jar +0 -0
- data/cran/AppliedPredictiveModeling.xml +0 -25
- data/cran/AssetPricing.jar +0 -0
- data/cran/AssetPricing.xml +0 -25
- data/lib/env.rb +0 -12
- data/lib/rinruby.rb +0 -795
- data/test/env.rb +0 -2
- data/test/test_tmp.rb +0 -67
- data/vendor/Renjin.pdf +0 -0
- data/vendor/renjin-script-engine-0.7.0-RC7-SNAPSHOT-jar-with-dependencies.jar +0 -0
data/lib/JRubyR/attributes.rb
CHANGED
|
@@ -40,7 +40,11 @@ class Renjin
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
#----------------------------------------------------------------------------------------
|
|
43
|
-
#
|
|
43
|
+
# When accessing an attribute, we need to keep track of the object that holds the
|
|
44
|
+
# attribute. This is necessary for the following construct to work:
|
|
45
|
+
# elmt.attr.name = "name". In this case, we need to change the attribute of elmt and
|
|
46
|
+
# in R this is done by elmt.attr <- name. But when parsing Ruby, when we get to
|
|
47
|
+
# elmt.attr.name, it is to late.
|
|
44
48
|
#----------------------------------------------------------------------------------------
|
|
45
49
|
|
|
46
50
|
def method_missing(symbol, *args)
|
|
@@ -52,7 +56,6 @@ class Renjin
|
|
|
52
56
|
name.gsub!("rclass", "class")
|
|
53
57
|
|
|
54
58
|
if name =~ /(.*)=$/
|
|
55
|
-
super if args.length != 1
|
|
56
59
|
args = R.parse(*args)
|
|
57
60
|
ret = R.eval("attr(#{@rbsexp.r}, \"#{name.delete!('=')}\") = #{args}")
|
|
58
61
|
else
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
##########################################################################################
|
|
4
|
+
# @author Rodrigo Botafogo
|
|
5
|
+
#
|
|
6
|
+
# Copyright © 2016 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
|
10
|
+
# distributions.
|
|
11
|
+
#
|
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
16
|
+
#
|
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
|
21
|
+
# OR MODIFICATIONS.
|
|
22
|
+
##########################################################################################
|
|
23
|
+
|
|
24
|
+
class Renjin
|
|
25
|
+
|
|
26
|
+
class Callback
|
|
27
|
+
include Java::RbScicom.RubyCallbackInterface
|
|
28
|
+
include Renjin::RBSexp
|
|
29
|
+
|
|
30
|
+
attr_reader :ruby_obj
|
|
31
|
+
|
|
32
|
+
#----------------------------------------------------------------------------------------
|
|
33
|
+
#
|
|
34
|
+
#----------------------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
def initialize(ruby_obj)
|
|
37
|
+
@ruby_obj = ruby_obj
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
#----------------------------------------------------------------------------------------
|
|
41
|
+
#
|
|
42
|
+
#----------------------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
def run(method, *args)
|
|
45
|
+
# puts "method #{method} called with args: #{args}"
|
|
46
|
+
# The returned value from the called method should be packed.
|
|
47
|
+
Callback.pack(@ruby_obj.send(method, *args))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#----------------------------------------------------------------------------------------
|
|
51
|
+
#
|
|
52
|
+
#----------------------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
def get_class(class_name)
|
|
55
|
+
run("const_get", class_name)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
#----------------------------------------------------------------------------------------
|
|
59
|
+
#
|
|
60
|
+
#----------------------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
def build(class_name, *args)
|
|
63
|
+
klass = get_class(class_name)
|
|
64
|
+
klass.run("new", *args)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#----------------------------------------------------------------------------------------
|
|
68
|
+
# Scope can be:
|
|
69
|
+
# * external: only the received object is packed
|
|
70
|
+
# * internal: only the internal objects are packed. In this case, the received object
|
|
71
|
+
# must respond to the 'each'.
|
|
72
|
+
# * all: packs both internal and external
|
|
73
|
+
#----------------------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
def self.pack(obj, scope: :external)
|
|
76
|
+
|
|
77
|
+
# Do not pack basic types Boolean, Numberic or String
|
|
78
|
+
case obj
|
|
79
|
+
when TrueClass, FalseClass, Numeric, String
|
|
80
|
+
return obj
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
case scope
|
|
84
|
+
when :internal
|
|
85
|
+
raise "Cannot rpack object's internals as it does not respond to the :each method." if
|
|
86
|
+
!obj.respond_to?(:each)
|
|
87
|
+
obj.map { |pk| Callback.new(pk) }
|
|
88
|
+
when :external
|
|
89
|
+
Callback.new(obj)
|
|
90
|
+
when :all
|
|
91
|
+
Callback.new(obj.map! { |pk| Callback.new(pk) })
|
|
92
|
+
else
|
|
93
|
+
raise "Scope must be :internal, :external or :all. Unknown #{scope} scope"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
=begin
|
|
103
|
+
class Hash
|
|
104
|
+
def deep_traverse(&block)
|
|
105
|
+
stack = self.map{ |k,v| [ [k], v ] }
|
|
106
|
+
while not stack.empty?
|
|
107
|
+
key, value = stack.pop
|
|
108
|
+
yield(key, value)
|
|
109
|
+
if value.is_a? Hash
|
|
110
|
+
value.each{ |k,v| stack.push [ key.dup << k, v ] }
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
=end
|
data/lib/JRubyR/environment.rb
CHANGED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
##########################################################################################
|
|
4
|
+
# @author Rodrigo Botafogo
|
|
5
|
+
#
|
|
6
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
|
10
|
+
# distributions.
|
|
11
|
+
#
|
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
16
|
+
#
|
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
|
21
|
+
# OR MODIFICATIONS.
|
|
22
|
+
##########################################################################################
|
|
23
|
+
|
|
24
|
+
require_relative "attributes"
|
|
25
|
+
|
|
26
|
+
#==========================================================================================
|
|
27
|
+
# Module Index, should be required by classes that can be accessed by an index, such as
|
|
28
|
+
# list and vector
|
|
29
|
+
#==========================================================================================
|
|
30
|
+
|
|
31
|
+
class Renjin
|
|
32
|
+
|
|
33
|
+
module Index
|
|
34
|
+
|
|
35
|
+
#----------------------------------------------------------------------------------------
|
|
36
|
+
# Access an element of the class by indexing
|
|
37
|
+
#----------------------------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
def [](*index)
|
|
40
|
+
index = parse(index)
|
|
41
|
+
R.eval("#{r}[#{index}]")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#----------------------------------------------------------------------------------------
|
|
45
|
+
# Assign a value to a given index
|
|
46
|
+
#----------------------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
def []=(*index, value)
|
|
49
|
+
index = parse(index)
|
|
50
|
+
value = R.parse(value)
|
|
51
|
+
R.eval("#{r}[#{index}] = #{value}")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#----------------------------------------------------------------------------------------
|
|
55
|
+
#
|
|
56
|
+
#----------------------------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
def parse(index)
|
|
59
|
+
|
|
60
|
+
params = Array.new
|
|
61
|
+
|
|
62
|
+
index.each do |i|
|
|
63
|
+
if (i.is_a? Array)
|
|
64
|
+
params << i
|
|
65
|
+
else
|
|
66
|
+
params << R.parse(i)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
ps = String.new
|
|
71
|
+
params.each_with_index do |p, i|
|
|
72
|
+
ps << "," if i > 0
|
|
73
|
+
ps << ((p == "NULL")? "" : p.to_s)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
ps
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
#----------------------------------------------------------------------------------------
|
|
81
|
+
# Module Index is included in list and vector. We allow access to list/vector elements
|
|
82
|
+
# by name. Two underscores are replaced with a '.' in order to be able to call methods
|
|
83
|
+
# in R that have a '.' such as is.na, becomes R.is__na.
|
|
84
|
+
#----------------------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
def method_missing(symbol, *args)
|
|
87
|
+
|
|
88
|
+
name = symbol.id2name
|
|
89
|
+
name.gsub!(/__/,".")
|
|
90
|
+
|
|
91
|
+
if name =~ /(.*)=$/
|
|
92
|
+
# p "#{r}$#{$1} = #{args[0].r}"
|
|
93
|
+
# ret = R.eval("#{r}[\"#{name}\"] = #{args[0].r}")
|
|
94
|
+
ret = R.eval("#{r}$#{$1} = #{args[0].r}")
|
|
95
|
+
elsif (args.length == 0)
|
|
96
|
+
# treat name as a named item of the list
|
|
97
|
+
if (R.eval("\"#{name}\" %in% names(#{r})").gt)
|
|
98
|
+
ret = R.eval("#{r}[[\"#{name}\"]]")
|
|
99
|
+
else
|
|
100
|
+
ret = R.eval("#{name}(#{r})") if ret == nil
|
|
101
|
+
end
|
|
102
|
+
elsif (args.length > 0)
|
|
103
|
+
# p "#{name}(#{r}, #{R.parse(*args)})"
|
|
104
|
+
ret = R.eval("#{name}(#{r}, #{R.parse(*args)})")
|
|
105
|
+
else
|
|
106
|
+
raise "Illegal argument for named list item #{name}"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
ret
|
|
110
|
+
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
#----------------------------------------------------------------------------------------
|
|
114
|
+
# We use the following notation to access binary R functions such as %in%:
|
|
115
|
+
# R.vec_ "in", list.
|
|
116
|
+
#----------------------------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
def _(*args)
|
|
119
|
+
method = "%#{args.shift.to_s}%"
|
|
120
|
+
arg2 = R.parse(*args)
|
|
121
|
+
ret = R.eval("#{r} #{method} #{arg2}")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
#----------------------------------------------------------------------------------------
|
|
125
|
+
#
|
|
126
|
+
#----------------------------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
def each(&block)
|
|
129
|
+
while (@iterator.hasNext())
|
|
130
|
+
block.call(@iterator.next())
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
require_relative 'vector'
|
|
139
|
+
require_relative 'list'
|
data/lib/JRubyR/list.rb
CHANGED
|
@@ -35,22 +35,6 @@ class Renjin
|
|
|
35
35
|
@iterator = @sexp.iterator()
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
#----------------------------------------------------------------------------------------
|
|
39
|
-
#
|
|
40
|
-
#----------------------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
def names
|
|
43
|
-
R.names(self)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
#----------------------------------------------------------------------------------------
|
|
47
|
-
#
|
|
48
|
-
#----------------------------------------------------------------------------------------
|
|
49
|
-
|
|
50
|
-
def unlist
|
|
51
|
-
R.unlist(self)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
38
|
end
|
|
55
39
|
|
|
56
40
|
end
|
data/lib/JRubyR/logical_value.rb
CHANGED
data/lib/JRubyR/rbsexp.rb
CHANGED
|
@@ -29,112 +29,8 @@ require_relative "attributes"
|
|
|
29
29
|
|
|
30
30
|
class Renjin
|
|
31
31
|
|
|
32
|
-
module Index
|
|
33
|
-
|
|
34
|
-
#----------------------------------------------------------------------------------------
|
|
35
|
-
#
|
|
36
|
-
#----------------------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
def [](*index)
|
|
39
|
-
index = parse(index)
|
|
40
|
-
R.eval("#{r}[#{index}]")
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
#----------------------------------------------------------------------------------------
|
|
44
|
-
#
|
|
45
|
-
#----------------------------------------------------------------------------------------
|
|
46
|
-
|
|
47
|
-
def []=(*index, value)
|
|
48
|
-
index = parse(index)
|
|
49
|
-
value = R.parse(value)
|
|
50
|
-
R.eval("#{r}[#{index}] = #{value}")
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
#----------------------------------------------------------------------------------------
|
|
54
|
-
#
|
|
55
|
-
#----------------------------------------------------------------------------------------
|
|
56
|
-
|
|
57
|
-
def parse(index)
|
|
58
|
-
|
|
59
|
-
params = Array.new
|
|
60
|
-
|
|
61
|
-
index.each do |i|
|
|
62
|
-
if (i.is_a? Array)
|
|
63
|
-
params << i
|
|
64
|
-
else
|
|
65
|
-
params << R.parse(i)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
ps = String.new
|
|
70
|
-
params.each_with_index do |p, i|
|
|
71
|
-
ps << "," if i > 0
|
|
72
|
-
ps << ((p == "NULL")? "" : p.to_s)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
ps
|
|
76
|
-
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
#----------------------------------------------------------------------------------------
|
|
80
|
-
#
|
|
81
|
-
#----------------------------------------------------------------------------------------
|
|
82
|
-
|
|
83
|
-
def method_missing(symbol, *args)
|
|
84
|
-
|
|
85
|
-
name = symbol.id2name
|
|
86
|
-
name.gsub!(/__/,".")
|
|
87
|
-
|
|
88
|
-
# super if args.length != 0
|
|
89
|
-
if name =~ /(.*)=$/
|
|
90
|
-
super if args.length != 1
|
|
91
|
-
# p "#{r}$#{$1} = #{args[0].r}"
|
|
92
|
-
# ret = R.eval("#{r}[\"#{name}\"] = #{args[0].r}")
|
|
93
|
-
ret = R.eval("#{r}$#{$1} = #{args[0].r}")
|
|
94
|
-
elsif (name == "_")
|
|
95
|
-
method = "%#{args.shift.to_s}%"
|
|
96
|
-
arg2 = R.parse(*args)
|
|
97
|
-
ret = R.eval("#{r} #{method} #{arg2}")
|
|
98
|
-
elsif (args.length == 0)
|
|
99
|
-
# treat name as a named item of the list
|
|
100
|
-
if (R.eval("\"#{name}\" %in% names(#{r})").gt)
|
|
101
|
-
ret = R.eval("#{r}[[\"#{name}\"]]")
|
|
102
|
-
else
|
|
103
|
-
ret = R.eval("#{name}(#{r})") if ret == nil
|
|
104
|
-
end
|
|
105
|
-
elsif (args.length > 0)
|
|
106
|
-
# p "#{name}(#{r}, #{R.parse(*args)})"
|
|
107
|
-
ret = R.eval("#{name}(#{r}, #{R.parse(*args)})")
|
|
108
|
-
else
|
|
109
|
-
raise "Illegal argument for named list item #{name}"
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
ret
|
|
113
|
-
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
#----------------------------------------------------------------------------------------
|
|
117
|
-
#
|
|
118
|
-
#----------------------------------------------------------------------------------------
|
|
119
|
-
|
|
120
|
-
def length
|
|
121
|
-
R.length(R.eval("#{r}")).gz
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
#----------------------------------------------------------------------------------------
|
|
125
|
-
#
|
|
126
|
-
#----------------------------------------------------------------------------------------
|
|
127
|
-
|
|
128
|
-
def each(&block)
|
|
129
|
-
while (@iterator.hasNext())
|
|
130
|
-
block.call(@iterator.next())
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
end
|
|
135
|
-
|
|
136
32
|
#==========================================================================================
|
|
137
|
-
#
|
|
33
|
+
# Module to wrapp every Renjin SEXP.
|
|
138
34
|
#==========================================================================================
|
|
139
35
|
|
|
140
36
|
module RBSexp
|
|
@@ -167,18 +63,26 @@ class Renjin
|
|
|
167
63
|
end
|
|
168
64
|
|
|
169
65
|
#----------------------------------------------------------------------------------------
|
|
170
|
-
#
|
|
66
|
+
# Push the object into the R evaluator. Check to see if this object already has an R
|
|
67
|
+
# value (rvar). The rvar is just a string of the form sc_xxxxxxxx. This string will be
|
|
68
|
+
# an R variable that holds the SEXP.
|
|
171
69
|
#----------------------------------------------------------------------------------------
|
|
172
70
|
|
|
173
71
|
def r
|
|
174
72
|
|
|
175
73
|
if (@rvar == nil)
|
|
74
|
+
# create a new variable name to hold this object inside R
|
|
176
75
|
@rvar = "sc_#{SecureRandom.hex(8)}"
|
|
76
|
+
|
|
77
|
+
# if this object already has a sexp value then assign to @rvar the existing sexp,
|
|
78
|
+
# otherwise, assign itself to @rvar.
|
|
177
79
|
(@sexp == nil)? R.assign(@rvar, self) : R.assign(@rvar, @sexp)
|
|
80
|
+
|
|
178
81
|
# Whenever a variable is injected in Renjin, it is also added to the Renjin stack.
|
|
179
82
|
# After eval, every injected variable is removed from Renjin making sure that we
|
|
180
83
|
# do not have memory leak.
|
|
181
84
|
Renjin.stack << self
|
|
85
|
+
|
|
182
86
|
end
|
|
183
87
|
|
|
184
88
|
@rvar
|
|
@@ -194,7 +98,7 @@ class Renjin
|
|
|
194
98
|
end
|
|
195
99
|
|
|
196
100
|
#----------------------------------------------------------------------------------------
|
|
197
|
-
#
|
|
101
|
+
# Scope is used for accessing attribute values for an R object.
|
|
198
102
|
#----------------------------------------------------------------------------------------
|
|
199
103
|
|
|
200
104
|
def unbind
|
|
@@ -234,22 +138,6 @@ class Renjin
|
|
|
234
138
|
print
|
|
235
139
|
end
|
|
236
140
|
|
|
237
|
-
#----------------------------------------------------------------------------------------
|
|
238
|
-
#
|
|
239
|
-
#----------------------------------------------------------------------------------------
|
|
240
|
-
|
|
241
|
-
def nrow
|
|
242
|
-
R.nrow(self)
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
#----------------------------------------------------------------------------------------
|
|
246
|
-
#
|
|
247
|
-
#----------------------------------------------------------------------------------------
|
|
248
|
-
|
|
249
|
-
def ncol
|
|
250
|
-
R.ncol(self)
|
|
251
|
-
end
|
|
252
|
-
|
|
253
141
|
end
|
|
254
142
|
|
|
255
143
|
end
|
|
@@ -297,13 +185,13 @@ class Renjin
|
|
|
297
185
|
|
|
298
186
|
def self.build(sexp)
|
|
299
187
|
|
|
300
|
-
if (sexp.
|
|
188
|
+
if (sexp.java_kind_of? Java::OrgRenjinSexp::Null)
|
|
301
189
|
res = nil
|
|
302
|
-
elsif (sexp.
|
|
190
|
+
elsif (sexp.java_kind_of? Java::OrgRenjinSexp::ListVector)
|
|
303
191
|
res = Renjin::List.new(sexp)
|
|
304
|
-
elsif (sexp.
|
|
192
|
+
elsif (sexp.java_kind_of? Java::OrgRenjinSexp::LogicalArrayVector)
|
|
305
193
|
res = Renjin::Logical.new(sexp)
|
|
306
|
-
elsif (sexp.
|
|
194
|
+
elsif (sexp.java_kind_of? Java::OrgRenjinSexp::Environment)
|
|
307
195
|
res = Renjin::Environment.new(sexp)
|
|
308
196
|
elsif (sexp.is_a? Java::OrgRenjinSexp::ComplexVector)
|
|
309
197
|
res = Renjin::ComplexVector.new(sexp)
|
|
@@ -311,11 +199,12 @@ class Renjin
|
|
|
311
199
|
res = Renjin::Vector.new(sexp)
|
|
312
200
|
elsif (sexp.is_a? Java::OrgRenjinSexp::Closure)
|
|
313
201
|
res = Renjin::Closure.new(sexp)
|
|
202
|
+
elsif (sexp.is_a? Java::OrgRenjinSexp::ExternalPtr)
|
|
203
|
+
res = Renjin::RubySexp.new(sexp)
|
|
314
204
|
# elsif (sexp.is_a? Java::OrgRenjinPrimitives::R$primitive$sum)
|
|
315
205
|
# res = Renjin::Primitive.new(sexp)
|
|
316
206
|
else
|
|
317
|
-
|
|
318
|
-
p sexp
|
|
207
|
+
puts "rbsexp build: sexp type needs to be specialized: #{sexp}"
|
|
319
208
|
res = Renjin::RubySexp.new(sexp)
|
|
320
209
|
end
|
|
321
210
|
|
|
@@ -328,8 +217,8 @@ class Renjin
|
|
|
328
217
|
end
|
|
329
218
|
|
|
330
219
|
require_relative 'ruby_classes'
|
|
331
|
-
require_relative '
|
|
332
|
-
require_relative 'list'
|
|
220
|
+
require_relative 'indexed'
|
|
333
221
|
require_relative 'function'
|
|
334
222
|
require_relative 'logical_value'
|
|
335
223
|
require_relative 'environment'
|
|
224
|
+
require_relative 'callback'
|