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/scicom.rb
CHANGED
data/target/helper.jar
CHANGED
|
Binary file
|
data/test/test_R_interface.rb
CHANGED
data/test/test_array.rb
CHANGED
data/test/test_assign_mdarray.rb
CHANGED
data/test/test_attributes.rb
CHANGED
data/test/test_basic.rb
CHANGED
|
@@ -23,7 +23,7 @@ require 'rubygems'
|
|
|
23
23
|
require "test/unit"
|
|
24
24
|
require 'shoulda'
|
|
25
25
|
|
|
26
|
-
require '
|
|
26
|
+
require '../config' if @platform == nil
|
|
27
27
|
require 'scicom'
|
|
28
28
|
|
|
29
29
|
|
|
@@ -82,9 +82,10 @@ class SciComTest < Test::Unit::TestCase
|
|
|
82
82
|
assert_equal(false, R.na?(R.eval("10.456")).gt)
|
|
83
83
|
|
|
84
84
|
# Use nil in Ruby when needing a NULL in R
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
# Cheching if nil is na returns an empty vector, size 0
|
|
86
|
+
assert_equal(0, R.na?(nil).length.gz)
|
|
87
|
+
|
|
88
|
+
# Does the same thing as above inside an R script
|
|
88
89
|
p "checking if NULL is na"
|
|
89
90
|
R.eval("is.na(NULL)").pp
|
|
90
91
|
|
|
@@ -127,7 +128,8 @@ class SciComTest < Test::Unit::TestCase
|
|
|
127
128
|
# Negative infinite number, equivalent to "-Inf" in R
|
|
128
129
|
p MInf.gz
|
|
129
130
|
|
|
130
|
-
assert_equal(
|
|
131
|
+
assert_equal(true, R.is__infinite(Inf).gt)
|
|
132
|
+
assert_equal(true, R.is__infinite(MInf).gt)
|
|
131
133
|
assert_equal(false, R.finite?(Inf).gt)
|
|
132
134
|
assert_equal(false, R.finite?(MInf).gt)
|
|
133
135
|
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
##########################################################################################
|
|
4
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
|
5
|
+
# and distribute this software and its documentation, without fee and without a signed
|
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
|
8
|
+
# distributions.
|
|
9
|
+
#
|
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
14
|
+
#
|
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
|
19
|
+
# OR MODIFICATIONS.
|
|
20
|
+
##########################################################################################
|
|
21
|
+
|
|
22
|
+
require 'rubygems'
|
|
23
|
+
require "test/unit"
|
|
24
|
+
require 'shoulda'
|
|
25
|
+
|
|
26
|
+
require '../config' if @platform == nil
|
|
27
|
+
require 'scicom'
|
|
28
|
+
|
|
29
|
+
class SciComTest < Test::Unit::TestCase
|
|
30
|
+
|
|
31
|
+
context "R environment" do
|
|
32
|
+
|
|
33
|
+
#--------------------------------------------------------------------------------------
|
|
34
|
+
#
|
|
35
|
+
#--------------------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
setup do
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
#--------------------------------------------------------------------------------------
|
|
42
|
+
#
|
|
43
|
+
#--------------------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
should "callback rpacked classes Array and Hash" do
|
|
46
|
+
|
|
47
|
+
# create an array of data in Ruby
|
|
48
|
+
array = [1, 2, 3]
|
|
49
|
+
|
|
50
|
+
# Pack the array and assign it to an R variable. Remember that ruby__array, becomes
|
|
51
|
+
# ruby.array inside the R script
|
|
52
|
+
R.ruby__array = R.rpack(array)
|
|
53
|
+
|
|
54
|
+
# note that this calls Ruby method 'length' on the array and not R length function.
|
|
55
|
+
R.eval("val <- ruby.array$run('length')")
|
|
56
|
+
assert_equal(3, R.val.gz)
|
|
57
|
+
|
|
58
|
+
# Let's use a more interesting array method '<<'. This method adds elements to the
|
|
59
|
+
# end of the array.
|
|
60
|
+
|
|
61
|
+
R.eval(<<-EOT)
|
|
62
|
+
print(typeof(ruby.array))
|
|
63
|
+
ruby.array$run('<<', 4)
|
|
64
|
+
ruby.array$run('<<', 5)
|
|
65
|
+
EOT
|
|
66
|
+
assert_equal(4, array[3])
|
|
67
|
+
assert_equal(5, array[4])
|
|
68
|
+
|
|
69
|
+
# Although the concept of chainning is foreign to R, it does apply to packed
|
|
70
|
+
# classes
|
|
71
|
+
R.eval(<<-EOT)
|
|
72
|
+
ruby.array$run('<<', 6)$run('<<', 7)$run('<<', 8)$run('<<', 9)
|
|
73
|
+
EOT
|
|
74
|
+
assert_equal(9, array[8])
|
|
75
|
+
|
|
76
|
+
# Let's try another method... remove a given element from the array
|
|
77
|
+
R.eval(<<-EOT)
|
|
78
|
+
ruby.array$run('delete', 4)
|
|
79
|
+
EOT
|
|
80
|
+
assert_equal(5, array[3])
|
|
81
|
+
|
|
82
|
+
# We can also acess any array element inside the R script, but note that we have
|
|
83
|
+
# to use Ruby indexing, i.e., the first element of the array is index 0
|
|
84
|
+
R.eval(<<-EOT)
|
|
85
|
+
print(ruby.array$run('[]', 0))
|
|
86
|
+
print(ruby.array$run('[]', 2))
|
|
87
|
+
print(ruby.array$run('[]', 4))
|
|
88
|
+
print(ruby.array$run('[]', 6))
|
|
89
|
+
EOT
|
|
90
|
+
|
|
91
|
+
# Try the same with a hash
|
|
92
|
+
hh = {"a" => 1, "b" =>2}
|
|
93
|
+
|
|
94
|
+
# Pack the hash and store it in R variable r.hash
|
|
95
|
+
R.r__hash = R.rpack(hh, scope: :external)
|
|
96
|
+
|
|
97
|
+
# Retrieve the value of a key
|
|
98
|
+
R.eval(<<-EOT)
|
|
99
|
+
h1 <- r.hash$run('[]', "a")
|
|
100
|
+
h2 <- r.hash$run('[]', "b")
|
|
101
|
+
EOT
|
|
102
|
+
assert_equal(1, R.h1.gz)
|
|
103
|
+
assert_equal(2, R.h2.gz)
|
|
104
|
+
|
|
105
|
+
# Add values to the hash
|
|
106
|
+
R.eval(<<-EOT)
|
|
107
|
+
h1 <- r.hash$run('[]=', "c", 3)
|
|
108
|
+
h2 <- r.hash$run('[]=', "d", 4)
|
|
109
|
+
EOT
|
|
110
|
+
assert_equal(3, hh["c"])
|
|
111
|
+
assert_equal(4, hh["d"])
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
#--------------------------------------------------------------------------------------
|
|
116
|
+
#
|
|
117
|
+
#--------------------------------------------------------------------------------------
|
|
118
|
+
|
|
119
|
+
should "allow use of Ruby classes and objects inside an R script" do
|
|
120
|
+
|
|
121
|
+
R.eval(<<-EOT)
|
|
122
|
+
# This is an actuall R script, which allows the creation and use of Ruby classes
|
|
123
|
+
# and methods.
|
|
124
|
+
# Create a string, from class String in Ruby. Use function build to intanciate a
|
|
125
|
+
# new object
|
|
126
|
+
string <- Ruby.Object$build("String", "this is a new string")
|
|
127
|
+
|
|
128
|
+
# Use function get_class to get a Ruby class
|
|
129
|
+
Marshal <- Ruby.Object$get_class("Marshal")
|
|
130
|
+
|
|
131
|
+
# Method 'dump' is a Marshal class method as is 'load'
|
|
132
|
+
str <- Marshal$run("dump", string)
|
|
133
|
+
restored <- Marshal$run("load", str)
|
|
134
|
+
EOT
|
|
135
|
+
|
|
136
|
+
assert_equal("this is a new string", R.string.gz)
|
|
137
|
+
assert_equal(Marshal.dump("this is a new string"), R.str.gz)
|
|
138
|
+
assert_equal("this is a new string", R.restored.gz)
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
#--------------------------------------------------------------------------------------
|
|
143
|
+
#
|
|
144
|
+
#--------------------------------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
should "callback all internal elements" do
|
|
147
|
+
|
|
148
|
+
# Create two arrays and store them in a third array
|
|
149
|
+
props1 = [1, 2, 3]
|
|
150
|
+
props2 = [10, 20]
|
|
151
|
+
props = [props1, props2]
|
|
152
|
+
|
|
153
|
+
# rpack the internal's of the container array props, i.e, pack only arrays
|
|
154
|
+
# props1 and props2. Array props is not being packed as Ruby arrays are morphed
|
|
155
|
+
# into R lists. And a list good for what we want. In order to work on R side
|
|
156
|
+
# we store the packed array into variable 'jake'
|
|
157
|
+
R.jake = R.rpack(props, scope: :internal)
|
|
158
|
+
|
|
159
|
+
R.eval(<<-EOT)
|
|
160
|
+
# We want to find the vector with the least elements we have stored. We can use
|
|
161
|
+
# sapply to get the length of all vectors. Although variable 'jake' is a regular
|
|
162
|
+
# R list, it's internal elements are rpacked Ruby objects
|
|
163
|
+
smallest <- which.min(sapply(jake, function(x) x$run("length")))
|
|
164
|
+
|
|
165
|
+
# Remember, the list has only rpacked Ruby objects. To print it, we need to convert
|
|
166
|
+
# it to a string.
|
|
167
|
+
print(jake[[smallest]]$run('to_s'))
|
|
168
|
+
EOT
|
|
169
|
+
|
|
170
|
+
# R.eval("val <- sapply(jake, function(x) x$run('length'))")
|
|
171
|
+
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
end
|
data/test/test_complete.rb
CHANGED
data/test/test_creation.rb
CHANGED
|
@@ -23,7 +23,7 @@ require 'rubygems'
|
|
|
23
23
|
require "test/unit"
|
|
24
24
|
require 'shoulda'
|
|
25
25
|
|
|
26
|
-
require '
|
|
26
|
+
require '../config' if @platform == nil
|
|
27
27
|
require 'scicom'
|
|
28
28
|
|
|
29
29
|
class SciComTest < Test::Unit::TestCase
|
|
@@ -215,10 +215,10 @@ class SciComTest < Test::Unit::TestCase
|
|
|
215
215
|
# Accessing a value outside of the defined vector bound returns a vector with
|
|
216
216
|
# one element, the NA (Not Available)
|
|
217
217
|
na = vec[10]
|
|
218
|
-
assert_equal(
|
|
218
|
+
assert_equal(true, R.is__na(na).gt)
|
|
219
219
|
|
|
220
220
|
# Converting to Ruby will return NaN (Not a Number)
|
|
221
|
-
assert_equal(
|
|
221
|
+
assert_equal(true, (na.gz).nan?)
|
|
222
222
|
|
|
223
223
|
# Method get can be used with an index, to get a given element of a vector
|
|
224
224
|
assert_equal(1, vec.get(0))
|
|
@@ -243,7 +243,7 @@ class SciComTest < Test::Unit::TestCase
|
|
|
243
243
|
vec1.pp
|
|
244
244
|
|
|
245
245
|
# Method length return the number of elements in a vector
|
|
246
|
-
assert_equal(4, vec1.length)
|
|
246
|
+
assert_equal(4, vec1.length.gz)
|
|
247
247
|
# The same can be obtained by calling length in R, but remember that R always returns
|
|
248
248
|
# a vector.
|
|
249
249
|
R.length(vec1).pp
|
|
@@ -258,7 +258,7 @@ class SciComTest < Test::Unit::TestCase
|
|
|
258
258
|
vec2.pp
|
|
259
259
|
|
|
260
260
|
# vec2 has only three elements
|
|
261
|
-
assert_equal(3, vec2.length)
|
|
261
|
+
assert_equal(3, vec2.length.gz)
|
|
262
262
|
|
|
263
263
|
end
|
|
264
264
|
|
|
@@ -294,6 +294,30 @@ class SciComTest < Test::Unit::TestCase
|
|
|
294
294
|
|
|
295
295
|
end
|
|
296
296
|
|
|
297
|
+
#--------------------------------------------------------------------------------------
|
|
298
|
+
#
|
|
299
|
+
#--------------------------------------------------------------------------------------
|
|
300
|
+
|
|
301
|
+
should "create lists" do
|
|
302
|
+
|
|
303
|
+
p "creating list"
|
|
304
|
+
R.eval("lst = c('a', 'b', 'c')")
|
|
305
|
+
R.eval("print(lst)")
|
|
306
|
+
# the returned value is a list
|
|
307
|
+
rb_lst = R.lst
|
|
308
|
+
p "this is the list"
|
|
309
|
+
rb_lst.pp
|
|
310
|
+
|
|
311
|
+
# assign to an R variable the rb_lst returned previously. The original variable
|
|
312
|
+
# is still valid
|
|
313
|
+
R.assign("lst2", rb_lst)
|
|
314
|
+
R.eval("print(lst2)")
|
|
315
|
+
R.lst2 = R.c("new list")
|
|
316
|
+
R.lst.pp
|
|
317
|
+
R.lst2.pp
|
|
318
|
+
|
|
319
|
+
end
|
|
320
|
+
|
|
297
321
|
end
|
|
298
322
|
|
|
299
323
|
end
|
data/test/test_dataframe.rb
CHANGED
data/test/test_factor.rb
CHANGED
data/test/test_functions.rb
CHANGED
|
@@ -23,7 +23,7 @@ require 'rubygems'
|
|
|
23
23
|
require "test/unit"
|
|
24
24
|
require 'shoulda'
|
|
25
25
|
|
|
26
|
-
require '
|
|
26
|
+
require '../config' if @platform == nil
|
|
27
27
|
require 'scicom'
|
|
28
28
|
|
|
29
29
|
|
|
@@ -45,21 +45,24 @@ class SciComTest < Test::Unit::TestCase
|
|
|
45
45
|
|
|
46
46
|
should "keep reference and call R functions" do
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
R.mean(var, trim: 0.10).pp
|
|
51
|
-
|
|
48
|
+
# f contais a reference to the R 'mean' function in the Ruby namespace, not in Renjin
|
|
49
|
+
# namespace. This is actually of type Renjin::Closure
|
|
52
50
|
f = R.eval("mean")
|
|
53
|
-
f.call(R.c(2, 3)).
|
|
54
|
-
f.call(var, trim: 0.10).pp
|
|
51
|
+
assert_equal(2.5, f.call(R.c(2, 3)).gz)
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
# using function 'mean' as parameter
|
|
54
|
+
mean = R.lapply(R.c(2, 3), "mean")
|
|
55
|
+
mean.pp
|
|
58
56
|
|
|
57
|
+
# we can also use function 'f' which was assigned to 'mean'
|
|
58
|
+
mean = R.lapply(R.c(2, 3), f)
|
|
59
|
+
mean.pp
|
|
60
|
+
|
|
61
|
+
=begin
|
|
59
62
|
sum = R.eval("sum")
|
|
60
63
|
dgamma = R.eval("dgamma")
|
|
61
64
|
p dgamma
|
|
62
|
-
|
|
65
|
+
=end
|
|
63
66
|
end
|
|
64
67
|
|
|
65
68
|
end
|
data/test/test_linear_model.rb
CHANGED
data/test/test_list.rb
CHANGED
|
@@ -23,7 +23,7 @@ require 'rubygems'
|
|
|
23
23
|
require "test/unit"
|
|
24
24
|
require 'shoulda'
|
|
25
25
|
|
|
26
|
-
require '
|
|
26
|
+
require '../config' if @platform == nil
|
|
27
27
|
require 'scicom'
|
|
28
28
|
|
|
29
29
|
class SciComTest < Test::Unit::TestCase
|
|
@@ -48,6 +48,9 @@ class SciComTest < Test::Unit::TestCase
|
|
|
48
48
|
@trth_vec2 = R.c(FALSE, FALSE)
|
|
49
49
|
@gl = R.gl(2, 3)
|
|
50
50
|
|
|
51
|
+
# names is a Ruby array
|
|
52
|
+
@names = ["Lisa", "Teasha", "Aaron", "Thomas"]
|
|
53
|
+
|
|
51
54
|
end
|
|
52
55
|
|
|
53
56
|
#--------------------------------------------------------------------------------------
|
|
@@ -93,7 +96,12 @@ class SciComTest < Test::Unit::TestCase
|
|
|
93
96
|
assert_equal("character", @x[["second"]].typeof.gz)
|
|
94
97
|
assert_equal("yes", @x[["second"]][1].gz)
|
|
95
98
|
assert_equal(2, @x[["fourth"]][4].gz)
|
|
96
|
-
|
|
99
|
+
|
|
100
|
+
assert_equal("first", @x.names[1].gz)
|
|
101
|
+
assert_equal("second", @x.names[2].gz)
|
|
102
|
+
assert_equal("third", @x.names[3].gz)
|
|
103
|
+
assert_equal("fourth", @x.names[4].gz)
|
|
104
|
+
|
|
97
105
|
end
|
|
98
106
|
|
|
99
107
|
#--------------------------------------------------------------------------------------
|
|
@@ -173,25 +181,56 @@ class SciComTest < Test::Unit::TestCase
|
|
|
173
181
|
|
|
174
182
|
end
|
|
175
183
|
|
|
184
|
+
#--------------------------------------------------------------------------------------
|
|
185
|
+
# Assign a Ruby array to R. The array is converted into a list.
|
|
186
|
+
#--------------------------------------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
should "be able to assign a Ruby array to R" do
|
|
189
|
+
|
|
190
|
+
# Ruby Arrays can be used as arguments to R functions. A Ruby Array will be
|
|
191
|
+
# converted to an R list.
|
|
192
|
+
people = R.identity(@names)
|
|
193
|
+
|
|
194
|
+
# Indexing of lists can be done by [x] or [[x]]. The first indexing still returns a
|
|
195
|
+
# list while the latter returns an element of the list. In the latter case we can
|
|
196
|
+
# use gz to retrieve the value of the element, on the first case, gz does not work
|
|
197
|
+
# as we cannot get convert the first element of a list to a Ruby value.
|
|
198
|
+
assert_equal("Lisa", people[[1]].gz)
|
|
199
|
+
assert_equal("Teasha", people[[2]].gz)
|
|
200
|
+
assert_equal("Aaron", people[[3]].gz)
|
|
201
|
+
assert_equal("Thomas", people[[4]].gz)
|
|
202
|
+
|
|
203
|
+
assert_equal(true, (R.list("Lisa")._ :in, people[1]).gt)
|
|
204
|
+
assert_equal(false, (R.list("Lisa")._ :in, people[2]).gt)
|
|
205
|
+
|
|
206
|
+
end
|
|
207
|
+
|
|
176
208
|
#--------------------------------------------------------------------------------------
|
|
177
209
|
#
|
|
178
210
|
#--------------------------------------------------------------------------------------
|
|
179
211
|
|
|
180
|
-
should "
|
|
212
|
+
should "unlist a list" do
|
|
181
213
|
|
|
182
|
-
|
|
183
|
-
|
|
214
|
+
people = R.convert(@names)
|
|
215
|
+
vec = people.unlist
|
|
216
|
+
assert_equal("Lisa", vec[1].gz)
|
|
217
|
+
assert_equal("Teasha", vec[2].gz)
|
|
218
|
+
assert_equal("Aaron", vec[3].gz)
|
|
219
|
+
assert_equal("Thomas", vec[4].gz)
|
|
184
220
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
#--------------------------------------------------------------------------------------
|
|
224
|
+
#
|
|
225
|
+
#--------------------------------------------------------------------------------------
|
|
226
|
+
|
|
227
|
+
should "assign values to Ruby variables and R variables" do
|
|
189
228
|
|
|
190
229
|
# If a Ruby Array is assigned to an R variable, this R variable is a list. Note
|
|
191
230
|
# that variable 'people' above and variable 'R.people' are two different variables.
|
|
192
231
|
# While the first is defined in the Ruby environment, the second is defined in
|
|
193
232
|
# R environment.
|
|
194
|
-
R.people = names
|
|
233
|
+
R.people = @names
|
|
195
234
|
R.people.pp
|
|
196
235
|
|
|
197
236
|
R.lst = [1, 2, 3, 4, 5, 6]
|