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.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +239 -55
  3. data/Rakefile +58 -5
  4. data/config.rb +34 -2
  5. data/doc/Array.html +153 -0
  6. data/doc/Java/OrgRenjinSexp/LogicalArrayVector.html +120 -0
  7. data/doc/Java/OrgRenjinSexp/StringArrayVector.html +133 -0
  8. data/doc/Java/RbScicom/MDDoubleVector.html +133 -0
  9. data/doc/MDArray.html +153 -0
  10. data/doc/MergeObservable.html +347 -0
  11. data/doc/NegRange.html +166 -0
  12. data/doc/PackageManager.html +823 -0
  13. data/doc/PackageManager/ParseXML.html +595 -0
  14. data/doc/Range.html +243 -0
  15. data/doc/Renjin.html +2210 -0
  16. data/doc/Renjin/Attributes.html +401 -0
  17. data/doc/Renjin/Closure.html +181 -0
  18. data/doc/Renjin/ComplexVector.html +557 -0
  19. data/doc/Renjin/DataFrame.html +258 -0
  20. data/doc/Renjin/Environment.html +279 -0
  21. data/doc/Renjin/Function.html +243 -0
  22. data/doc/Renjin/Index.html +628 -0
  23. data/doc/Renjin/List.html +398 -0
  24. data/doc/Renjin/Logical.html +352 -0
  25. data/doc/Renjin/Primitive.html +181 -0
  26. data/doc/Renjin/RBSexp.html +1151 -0
  27. data/doc/Renjin/RubySexp.html +498 -0
  28. data/doc/Renjin/Vector.html +3163 -0
  29. data/doc/RinRuby.html +2079 -0
  30. data/doc/_index.html +365 -0
  31. data/doc/class_list.html +58 -0
  32. data/doc/css/common.css +1 -0
  33. data/doc/css/full_list.css +57 -0
  34. data/doc/css/style.css +339 -0
  35. data/doc/file.README.html +159 -0
  36. data/doc/file_list.html +60 -0
  37. data/doc/frames.html +26 -0
  38. data/doc/index.html +159 -0
  39. data/doc/js/app.js +219 -0
  40. data/doc/js/full_list.js +181 -0
  41. data/doc/js/jquery.js +4 -0
  42. data/doc/method_list.html +939 -0
  43. data/doc/top-level-namespace.html +679 -0
  44. data/lib/JRubyR/attributes.rb +5 -2
  45. data/lib/JRubyR/callback.rb +115 -0
  46. data/lib/JRubyR/environment.rb +0 -1
  47. data/lib/JRubyR/indexed.rb +139 -0
  48. data/lib/JRubyR/list.rb +0 -16
  49. data/lib/JRubyR/logical_value.rb +0 -1
  50. data/lib/JRubyR/rbsexp.rb +20 -131
  51. data/lib/JRubyR/renjin.rb +201 -71
  52. data/lib/JRubyR/vector.rb +16 -15
  53. data/lib/scicom.rb +1 -3
  54. data/target/helper.jar +0 -0
  55. data/test/test_R_interface.rb +1 -1
  56. data/test/test_array.rb +1 -1
  57. data/test/test_assign_mdarray.rb +1 -1
  58. data/test/test_assign_mdarray_2d.rb +1 -1
  59. data/test/test_assign_mdarray_3d.rb +1 -1
  60. data/test/test_attributes.rb +1 -1
  61. data/test/test_basic.rb +7 -5
  62. data/test/test_callback.rb +176 -0
  63. data/test/test_complete.rb +1 -1
  64. data/test/test_creation.rb +29 -5
  65. data/test/test_dataframe.rb +1 -1
  66. data/test/test_factor.rb +1 -1
  67. data/test/test_functions.rb +13 -10
  68. data/test/test_linear_model.rb +1 -1
  69. data/test/test_list.rb +49 -10
  70. data/test/test_matrix.rb +6 -6
  71. data/test/test_operators.rb +1 -1
  72. data/test/test_package.rb +5 -5
  73. data/test/test_vector.rb +13 -7
  74. data/vendor/aether-api-1.0.2.v20150114.jar +0 -0
  75. data/vendor/aether-connector-basic-1.0.2.v20150114.jar +0 -0
  76. data/vendor/aether-impl-1.0.2.v20150114.jar +0 -0
  77. data/vendor/aether-spi-1.0.2.v20150114.jar +0 -0
  78. data/vendor/aether-transport-file-1.0.2.v20150114.jar +0 -0
  79. data/vendor/aether-transport-http-1.0.2.v20150114.jar +0 -0
  80. data/vendor/aether-util-1.0.2.v20150114.jar +0 -0
  81. data/vendor/aopalliance-1.0.jar +0 -0
  82. data/vendor/asm-3.3.1.jar +0 -0
  83. data/vendor/asm-5.0.4.jar +0 -0
  84. data/vendor/asm-commons-5.0.4.jar +0 -0
  85. data/vendor/asm-tree-5.0.4.jar +0 -0
  86. data/vendor/asm-util-5.0.4.jar +0 -0
  87. data/vendor/blas-0.8.jar +0 -0
  88. data/vendor/cdi-api-1.0.jar +0 -0
  89. data/vendor/codemodel-2.6.jar +0 -0
  90. data/vendor/collections-generic-4.01.jar +0 -0
  91. data/vendor/commons-codec-1.6.jar +0 -0
  92. data/vendor/commons-compress-1.4.1.jar +0 -0
  93. data/vendor/commons-logging-1.1.1.jar +0 -0
  94. data/vendor/commons-math-2.2.jar +0 -0
  95. data/vendor/commons-vfs2-2.0.jar +0 -0
  96. data/vendor/datasets-0.8.1891.jar +0 -0
  97. data/vendor/f2jutil-0.8.jar +0 -0
  98. data/vendor/gcc-runtime-0.8.1891.jar +0 -0
  99. data/vendor/grDevices-0.8.1891.jar +0 -0
  100. data/vendor/graphics-0.8.1891.jar +0 -0
  101. data/vendor/guava-17.0.jar +0 -0
  102. data/vendor/httpclient-4.2.6.jar +0 -0
  103. data/vendor/httpcore-4.2.5.jar +0 -0
  104. data/vendor/javax.inject-1.jar +0 -0
  105. data/vendor/jcl-over-slf4j-1.6.2.jar +0 -0
  106. data/vendor/joda-time-2.0.jar +0 -0
  107. data/vendor/jsr250-api-1.0.jar +0 -0
  108. data/vendor/jtransforms-2.4.jar +0 -0
  109. data/vendor/jung-api-2.0.1.jar +0 -0
  110. data/vendor/jung-graph-impl-2.0.1.jar +0 -0
  111. data/vendor/lapack-0.8.jar +0 -0
  112. data/vendor/maven-aether-provider-3.1.0.jar +0 -0
  113. data/vendor/maven-model-3.1.0.jar +0 -0
  114. data/vendor/maven-model-builder-3.1.0.jar +0 -0
  115. data/vendor/maven-repository-metadata-3.1.0.jar +0 -0
  116. data/vendor/maven-scm-api-1.4.jar +0 -0
  117. data/vendor/maven-scm-provider-svn-commons-1.4.jar +0 -0
  118. data/vendor/maven-scm-provider-svnexe-1.4.jar +0 -0
  119. data/vendor/maven-settings-3.1.0.jar +0 -0
  120. data/vendor/maven-settings-builder-3.1.0.jar +0 -0
  121. data/vendor/methods-0.8.1891.jar +0 -0
  122. data/vendor/netlib-java-0.9.3-renjin-patched-2.jar +0 -0
  123. data/vendor/org.eclipse.sisu.inject-0.0.0.M2a.jar +0 -0
  124. data/vendor/org.eclipse.sisu.plexus-0.0.0.M2a.jar +0 -0
  125. data/vendor/plexus-cipher-1.4.jar +0 -0
  126. data/vendor/plexus-classworlds-2.4.jar +0 -0
  127. data/vendor/plexus-component-annotations-1.5.5.jar +0 -0
  128. data/vendor/plexus-interpolation-1.16.jar +0 -0
  129. data/vendor/plexus-sec-dispatcher-1.3.jar +0 -0
  130. data/vendor/plexus-utils-1.5.6.jar +0 -0
  131. data/vendor/plexus-utils-3.0.10.jar +0 -0
  132. data/vendor/regexp-1.3.jar +0 -0
  133. data/vendor/renjin-aether-package-loader-0.8.1891.jar +0 -0
  134. data/vendor/renjin-appl-0.8.1891.jar +0 -0
  135. data/vendor/renjin-core-0.8.1891.jar +0 -0
  136. data/vendor/renjin-gnur-runtime-0.8.1891.jar +0 -0
  137. data/vendor/renjin-script-engine-0.8.1891.jar +0 -0
  138. data/vendor/sisu-guice-3.1.0-no_aop.jar +0 -0
  139. data/vendor/slf4j-api-1.6.2.jar +0 -0
  140. data/vendor/stats-0.8.1891.jar +0 -0
  141. data/vendor/utils-0.8.1891.jar +0 -0
  142. data/vendor/xerbla-0.8.jar +0 -0
  143. data/vendor/xz-1.0.jar +0 -0
  144. data/version.rb +1 -1
  145. metadata +229 -127
  146. data/cran/AppliedPredictiveModeling.jar +0 -0
  147. data/cran/AppliedPredictiveModeling.xml +0 -25
  148. data/cran/AssetPricing.jar +0 -0
  149. data/cran/AssetPricing.xml +0 -25
  150. data/lib/env.rb +0 -12
  151. data/lib/rinruby.rb +0 -795
  152. data/test/env.rb +0 -2
  153. data/test/test_tmp.rb +0 -67
  154. data/vendor/Renjin.pdf +0 -0
  155. data/vendor/renjin-script-engine-0.7.0-RC7-SNAPSHOT-jar-with-dependencies.jar +0 -0
@@ -23,7 +23,5 @@
23
23
 
24
24
  require 'mdarray'
25
25
 
26
- require_relative 'env'
26
+ require_relative '../config'
27
27
  require_relative 'JRubyR/renjin'
28
-
29
-
Binary file
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  class SciComTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  class SciComTest < Test::Unit::TestCase
@@ -24,7 +24,7 @@ require 'test/unit'
24
24
  require 'shoulda'
25
25
  require 'benchmark'
26
26
 
27
- require 'env'
27
+ require '../config' if @platform == nil
28
28
  require 'scicom'
29
29
 
30
30
  class SciComTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  class SciComTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  class SciComTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  class SciComTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
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
- p "R prints Warning message when is.na is applied to a value and not a vector: "
86
- #assert_equal(0, R.length(R.na?(nil).gt))
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(Inf, Inf)
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
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  require_relative 'test_R_interface'
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
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(NA, na)
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(NaN, na.gz)
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
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  class SciComTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  class SciComTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
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
- var = R.c((0..10), 50)
49
- R.mean(var).pp
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)).pp
54
- f.call(var, trim: 0.10).pp
51
+ assert_equal(2.5, f.call(R.c(2, 3)).gz)
55
52
 
56
- ff = R.d("mean")
57
- ff.call(var, trim: 0.10).pp
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
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
26
+ require '../config' if @platform == nil
27
27
  require 'scicom'
28
28
 
29
29
  class SciComTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ require 'rubygems'
23
23
  require "test/unit"
24
24
  require 'shoulda'
25
25
 
26
- require 'env'
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 "be able to assign a Ruby array to R (not really recommended)" do
212
+ should "unlist a list" do
181
213
 
182
- # names is a Ruby array
183
- names = ["Lisa", "Teasha", "Aaron", "Thomas"]
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
- # Ruby Arrays can be used as arguments to R functions. An Ruby Array will be
186
- # converted to an R list.
187
- people = R.identity(names)
188
- people.pp
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]