galaaz 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +696 -270
  3. data/Rakefile +9 -22
  4. data/bin/gknit +2 -217
  5. data/bin/gknit_old_r +236 -0
  6. data/bin/grun +5 -0
  7. data/blogs/dev/dev.Rmd +7 -0
  8. data/blogs/dev/dev.html +34 -26
  9. data/blogs/dev/dev.md +40 -25
  10. data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
  11. data/blogs/dev/dev_files/figure-html/diverging_bar. +0 -0
  12. data/blogs/dev/dev_files/figure-html/diverging_bar.png +0 -0
  13. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +4 -4
  14. data/blogs/galaaz_ggplot/galaaz_ggplot.html +251 -59
  15. data/blogs/galaaz_ggplot/galaaz_ggplot.log +640 -0
  16. data/blogs/galaaz_ggplot/galaaz_ggplot.md +199 -95
  17. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +45 -228
  18. data/blogs/galaaz_ggplot/midwest.png +0 -0
  19. data/blogs/galaaz_ggplot/scatter_plot.png +0 -0
  20. data/blogs/gknit/gknit.Rmd +271 -148
  21. data/blogs/manual/manual.Rmd +212 -0
  22. data/blogs/manual/manual.html +1832 -0
  23. data/blogs/manual/manual.md +751 -0
  24. data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
  25. data/blogs/ruby_plot/ruby_plot.Rmd +5 -69
  26. data/blogs/ruby_plot/ruby_plot.html +195 -236
  27. data/blogs/ruby_plot/ruby_plot.md +1 -261
  28. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +38 -38
  29. data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +5 -5
  30. data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +1 -0
  31. data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +3 -7
  32. data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +3 -1
  33. data/lib/R_interface/r.rb +12 -9
  34. data/lib/R_interface/r_methods.rb +2 -2
  35. data/lib/R_interface/rbinary_operators.rb +2 -20
  36. data/lib/R_interface/rdata_frame.rb +56 -9
  37. data/lib/R_interface/rdevices.R +0 -12
  38. data/lib/R_interface/rexpression.rb +0 -97
  39. data/lib/R_interface/rindexed_object.rb +12 -3
  40. data/lib/R_interface/rlanguage.rb +1 -1
  41. data/lib/R_interface/rlist.rb +29 -4
  42. data/lib/R_interface/rlogical_operators.rb +50 -0
  43. data/lib/R_interface/rmatrix.rb +7 -1
  44. data/lib/R_interface/robject.rb +29 -15
  45. data/lib/R_interface/rsupport.rb +74 -58
  46. data/lib/R_interface/rsymbol.rb +2 -1
  47. data/lib/R_interface/ruby_extensions.rb +11 -2
  48. data/lib/R_interface/rvector.rb +26 -11
  49. data/lib/gknit.rb +2 -0
  50. data/lib/gknit/include_engine.rb +57 -0
  51. data/lib/gknit/knitr_engine.rb +596 -50
  52. data/lib/gknit/rb_engine.rb +56 -0
  53. data/lib/gknit/ruby_engine.rb +13 -36
  54. data/lib/util/exec_ruby.rb +132 -21
  55. data/lib/util/inline_file.rb +9 -7
  56. data/specs/all.rb +5 -0
  57. data/specs/figures/bg.jpeg +0 -0
  58. data/specs/figures/bg.png +0 -0
  59. data/specs/figures/bg.svg +57 -0
  60. data/specs/figures/no_args.jpeg +0 -0
  61. data/specs/figures/no_args.png +0 -0
  62. data/specs/figures/no_args.svg +57 -0
  63. data/specs/figures/width_height.jpeg +0 -0
  64. data/specs/figures/width_height.png +0 -0
  65. data/specs/figures/width_height_units1.jpeg +0 -0
  66. data/specs/figures/width_height_units1.png +0 -0
  67. data/specs/figures/width_height_units2.jpeg +0 -0
  68. data/specs/figures/width_height_units2.png +0 -0
  69. data/specs/r_dataframe.spec.rb +29 -27
  70. data/specs/r_devices.spec.rb +347 -0
  71. data/specs/r_eval.spec.rb +10 -3
  72. data/specs/r_formula.spec.rb +2 -2
  73. data/specs/r_language.spec.rb +112 -0
  74. data/specs/r_list.spec.rb +174 -14
  75. data/specs/r_list_apply.spec.rb +17 -10
  76. data/specs/r_matrix.spec.rb +3 -3
  77. data/specs/r_vector_operators.spec.rb +13 -7
  78. data/specs/tmp.rb +42 -12
  79. data/version.rb +1 -1
  80. metadata +28 -24
  81. data/bin/gknit2 +0 -14
  82. data/bin/prepareR.rb +0 -3
  83. data/bin/tmp.py +0 -51
  84. data/blogs/gknit/gknit.html +0 -528
  85. data/blogs/gknit/gknit.md +0 -628
  86. data/blogs/gknit/gknit.pdf +0 -0
  87. data/blogs/gknit/gknit.tex +0 -745
  88. data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
  89. data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
  90. data/blogs/ruby_plot/figures/dose_len.png +0 -0
  91. data/blogs/ruby_plot/figures/facet_by_delivery.png +0 -0
  92. data/blogs/ruby_plot/figures/facet_by_dose.png +0 -0
  93. data/blogs/ruby_plot/figures/facets_by_delivery_color.png +0 -0
  94. data/blogs/ruby_plot/figures/facets_by_delivery_color2.png +0 -0
  95. data/blogs/ruby_plot/figures/facets_with_decorations.png +0 -0
  96. data/blogs/ruby_plot/figures/facets_with_jitter.png +0 -0
  97. data/blogs/ruby_plot/figures/facets_with_points.png +0 -0
  98. data/blogs/ruby_plot/figures/final_box_plot.png +0 -0
  99. data/blogs/ruby_plot/figures/final_violin_plot.png +0 -0
  100. data/blogs/ruby_plot/figures/violin_with_jitter.png +0 -0
  101. data/lib/R/eng_ruby.R +0 -62
  102. data/lib/R_interface/rdevices.rb +0 -225
@@ -49,7 +49,7 @@ describe R::Language do
49
49
  expect(rform.rclass).to eq 'formula'
50
50
  end
51
51
 
52
- it "should create a formula with '.' by using the ':all' keyword in the rhs" do
52
+ it "should create a formula with '.' in the rhs" do
53
53
  formula = R.formula("supp ~ .")
54
54
  expect(formula.to_s.lines.first.chomp).to eq "supp ~ ."
55
55
 
@@ -77,7 +77,7 @@ describe R::Language do
77
77
  expect(formula.to_s.lines.first.chomp).to eq "~supp"
78
78
 
79
79
  formula = :all.til :supp
80
- expect(formula.to_s.lines.first.chomp).to eq " ~ supp"
80
+ expect(formula.to_s.lines.first.chomp).to eq "~supp"
81
81
  expect(formula.rclass).to eq "formula"
82
82
  expect(formula.typeof).to eq "language"
83
83
  end
@@ -0,0 +1,112 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2018 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 'galaaz'
25
+
26
+ describe R::Language do
27
+
28
+ #========================================================================================
29
+ context "Working with symbols" do
30
+
31
+ it "should convert a Ruby Symbol to an R Symbol with '+'" do
32
+ a = +:cyl
33
+ expect(a.is_a? R::RSymbol).to eq true
34
+ expect(a.to_s).to eq "cyl"
35
+ end
36
+
37
+ it "should assign to an R symbol and retrieve from it" do
38
+ R.cyl = 10
39
+ expect(~:cyl).to eq 10
40
+ end
41
+
42
+ it "should allow calling evaluate on the symbol" do
43
+ R.cyl = 10
44
+ expect(R.eval(~:cyl)).to eq 10
45
+ end
46
+
47
+ end
48
+
49
+ #========================================================================================
50
+
51
+ context "Executing R expressions" do
52
+
53
+ it "should eval an R expression in the context of a list" do
54
+ ct = R.list(a: 10, b: 20, c: 30)
55
+ exp = :a + :b * :c
56
+ expect(R.eval(exp, ct)).to eq 610
57
+ end
58
+
59
+ it "should eval an R function in the context of a list" do
60
+ R.x = 5
61
+ expect(R.eval(:x + 10)).to eq 15
62
+ ct = R.list(x: 20)
63
+ expect(R.eval(:x + 10, ct)).to eq 30
64
+ end
65
+
66
+ end
67
+
68
+
69
+ #========================================================================================
70
+ context "When working with Formulas" do
71
+ # When working with formulas, Ruby symbols such be preceded by the '+' function.
72
+ # If you want to make a formula such as 'a ~ b' in R, then this should be written
73
+ # as '+:a =~ +:b'. When, in an binary operation, the Ruby symbol will be converted
74
+ # to an R symbol. The formula '+:a =~ +:b', can also be written as '+:a =~ :b'. Be
75
+ # careful, however, when using the Ruby symbol without the '+' since in a more complex
76
+ # formula, Ruby's precedence rules might not result in what is expected. As an example
77
+ # '+:a =~ :b * +:c' crashes with the error 'b' not found, since '*' has precedence over
78
+ # '=~' and this is equivalent to '+:a =~ (:b * +:c)' and there is no sense in
79
+ # multiplying a Ruby symbol. The recomendation is to always use the '+' function
80
+ # before the Ruby symbol.
81
+
82
+ it "should create a RSymbol from a Ruby Symbol using +" do
83
+ sym = +:sym
84
+ expect(sym.to_s).to eq "sym"
85
+ end
86
+
87
+ =begin
88
+
89
+ it "should create a formula without the lhs" do
90
+ pending "formulas need to be reimplemented"
91
+ formula = ~(:cyl + :exp)
92
+ expect formula.to_s == '~.Primitive("+")(cyl, exp)'
93
+ expect formula.typeof == 'language'
94
+ expect formula.rclass == 'formula'
95
+ end
96
+
97
+ it "should create formulas with the '=~' operator" do
98
+ formula = (:cyl =~ :exp)
99
+ expect(formula.to_s) == '.Primitive("~")(cyl, exp)'
100
+ expect formula.typeof == 'language'
101
+ expect formula.rclass == 'formula'
102
+
103
+ formula2 = (:cyl =~ :exp + :exp2 - :exp3)
104
+ expect formula2.to_s == 'cyl ~ .Primitive("-")(.Primitive("+")(exp, exp2), exp3)'
105
+ expect formula.typeof == 'language'
106
+ expect formula.rclass == 'formula'
107
+ end
108
+ =end
109
+
110
+ end
111
+
112
+ end
@@ -59,31 +59,103 @@ describe R::List do
59
59
  end
60
60
 
61
61
  #----------------------------------------------------------------------------------------
62
- context "When subsetting a list" do
62
+ context "When subsetting a list with '<<' (starts at 0)" do
63
63
 
64
- before(:all) do
65
- @l = R.list(1, 2, 3, R.list(4, 5, 6))
64
+ before(:each) do
65
+ @l = R.list(1, a: 2, b: 3, c: R.list(4, 5, 6))
66
+ end
67
+
68
+ it "should return the 'native' (Ruby) element of the list at numeric index" do
69
+ expect(@l >> 0).to eq 1
70
+ expect(@l >> 1).to eq 2
71
+ expect(@l >> 2).to eq 3
72
+ end
73
+
74
+ it "should return the 'native' (Ruby) element of the list at named index" do
75
+ expect(@l['a'] >> 0).to eq 2
76
+ expect(@l[['a']] >> 0).to eq 2
77
+ expect(@l['b'] >> 0).to eq 3
78
+ end
79
+
80
+ it "should raise an exception (IndexError) if index out of bounds" do
81
+ expect { @l >> 4 }.to raise_error(IndexError)
82
+ end
83
+
84
+ it "should raise an exception (Argument error) if indexed element is not a vector" do
85
+ expect { @l >> 3 }.to raise_error(ArgumentError)
86
+ end
87
+
88
+ it "should return nil if named index does not exists" do
89
+ expect(@l['k'] >> 0).to eq nil
90
+ end
91
+
92
+ end
93
+
94
+ #----------------------------------------------------------------------------------------
95
+ context "When subsetting a list with '['" do
96
+
97
+ before(:each) do
98
+ # the 'all' keywork means 'empty', so this is a list of the form
99
+ # list(a = 1, b = 2, list(c = 3))... note that the 3rd element of the
100
+ # list has no name. In Ruby, doing R.list(a: 1, b: 2, R.list(c: 3)) is
101
+ # a syntax error, since named parameters need to come at the end of the
102
+ # parameter list. To fix that we do: R.list(a: 1, b: 2, all: R.list(c: 3))
103
+ # However, note that we cannot have two identical named parameters in a
104
+ # function call, as Ruby will detect it as an error and pass only one of
105
+ # the named parameters and not both.
106
+
107
+ # The following list has only 3 elements and not 4 since the 'all' parameter
108
+ # was used twice. This is a limitation of Ruby
109
+ @l = R.list(a: 1, b: 2, all: 3, all: R.list(i: 4, j: 5, all: 6))
110
+
111
+ # This list has 4 elements.
112
+ @l1 = R.list(a: 1, b: 2, all: 3, d: R.list(i: 4, j: 5, all: 6))
113
+
114
+ # if possible, change the order of the list with unamed parameters first.
115
+ # Although clearly those lists are different, named parameters can still
116
+ # be recovered by name
117
+ @l2 = R.list(3, R.list(6, i:4, j: 5), a: 1, b: 2)
118
+ end
119
+
120
+ it "should allow accessing parameters named with 'all' by position" do
121
+ expect(@l.length).to eq 3
122
+ # Note that the first 'all' parameter was droped. Don't know if this
123
+ # is implementation dependend, but in TruffleRuby that's the way it is
124
+ # (at least for now).
125
+ expect(@l[[3]]).to eq R.list(i:4, j: 5, all: 6)
66
126
  end
67
127
 
68
128
  it "should subset with [] and positve integer. Returns a list" do
69
- expect(@l.length).to eq 4
129
+ expect(@l1.length).to eq 4
70
130
  # Subsetting a list with [] returns a list
71
- expect(@l[1].identical(R.list(1))).to eq true
72
- # the 4th element of the list is a list of a list
73
- expect(@l[4].identical(R.list(R.list(4, 5, 6)))).to eq true
131
+ expect(@l1[1]).to eq R.list(a: 1)
132
+ expect(@l1[1] == R.c(a: 1)).to eq false
133
+ expect(@l1[1]).not_to eq R.c(a: 1)
134
+
135
+ # the 4th element of the list is another list
136
+ expect(@l1[4]).to eq R.list(d: R.list(i: 4, j: 5, all: 6))
74
137
  end
75
138
 
76
139
  it "should subset with [] and negative integer. Returns a list" do
77
- expect(@l[-4].identical(R.list(1, 2, 3))).to eq true
140
+ expect(@l1[-4] == R.list(a: 1, b: 2, all: 3)).to eq true
78
141
  end
79
142
 
80
143
  it "should subset with [] and a vector as index" do
81
- expect(@l[R.c(4, 1)].identical(R.list(R.list(4, 5, 6), 1))).to eq true
144
+ expect(@l1[R.c(4, 1)] == R.list(d: R.list(i: 4, j: 5, all: 6), a: 1)).to eq true
82
145
  end
83
-
146
+
84
147
  it "should raise an exception when index dimension is wrong" do
85
148
  expect { @l[4, 1] }.to raise_error(ArgumentError)
86
149
  end
150
+
151
+ end
152
+
153
+ #----------------------------------------------------------------------------------------
154
+ context "When subsetting a list with '[['" do
155
+
156
+ before(:each) do
157
+ @l = R.list(1, 2, 3, R.list(4, 5, 6))
158
+ end
87
159
 
88
160
  it "should subset with [[]] and positive integer. Returns the actual element of the list" do
89
161
  # to extract an element of a list we need double square (dbk) indexing
@@ -106,13 +178,40 @@ describe R::List do
106
178
  expect(@l[[4, 1]]).to eq 4
107
179
  end
108
180
 
181
+ end
182
+
183
+ #----------------------------------------------------------------------------------------
184
+ context "When subsetting a list with '.'" do
185
+
186
+ before(:each) do
187
+ # This list has 4 elements.
188
+ @l1 = R.list(a: 1, b: 2, all: 3, d: R.list(i: 4, j: 5, all: 6))
189
+ end
190
+
191
+ it "should access named elements with '.<name>'" do
192
+ # access with '.' is equivalent to access with '[[
193
+ expect(@l1.a == R.c(1)).to eq true
194
+ expect(@l1.a).to eq 1
195
+ expect(@l1.b).to eq 2
196
+ expect(@l1.d == R.list(i: 4, j: 5, all: 6)).to eq true
197
+ end
198
+
199
+ end
200
+
201
+ #----------------------------------------------------------------------------------------
202
+ context "When subsetting a list with 'each' and 'each_with_index'" do
203
+
204
+ before(:each) do
205
+ @l = R.list(1, 2, 3, R.list(4, 5, 6))
206
+ end
207
+
109
208
  it "should subset with 'each' returning every element as if subsetting with '[['" do
110
209
  i = 1
111
210
  @l.each do |elmt|
112
211
  if (i < 4)
113
- expect elmt == i
212
+ expect(elmt).to eq i
114
213
  else
115
- expect elmt.identical(R.list(4, 5, 6)) == true
214
+ expect(elmt.identical(R.list(4, 5, 6))).to eq true
116
215
  end
117
216
  i = i + 1
118
217
  end
@@ -121,13 +220,74 @@ describe R::List do
121
220
  it "should subset with 'each_with_index'" do
122
221
  @l.each_with_index do |elmt, i|
123
222
  if (i < 4)
124
- expect elmt == i
223
+ expect(elmt).to eq i
125
224
  else
126
- expect elmt.identical(R.list(4, 5, 6)) == true
225
+ expect(elmt.identical(R.list(4, 5, 6))).to eq true
127
226
  end
128
227
  end
129
228
  end
130
229
 
131
230
  end
132
231
 
232
+ #----------------------------------------------------------------------------------------
233
+ context "When modifying a list" do
234
+
235
+ before(:each) do
236
+ @l = R.list(a: 1, b: 2, c: 3, d: R.list(i: 4, j: 5, k: 6))
237
+ end
238
+
239
+ it "should be possible to modify a list by index" do
240
+ @l[[1]] = 10
241
+ expect(@l.length).to eq 4
242
+ expect(@l[[1]]).to eq 10
243
+ end
244
+
245
+ it "should be possible to modify a list by element name in '[[" do
246
+ @l[['a']] = 10
247
+ expect(@l[['a']]).to eq 10
248
+ expect(@l.a).to eq 10
249
+ end
250
+
251
+ it "should be possible to modify a list by element name with '.'" do
252
+ @l.b = 20
253
+ expect(@l[['b']]).to eq 20
254
+ expect(@l.b).to eq 20
255
+ end
256
+
257
+ it "should be possible to add an element to the list with '[[" do
258
+ @l[['married']] = true
259
+ expect(@l.length).to eq 5
260
+ expect(@l[['married']]).to eq true
261
+ expect(@l.married).to eq true
262
+ end
263
+
264
+ it "should be possible to add an element to the list with '.'" do
265
+ @l.married = true
266
+ expect(@l.length).to eq 5
267
+ expect(@l[['married']]).to eq true
268
+ expect(@l.married).to eq true
269
+
270
+ @l.number = 5.345
271
+ @l.lst = R.list(100, 200)
272
+ @l.vec = R.c(500, 600)
273
+
274
+ expect(@l.length).to eq 8
275
+ expect(@l.vec).to eq R.c(500, 600)
276
+ expect(@l.vec).not_to eq R.c(1000)
277
+ end
278
+
279
+ it "should be possible to remove an element from a list by assigning 'nil' to it" do
280
+ @l[['d']] = nil
281
+ expect(@l.length).to eq 3
282
+ expect(@l).to eq R.list(a: 1, b: 2, c: 3)
283
+ end
284
+
285
+ it "should be possible to remove an element from a list by assigning 'nil' with '.'" do
286
+ @l.d = nil
287
+ expect(@l.length).to eq 3
288
+ expect(@l).to eq R.list(a: 1, b: 2, c: 3)
289
+ end
290
+
291
+ end
292
+
133
293
  end
@@ -58,29 +58,36 @@ describe R::List do
58
58
  # lapply applies a function to each element of a list or vector, returning a list.
59
59
  # median and quartiles for each list element
60
60
  quant = R.lapply(@x, @q)
61
- expect(quant.a[1]).to eq 1
62
- expect(quant.a["50,00000%"]).to eq 5.50
61
+ expect(quant.a[1] == R.c('0%': 1.0)).to eq true
62
+ expect(quant.a[1]).to eq R.c('0%': 1.0)
63
+ expect(quant.a[[1]]).to eq 1.0
64
+
65
+ expect(quant.a[["50%"]]).to eq 5.50
66
+ expect(quant.a['50%']).to eq R.c('50%': 5.50)
63
67
  expect(R.all__equal(quant.beta["100%"],
64
68
  R.c('100%': 20.08553692),
65
69
  tolerance: (~:".Machine").double__eps ** 0.5)).to eq true
66
- expect(quant.logic[2]).to eq 0.0
70
+ expect(quant.logic[[2]]).to eq 0.0
67
71
  end
68
72
 
69
73
  it "should allow using method lapply with quantile" do
70
74
  x = R.lapply(@x, @q, R.c(0.25, 0.50, 0.75))
71
- expect(x.a[1]).to eq 3.25
72
- expect(x.a["50,00000%"]).to eq 5.50
75
+ expect(x.a[[1]]).to eq 3.25
76
+ expect(x.a[["50%"]]).to eq 5.50
73
77
  expect(R.all__equal(x.beta['75%'],
74
78
  R.c('75%': 5.0536690),
75
79
  tolerance: (~:".Machine").double__eps ** 0.5)).to eq true
76
- expect(x.logic[2]).to eq 0.5
80
+ expect(x.logic[[2]]).to eq 0.5
77
81
  end
78
82
 
79
83
  it "should allow using sapply and quantile" do
84
+ # sapply will return a matrix
80
85
  quant = R.sapply(@x, @q)
81
86
  expect(quant.rclass).to eq 'matrix'
82
- expect(quant[:all, 'a']).to eq R.c(1, 3.25, 5.50, 7.75, 10)
83
- expect(quant[3, 'beta']).to eq 1
87
+
88
+ expect(quant[:all, 'a']).to eq R.c('0%': 1, '25%': 3.25, '50%': 5.50, '75%': 7.75, '100%': 10)
89
+
90
+ expect(quant[3, 'beta']).to eq 1.0
84
91
  end
85
92
 
86
93
  it "should sapply to a sequence" do
@@ -90,8 +97,8 @@ describe R::List do
90
97
  expect(i39[[1]]).to eq R.c(1, 2, 3)
91
98
  expect(i39[[7]]).to eq R.c(1, 2, 3, 4, 5, 6, 7, 8, 9)
92
99
  sap = R.sapply(i39, ~:fivenum)
93
- expect(sap[1, 1]).to eq 1
94
- expect(sap[5, 7]).to eq 9
100
+ expect(sap[1, 1]).to eq 1.0
101
+ expect(sap[5, 7]).to eq 9.0
95
102
  end
96
103
 
97
104
  end
@@ -32,14 +32,14 @@ describe R::Matrix do
32
32
  x = R.matrix(data: R.c(1, 2, 3, 4), nrow: 2, ncol: 2)
33
33
  expect(x[1, 1] == 1).to eq true
34
34
  expect(x[1, 2] == 3).to eq true
35
- expect(x.dim == 2).to eq true
35
+ expect(x.dim == R.c(2, 2)).to eq true
36
36
  end
37
37
 
38
38
  it "Should create a matrix by row" do
39
39
  x = R.matrix(data: R.c(1, 2, 3, 4), nrow: 2, ncol: 2, byrow: true)
40
40
  expect(x[1, 1] == 1).to eq true
41
41
  expect(x[1, 2] == 2).to eq true
42
- expect(x.dim == 2).to eq true
42
+ expect(x.dim == R.c(2, 2)).to eq true
43
43
  end
44
44
 
45
45
  it "Should add matrices" do
@@ -68,7 +68,7 @@ describe R::Matrix do
68
68
  it "should divide a scalar by a matrix" do
69
69
  y = R.matrix(data: R.c(2, 4, 6, 8), nrow: 2, ncol: 2)
70
70
  z = 10/y
71
- expect(z == R.c(10/2, 10/4, 10/6, 10/8)).to eq true
71
+ expect(z).to eq R.matrix(data: R.c(10/2.0, 10/4.0, 10/6.0, 10/8.0), nrow: 2, ncol: 2)
72
72
  end
73
73
 
74
74
  it "should apply a function to all elements of the matrix: ex: sqrt" do
@@ -69,9 +69,11 @@ describe R::Vector do
69
69
 
70
70
  it "should operate with Numeric first" do
71
71
  res = 10 + @vec1
72
- expect(res == R.c(13, 15.7, 20, 22)).to eq true
72
+ expect(res.identical(R.c(13, 15.7, 20, 22))).to eq true
73
+
73
74
  res = 10 - @vec1
74
- expect(res == R.c(7, 4.3, 0, -1)).to eq true
75
+ expect(res.identical(R.c(7, 4.3, 0, -2))).to eq true
76
+
75
77
  res = 10 / @vec1
76
78
  expect(res.all__equal R.c(3.333333333, 1.754385964, 1, 0.833333333)).to eq true
77
79
  end
@@ -135,17 +137,21 @@ describe R::Vector do
135
137
  # Use the '<<' operator to retrieve an element of the R::Vector as a Numeric
136
138
  # object
137
139
  expect(@vec1[1].is_a? R::Vector).to eq true
138
- expect((@vec1 << 0).is_a? Numeric).to eq true
140
+ expect((@vec1 >> 0).is_a? Numeric).to eq true
139
141
 
140
142
  # Note, however, that indexing starts at 0
141
- expect((@vec1 << 0)).to eq 3
142
- expect((@vec1 << 2)).to eq 10
143
+ expect((@vec1 >> 0)).to eq 3
144
+ expect((@vec1 >> 2)).to eq 10
145
+ end
146
+
147
+ it "Should raise an exeption if '<<' out of bounds" do
148
+ expect { @vec1 >> 5 }.to raise_error(IndexError)
143
149
  end
144
150
 
145
151
  it "should treat R::Vector as an Enumerable" do
146
152
  # each 'value' is an R::Vector, with only 1 element. In order to use Ruby 'sum'
147
- # we need to extract the value as a Ruby Numeric with << 1
148
- expect(@vec1.sum { |value| value << 0 }).to eq 30.7
153
+ # we need to extract the value as a Ruby Numeric with >> 1
154
+ expect(@vec1.sum { |value| value >> 0 }).to eq 30.7
149
155
  end
150
156
 
151
157
  it "should implement 'pop' to extract the first element of an R::Vector" do