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
@@ -38,8 +38,7 @@ describe R::DataFrame do
38
38
  expect(df[1, 'V2']).to eq 3
39
39
  # When you extract a single row from a data frame you get a one-row data frame.
40
40
  # Convert it to a numeric vector with 'as__numeric'
41
- expect(df[1, :all].as__numeric).to eq R.c(V1: 1, V2: 3, V3: 5)
42
-
41
+ expect(df[1, :all].as__numeric).to eq R.c(1.0, 3, 5)
43
42
  end
44
43
 
45
44
  end
@@ -84,26 +83,26 @@ describe R::DataFrame do
84
83
  # col_name a Ruby string with the column name
85
84
  case col_name
86
85
  when "mpg"
87
- expect(col[1]).to eq 21
86
+ expect(col[1]).to eq 21.0
88
87
  expect(col[9]).to eq 22.8
89
88
  expect(col[32]).to eq 21.4
90
- expect(col[1] == 21).to eq true
89
+ expect(col[1] == 21.0).to eq true
91
90
  expect(col[9] == 22.8).to eq true
92
91
  expect(col[9] == 30).to eq false
93
92
  expect(col[32] == 21.4).to eq true
94
93
  when "cyl"
95
- expect(col[1] == 6).to eq true
96
- expect(col[10] == 6).to eq true
97
- expect(col[32] == 4).to eq true
98
- expect(col[1]).to eq 6
99
- expect(col[10]).to eq 6
100
- expect(col[32]).to eq 4
94
+ expect(col[1] == 6.0).to eq true
95
+ expect(col[10] == 6.0).to eq true
96
+ expect(col[32] == 4.0).to eq true
97
+ expect(col[1]).to eq 6.0
98
+ expect(col[10]).to eq 6.0
99
+ expect(col[32]).to eq 4.0
101
100
  when "disp"
102
- expect(col[1]).to eq 160
103
- expect(col[32]).to eq 121
104
- expect(col[1] == 160).to eq true
105
- expect(col[1] == 200).to eq false
106
- expect(col[32] == 121).to eq true
101
+ expect(col[1]).to eq 160.0
102
+ expect(col[32]).to eq 121.0
103
+ expect(col[1] == 160.0).to eq true
104
+ expect(col[1] == 200.0).to eq false
105
+ expect(col[32] == 121.0).to eq true
107
106
  end
108
107
 
109
108
  end
@@ -118,25 +117,28 @@ describe R::DataFrame do
118
117
  # row_name a Ruby string with the column name
119
118
  case row_name
120
119
  when "Mazda RX4"
121
- expect(row[['mpg']]).to eq 21
122
- expect(row.mpg). to eq 21
120
+ expect(row[['mpg']]).to eq 21.0
121
+ # indexig with only '[ returns a data.frame which is not
122
+ # equal to 21.0
123
+ expect(row['mpg']).not_to eq 21.0
124
+ expect(row.mpg).to eq 21.0
123
125
  expect(row.qsec).to eq 16.46
124
- expect(row['mpg'] == 21).to eq true
126
+ expect(row[['mpg']] == 21.0).to eq true
125
127
  expect(row.qsec == 16.46).to eq true
126
128
  when "Hornet Sportabout"
127
- expect(row[['cyl']]).to eq 8
128
- expect(row.cyl).to eq 8
129
+ expect(row[['cyl']]).to eq 8.0
130
+ expect(row.cyl).to eq 8.0
129
131
  expect(row[['wt']]).to eq 3.44
130
- expect(row['cyl'] == 8).to eq true
131
- expect(row['wt'] == 3.44).to eq true
132
132
  when "Merc 240D"
133
- expect(row[['hp']]).to eq 62
134
- expect(row['hp'] == 62).to eq true
133
+ expect(row[['hp']]).to eq 62.0
134
+ expect(row[['hp']] == 62.0).to eq true
135
+ expect(row[['cyl']] == 4.0).to eq true
136
+ expect(row[['wt']] == 3.19).to eq true
135
137
  expect(row.drat).to eq 3.69
136
138
  when "Volvo 142E"
137
- expect(row.hp).to eq 109
138
- expect(row.am).to eq 1
139
- expect(row.carb).to eq 2
139
+ expect(row.hp).to eq 109.0
140
+ expect(row.am).to eq 1.0
141
+ expect(row.carb).to eq 2.0
140
142
  end
141
143
 
142
144
  end
@@ -0,0 +1,347 @@
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
+ require 'ggplot'
26
+
27
+ describe R do
28
+
29
+ before(:each) do
30
+ # Read the R ToothGrowth variable and assign it to the
31
+ # Ruby instance variable @tooth_growth that will be
32
+ # available to all Ruby chunks in this document.
33
+ @tooth_growth = ~:ToothGrowth
34
+
35
+ # convert the dose to a factor
36
+ @tooth_growth.dose = @tooth_growth.dose.as__factor
37
+
38
+ end
39
+
40
+ #----------------------------------------------------------------------------------------
41
+ context "Using png device" do
42
+
43
+ it "should generate png file without arguments" do
44
+
45
+ out_file = "specs/figures/no_args.png"
46
+ dir = File.dirname(out_file)
47
+
48
+ unless File.directory?(dir)
49
+ FileUtils.mkdir_p(dir)
50
+ end
51
+
52
+ R.png(out_file)
53
+
54
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
55
+ print e + R.geom_boxplot
56
+
57
+ R.dev__off
58
+
59
+ end
60
+
61
+ it "should generate png file with width and height" do
62
+
63
+ out_file = "specs/figures/width_height.png"
64
+ dir = File.dirname(out_file)
65
+
66
+ unless File.directory?(dir)
67
+ FileUtils.mkdir_p(dir)
68
+ end
69
+
70
+ # default 'units' is 'px'
71
+ R.png(out_file, width: 520, height: 520)
72
+
73
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
74
+ print e + R.geom_boxplot
75
+
76
+ R.dev__off
77
+
78
+ end
79
+
80
+ it "should generate png file with width, height and units 'in'" do
81
+
82
+ out_file = "specs/figures/width_height_units1.png"
83
+ dir = File.dirname(out_file)
84
+
85
+ unless File.directory?(dir)
86
+ FileUtils.mkdir_p(dir)
87
+ end
88
+
89
+ # set units to inches, needs to specify resolution also
90
+ # using 72 dpi
91
+ R.png(out_file, width: 7, height: 7, units: "in", res: 72)
92
+
93
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
94
+ print e + R.geom_boxplot
95
+
96
+ R.dev__off
97
+
98
+ end
99
+
100
+ it "should generate png file with width, height and units 'cm'" do
101
+
102
+ out_file = "specs/figures/width_height_units2.png"
103
+ dir = File.dirname(out_file)
104
+
105
+ unless File.directory?(dir)
106
+ FileUtils.mkdir_p(dir)
107
+ end
108
+
109
+ # set units to cm, needs to specify resolution also,
110
+ # using 72 dpi
111
+ R.png(out_file, width: 7, height: 7, units: "cm", res: 72)
112
+
113
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
114
+ print e + R.geom_boxplot
115
+
116
+ R.dev__off
117
+
118
+ end
119
+
120
+ it "should generate png file with a background" do
121
+
122
+ out_file = "specs/figures/bg.png"
123
+ dir = File.dirname(out_file)
124
+
125
+ unless File.directory?(dir)
126
+ FileUtils.mkdir_p(dir)
127
+ end
128
+
129
+ R.png(out_file, bg: "blue")
130
+
131
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
132
+ print e + R.geom_boxplot
133
+
134
+ R.dev__off
135
+
136
+ end
137
+
138
+ end
139
+
140
+ #----------------------------------------------------------------------------------------
141
+ context "Using svg device" do
142
+
143
+ it "should generate svg file without arguments" do
144
+
145
+ out_file = "specs/figures/no_args.svg"
146
+ dir = File.dirname(out_file)
147
+
148
+ unless File.directory?(dir)
149
+ FileUtils.mkdir_p(dir)
150
+ end
151
+
152
+ R.svg(out_file)
153
+
154
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
155
+ print e + R.geom_boxplot
156
+
157
+ R.dev__off
158
+
159
+ end
160
+
161
+ =begin
162
+ # does not work... should not pass width and height to svg file
163
+ it "should generate svg file with width and height" do
164
+
165
+ out_file = "specs/figures/width_height.svg"
166
+ dir = File.dirname(out_file)
167
+
168
+ unless File.directory?(dir)
169
+ FileUtils.mkdir_p(dir)
170
+ end
171
+
172
+ # default 'units' is 'px'
173
+ R.svg(out_file, width: 520, height: 520)
174
+
175
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
176
+ print e + R.geom_boxplot
177
+
178
+ R.dev__off
179
+
180
+ end
181
+
182
+
183
+ it "should generate svg file with width, height and units 'in'" do
184
+
185
+ out_file = "specs/figures/width_height_units1.svg"
186
+ dir = File.dirname(out_file)
187
+
188
+ unless File.directory?(dir)
189
+ FileUtils.mkdir_p(dir)
190
+ end
191
+
192
+ # set units to inches, needs to specify resolution also
193
+ # using 72 dpi
194
+ R.svg(out_file, width: 7, height: 7, units: "in", res: 72)
195
+
196
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
197
+ print e + R.geom_boxplot
198
+
199
+ R.dev__off
200
+
201
+ end
202
+
203
+ it "should generate svg file with width, height and units 'cm'" do
204
+
205
+ out_file = "specs/figures/width_height_units2.svg"
206
+ dir = File.dirname(out_file)
207
+
208
+ unless File.directory?(dir)
209
+ FileUtils.mkdir_p(dir)
210
+ end
211
+
212
+ # set units to cm, needs to specify resolution also,
213
+ # using 72 dpi
214
+ R.svg(out_file, width: 7, height: 7, units: "cm", res: 72)
215
+
216
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
217
+ print e + R.geom_boxplot
218
+
219
+ R.dev__off
220
+
221
+ end
222
+ =end
223
+
224
+ #----------------------------------------------------------------------------------------
225
+ it "should generate svg file with a background" do
226
+
227
+ out_file = "specs/figures/bg.svg"
228
+ dir = File.dirname(out_file)
229
+
230
+ unless File.directory?(dir)
231
+ FileUtils.mkdir_p(dir)
232
+ end
233
+
234
+ R.svg(out_file, bg: "blue")
235
+
236
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
237
+ print e + R.geom_boxplot
238
+
239
+ R.dev__off
240
+
241
+ end
242
+
243
+ end
244
+
245
+ #----------------------------------------------------------------------------------------
246
+ context "Using jpg device" do
247
+
248
+ it "should generate jpeg file without arguments" do
249
+
250
+ out_file = "specs/figures/no_args.jpeg"
251
+ dir = File.dirname(out_file)
252
+
253
+ unless File.directory?(dir)
254
+ FileUtils.mkdir_p(dir)
255
+ end
256
+
257
+ R.jpeg(out_file)
258
+
259
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
260
+ print e + R.geom_boxplot
261
+
262
+ R.dev__off
263
+
264
+ end
265
+
266
+ it "should generate jpeg file with width and height" do
267
+
268
+ out_file = "specs/figures/width_height.jpeg"
269
+ dir = File.dirname(out_file)
270
+
271
+ unless File.directory?(dir)
272
+ FileUtils.mkdir_p(dir)
273
+ end
274
+
275
+ # default 'units' is 'px'
276
+ R.jpeg(out_file, width: 520, height: 520)
277
+
278
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
279
+ print e + R.geom_boxplot
280
+
281
+ R.dev__off
282
+
283
+ end
284
+
285
+ it "should generate jpeg file with width, height and units 'in'" do
286
+
287
+ out_file = "specs/figures/width_height_units1.jpeg"
288
+ dir = File.dirname(out_file)
289
+
290
+ unless File.directory?(dir)
291
+ FileUtils.mkdir_p(dir)
292
+ end
293
+
294
+ # set units to inches, needs to specify resolution also
295
+ # using 72 dpi
296
+ R.jpeg(out_file, width: 7, height: 7, units: "in", res: 72)
297
+
298
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
299
+ print e + R.geom_boxplot
300
+
301
+ R.dev__off
302
+
303
+ end
304
+
305
+ it "should generate jpeg file with width, height and units 'cm'" do
306
+
307
+ out_file = "specs/figures/width_height_units2.jpeg"
308
+ dir = File.dirname(out_file)
309
+
310
+ unless File.directory?(dir)
311
+ FileUtils.mkdir_p(dir)
312
+ end
313
+
314
+ # set units to cm, needs to specify resolution also,
315
+ # using 72 dpi
316
+ R.jpeg(out_file, width: 7, height: 7, units: "cm", res: 72)
317
+
318
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
319
+ print e + R.geom_boxplot
320
+
321
+ R.dev__off
322
+
323
+ end
324
+
325
+ it "should generate jpeg file with a background" do
326
+
327
+ out_file = "specs/figures/bg.jpeg"
328
+ dir = File.dirname(out_file)
329
+
330
+ unless File.directory?(dir)
331
+ FileUtils.mkdir_p(dir)
332
+ end
333
+
334
+ # R.jpeg(out_file, bg: "blue")
335
+ R.jpeg(out_file)
336
+
337
+ e = @tooth_growth.ggplot(E.aes(x: :dose, y: :len))
338
+ print e + R.geom_boxplot
339
+
340
+ R.dev__off
341
+
342
+ end
343
+
344
+ end
345
+
346
+
347
+ end
@@ -110,7 +110,13 @@ describe R do
110
110
  # one element of the vector is a 'float'
111
111
  double = R.c(1.0, 2, 3)
112
112
  expect((~:x).identical double).to eq true
113
- expect(R.hyp(3, 4)).to eq 5
113
+ expect(R.hyp(3, 4).all__equal(5)).to eq true
114
+ # @TODO: this should work but raises the following error:
115
+ # TypeError:
116
+ # Truffle doesn't have a case for the org.truffleruby.interop.InteropNodesFactory$HasSizeNodeFactory$HasSizeNodeGen node with values of type java.lang.Double=5.0
117
+ # I think this is a bug with TruffleRuby that hopefully will be fixed in RC12
118
+ # If not fixed in RC12 open issue
119
+ # expect(R.hyp(3, 4)).to eq 5
114
120
  end
115
121
 
116
122
  it "should box R functions in R::Closure Ruby class" do
@@ -136,8 +142,9 @@ describe R do
136
142
  # retrieve x and hyp from R and attribute it to local Ruby variables
137
143
  x = ~:x
138
144
 
139
- expect(x[1] == 1).to eq true
140
- expect(x[2] == 1).to eq false
145
+ expect(x[1].all__equal(1)).to eq true
146
+ expect(x[2].identical(1)).to eq false
147
+ expect((x >> 0) == 1).to eq true
141
148
  end
142
149
 
143
150
  it "should have NA" do