galaaz 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +325 -32
  3. data/Rakefile +14 -0
  4. data/bin/galaaz +0 -3
  5. data/bin/gknit +28 -0
  6. data/bin/gstudio +6 -0
  7. data/bin/gstudio.rb +6 -0
  8. data/bin/ogk~ +4 -0
  9. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +335 -0
  10. data/blogs/galaaz_ggplot/galaaz_ggplot.html +460 -0
  11. data/blogs/galaaz_ggplot/galaaz_ggplot.md +327 -0
  12. data/blogs/galaaz_ggplot/midwest.Rmd +39 -0
  13. data/blogs/galaaz_ggplot/midwest.html +188 -0
  14. data/blogs/galaaz_ggplot/midwest.png +0 -0
  15. data/blogs/galaaz_ggplot/scatter_plot.png +0 -0
  16. data/examples/50Plots_MasterList/Images/midwest-scatterplot.PNG +0 -0
  17. data/examples/50Plots_MasterList/ScatterPlot.rb +159 -0
  18. data/examples/R/calc.R +21 -0
  19. data/examples/R/java_interop.R +29 -0
  20. data/examples/{baseball.csv → misc/baseball.csv} +0 -0
  21. data/examples/{ggplot.rb → misc/ggplot.rb} +0 -0
  22. data/examples/misc/moneyball.rb +33 -0
  23. data/examples/{baseball.rb → misc/moneyball.rb~} +0 -0
  24. data/examples/misc/subsetting.rb +374 -0
  25. data/examples/{subsetting.rb → misc/subsetting.rb~} +0 -0
  26. data/lib/{expression.rb → R/expression.rb} +0 -0
  27. data/lib/{r.rb → R/r.rb} +1 -0
  28. data/lib/R/r.rb~ +121 -0
  29. data/lib/{r_methods.rb → R/r_methods.rb} +0 -0
  30. data/lib/{rbinary_operators.rb → R/rbinary_operators.rb} +0 -0
  31. data/lib/{rclosure.rb → R/rclosure.rb} +0 -0
  32. data/lib/{rdata_frame.rb → R/rdata_frame.rb} +0 -0
  33. data/lib/{renvironment.rb → R/renvironment.rb} +0 -0
  34. data/lib/{rexpression.rb → R/rexpression.rb} +0 -0
  35. data/lib/{rindexed_object.rb → R/rindexed_object.rb} +0 -0
  36. data/lib/{rlanguage.rb → R/rlanguage.rb} +0 -0
  37. data/lib/{rlist.rb → R/rlist.rb} +0 -0
  38. data/lib/{rmatrix.rb → R/rmatrix.rb} +0 -0
  39. data/lib/{rmd_indexed_object.rb → R/rmd_indexed_object.rb} +0 -0
  40. data/lib/{robject.rb → R/robject.rb} +0 -0
  41. data/lib/{rpkg.rb → R/rpkg.rb} +0 -0
  42. data/lib/{rsupport.rb → R/rsupport.rb} +0 -0
  43. data/lib/{rsupport_scope.rb → R/rsupport_scope.rb} +0 -0
  44. data/lib/{rsymbol.rb → R/rsymbol.rb} +0 -0
  45. data/lib/{ruby_callback.rb → R/ruby_callback.rb} +0 -0
  46. data/lib/{ruby_extensions.rb → R/ruby_extensions.rb} +0 -0
  47. data/lib/{runary_operators.rb → R/runary_operators.rb} +0 -0
  48. data/lib/{rvector.rb → R/rvector.rb} +0 -0
  49. data/lib/galaaz.rb +2 -1
  50. data/lib/util/exec_ruby.rb +44 -0
  51. data/specs/tmp.rb +167 -1
  52. data/version.rb +1 -1
  53. metadata +63 -28
File without changes
@@ -116,3 +116,4 @@ require_relative 'expression'
116
116
  require_relative 'ruby_extensions'
117
117
  # Class to allow R calling back into Ruby
118
118
  require_relative 'ruby_callback'
119
+
@@ -0,0 +1,121 @@
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_relative 'robject'
25
+ require_relative 'rsupport'
26
+
27
+ module R
28
+
29
+ RCONSTANTS = ["LETTERS", "letters", "month.abb", "month.name", "pi"]
30
+
31
+ #----------------------------------------------------------------------------------------
32
+ #
33
+ #----------------------------------------------------------------------------------------
34
+
35
+ def self.method_missing(symbol, *args, &block)
36
+
37
+ if (block_given?)
38
+ val = R::Support.process_missing(symbol, false, *args)
39
+ return R::Support.new_scope(symbol, val, *args, &block)
40
+ end
41
+
42
+ R::Support.process_missing(symbol, false, *args)
43
+
44
+ end
45
+
46
+ #----------------------------------------------------------------------------------------
47
+ #
48
+ #----------------------------------------------------------------------------------------
49
+
50
+ def self.internal_eval(symbol, *args)
51
+ R::Support.process_missing(symbol, true, *args)
52
+ end
53
+
54
+ #----------------------------------------------------------------------------------------
55
+ # Checks to see if the given libs are installed in R and if not, install them
56
+ # @param libs [Array] Array of strings with the names of the libraries to check and
57
+ # install
58
+ #----------------------------------------------------------------------------------------
59
+
60
+ def self.install_rlibs(*libs)
61
+
62
+ packages = R.c(libs)
63
+
64
+ new_packages = packages[!(packages._ :in, R.installed__packages[:all, "Package"])]
65
+ if(new_packages.size > 0)
66
+ puts "The following packages are missing and will be installed:\n #{new_packages}"
67
+ R.install__packages(new_packages)
68
+ end
69
+
70
+ end
71
+
72
+ #----------------------------------------------------------------------------------------
73
+ #
74
+ #----------------------------------------------------------------------------------------
75
+
76
+ def self.install_and_loads(*libs)
77
+ R.install_rlibs(*libs)
78
+ libs.each { |lib| R.require lib }
79
+ end
80
+
81
+ end
82
+
83
+ # define methods for accessing indexed object: Vector, Lists
84
+ require_relative 'rindexed_object'
85
+ # define methods for accessing multi dimensional indexed objects: Matrix, DataFrames
86
+ require_relative 'rmd_indexed_object'
87
+ # Binary operators: '+', '-', etc
88
+ require_relative 'rbinary_operators'
89
+ # Unary operators: '!', '@-', etc
90
+ require_relative 'runary_operators'
91
+ # Definition of R Vector
92
+ require_relative 'rvector'
93
+ # Definition of R Lists
94
+ require_relative 'rlist'
95
+ # Definition of R Matrix
96
+ require_relative 'rmatrix'
97
+ # Definition of R DataFrame
98
+ require_relative 'rdata_frame'
99
+ # Definition of R Closure (functions)
100
+ require_relative 'rclosure'
101
+ # Definition of R Expression
102
+ require_relative 'rexpression'
103
+ # Definition of R Environment
104
+ require_relative 'renvironment'
105
+ # Definition of R Language
106
+ require_relative 'rlanguage'
107
+ # Definition of R Symbol
108
+ require_relative 'rsymbol'
109
+ # Access to package symbols
110
+ require_relative 'rpkg'
111
+
112
+ # Defines the E module for creating R expressions
113
+ require_relative 'expression'
114
+ # Ruby class extensions. Extends Symbol to allow the creation of
115
+ # expressions using Symbol: (:x > 10)
116
+ require_relative 'ruby_extensions'
117
+ # Class to allow R calling back into Ruby
118
+ require_relative 'ruby_callback'
119
+
120
+ # Util to execute Ruby code in a string redirecting stdout
121
+ require_relative 'util/exec_ruby'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -21,7 +21,8 @@
21
21
  # OR MODIFICATIONS.
22
22
  ##########################################################################################
23
23
 
24
- require_relative 'r'
24
+ require_relative 'R/r'
25
+ require_relative 'util/exec_ruby'
25
26
 
26
27
  $LOAD_PATH << File.dirname(File.expand_path('..', __FILE__)) + "/r_requires"
27
28
 
@@ -0,0 +1,44 @@
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 'stringio'
25
+
26
+ module GalaazUtil
27
+
28
+ def self.exec_ruby(code)
29
+ # Set up standard output as a StringIO object.
30
+ foo = StringIO.new
31
+ $stdout = foo
32
+
33
+ eval code
34
+
35
+ out = $stdout.string
36
+
37
+ # return $stdout to standard output
38
+ $stdout = STDOUT
39
+
40
+ # return everything that was outputed
41
+ out
42
+ end
43
+
44
+ end
@@ -23,6 +23,48 @@
23
23
 
24
24
  require 'galaaz'
25
25
 
26
+ # puts GalaazUtil.exec_ruby("puts 1 + 1")
27
+
28
+ =begin
29
+ R::Support.eval(<<-R)
30
+ print.polyglot.value = function(poly) {
31
+ print("printing external");
32
+ print(poly$puts());
33
+ }
34
+
35
+ R
36
+
37
+ ext = R::Support.eval(<<-R)
38
+ function(data) {
39
+ print(data);
40
+ }
41
+ R
42
+
43
+ class User
44
+
45
+ attr_reader :id
46
+ attr_reader :name
47
+
48
+ def initialize
49
+ @id = 1
50
+ @name = ["a", "b", "c"]
51
+ end
52
+
53
+ def method_missing(symbol, *args)
54
+ p symbol
55
+ p args
56
+ end
57
+
58
+ def puts(*args)
59
+ @id
60
+ end
61
+
62
+ end
63
+
64
+ ext.call(User.new)
65
+ =end
66
+
67
+ =begin
26
68
  class ArrayEmul
27
69
  attr_reader :array
28
70
 
@@ -79,7 +121,7 @@ puts h
79
121
  r_obj = make_obj.call(h)
80
122
  p Polyglot.eval("R", "print").call(r_obj, 0)[0]
81
123
 
82
-
124
+ =end
83
125
 
84
126
 
85
127
  =begin
@@ -132,3 +174,127 @@ puts R.model__frame(+:y =~ +:x + +:x2 + (+:x ^ +:x2),
132
174
  puts R.model__frame(+:y =~ +:x + (:x ** 2).i,
133
175
  data: R.data__frame(x: R.rnorm(5), y: R.rnorm(5)))
134
176
  =end
177
+ =begin
178
+ class User
179
+
180
+ attr_reader :id
181
+ attr_reader :name
182
+ attr_reader :favoriteLanguage
183
+
184
+ def initialize(id, name, favorite_language)
185
+ @id = id
186
+ @name = name
187
+ @favorite_language = favorite_language
188
+ end
189
+
190
+ end
191
+
192
+ class NameColumn
193
+
194
+ attr_reader :users
195
+
196
+ def initialize(users)
197
+ @users = users
198
+ end
199
+
200
+ def get(index)
201
+ users[index].name
202
+ end
203
+
204
+ def set(index, val)
205
+ end
206
+
207
+ def getSize
208
+ users.size
209
+ end
210
+
211
+ def method_missing(symbol, *args)
212
+ puts "NameColumn method_missing"
213
+ puts symbol
214
+ puts args
215
+ end
216
+
217
+ end
218
+
219
+ class IdColumn
220
+
221
+ attr_reader :users
222
+
223
+ def initialize(users)
224
+ @users = users
225
+ end
226
+
227
+ def get(index)
228
+ users[index].id
229
+ end
230
+
231
+ def set(index, val)
232
+ end
233
+
234
+ def getSize
235
+ users.size
236
+ end
237
+
238
+ def method_missing(symbol, *args)
239
+ puts "IdColumn method_missing"
240
+ puts symbol
241
+ puts args
242
+ end
243
+
244
+ end
245
+
246
+ class UsersTable
247
+ attr_reader :id
248
+ attr_reader :name
249
+ attr_reader :language
250
+
251
+ def initialize(users)
252
+ @users = users
253
+ @id = IdColumn.new(users)
254
+ @name = NameColumn.new(users)
255
+ end
256
+
257
+ def getSize
258
+ puts users.size
259
+ users.size
260
+ end
261
+
262
+ def method_missing(symbol, *args)
263
+ puts "UsersTable method_missing"
264
+ puts symbol
265
+ puts args
266
+ end
267
+
268
+ end
269
+
270
+ rf = R::Support.eval(<<-R)
271
+ function(table) {
272
+ print(table);
273
+ table <- as.data.frame(table);
274
+ cat('The whole data frame printed in R:\n');
275
+ print(table);
276
+ cat('---------\n\n');
277
+
278
+ cat('Filter out users with ID>2:\n');
279
+ print(table[table$id > 2,]);
280
+ cat('---------\n\n');
281
+
282
+ cat('How many users like Java: ');
283
+ cat(nrow(table[table$language == 'Java',]), '\n');
284
+ }
285
+ R
286
+
287
+ users = []
288
+ users << User.new(1, "Florian", "Python")
289
+ users << User.new(2, "Lukas", "R")
290
+ users << User.new(3, "Mila", "Java")
291
+ users << User.new(4, "Paley", "Coq")
292
+ users << User.new(5, "Stepan", "C#")
293
+ users << User.new(6, "Tomas", "Java")
294
+ users << User.new(7, "Zbynek", "Scala")
295
+
296
+ puts users[0].name
297
+ ut = UsersTable.new(users)
298
+ rut = R.list(ut)
299
+ rf.call(rut)
300
+ =end
data/version.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  $gem_name = "galaaz"
2
- $version="0.4.0"
2
+ $version="0.4.1"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: galaaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Botafogo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-05 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ prerelease: false
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.10'
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  prerelease: false
@@ -83,16 +97,30 @@ description: "Galaaz brings the power of R to the Ruby community. Galaaz \nis ba
83
97
  email: rodrigo.a.botafogo@gmail.com
84
98
  executables:
85
99
  - galaaz
100
+ - gstudio
101
+ - gknit
86
102
  extensions: []
87
103
  extra_rdoc_files: []
88
104
  files:
89
105
  - README.md
90
106
  - Rakefile
91
107
  - bin/galaaz
108
+ - bin/gknit
109
+ - bin/gstudio
110
+ - bin/gstudio.rb
111
+ - bin/ogk~
112
+ - blogs/galaaz_ggplot/galaaz_ggplot.Rmd
113
+ - blogs/galaaz_ggplot/galaaz_ggplot.html
114
+ - blogs/galaaz_ggplot/galaaz_ggplot.md
115
+ - blogs/galaaz_ggplot/midwest.Rmd
116
+ - blogs/galaaz_ggplot/midwest.html
117
+ - blogs/galaaz_ggplot/midwest.png
118
+ - blogs/galaaz_ggplot/scatter_plot.png
119
+ - examples/50Plots_MasterList/Images/midwest-scatterplot.PNG
120
+ - examples/50Plots_MasterList/ScatterPlot.rb
92
121
  - examples/50Plots_MasterList/scatter_plot.rb
93
- - examples/baseball.csv
94
- - examples/baseball.rb
95
- - examples/ggplot.rb
122
+ - examples/R/calc.R
123
+ - examples/R/java_interop.R
96
124
  - examples/islr/Figure.jpg
97
125
  - examples/islr/all.rb
98
126
  - examples/islr/ch2.spec.rb
@@ -100,6 +128,12 @@ files:
100
128
  - examples/islr/ch3_boston.rb
101
129
  - examples/islr/ch3_multiple_regression.rb
102
130
  - examples/islr/ch6.spec.rb
131
+ - examples/misc/baseball.csv
132
+ - examples/misc/ggplot.rb
133
+ - examples/misc/moneyball.rb
134
+ - examples/misc/moneyball.rb~
135
+ - examples/misc/subsetting.rb
136
+ - examples/misc/subsetting.rb~
103
137
  - examples/paper/paper.rb
104
138
  - examples/sthda_ggplot/README.md
105
139
  - examples/sthda_ggplot/all.rb
@@ -130,30 +164,31 @@ files:
130
164
  - examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb
131
165
  - examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb
132
166
  - examples/sthda_ggplot/two_variables_error/geom_crossbar.rb
133
- - examples/subsetting.rb
134
- - lib/expression.rb
167
+ - lib/R/expression.rb
168
+ - lib/R/r.rb
169
+ - lib/R/r.rb~
170
+ - lib/R/r_methods.rb
171
+ - lib/R/rbinary_operators.rb
172
+ - lib/R/rclosure.rb
173
+ - lib/R/rdata_frame.rb
174
+ - lib/R/renvironment.rb
175
+ - lib/R/rexpression.rb
176
+ - lib/R/rindexed_object.rb
177
+ - lib/R/rlanguage.rb
178
+ - lib/R/rlist.rb
179
+ - lib/R/rmatrix.rb
180
+ - lib/R/rmd_indexed_object.rb
181
+ - lib/R/robject.rb
182
+ - lib/R/rpkg.rb
183
+ - lib/R/rsupport.rb
184
+ - lib/R/rsupport_scope.rb
185
+ - lib/R/rsymbol.rb
186
+ - lib/R/ruby_callback.rb
187
+ - lib/R/ruby_extensions.rb
188
+ - lib/R/runary_operators.rb
189
+ - lib/R/rvector.rb
135
190
  - lib/galaaz.rb
136
- - lib/r.rb
137
- - lib/r_methods.rb
138
- - lib/rbinary_operators.rb
139
- - lib/rclosure.rb
140
- - lib/rdata_frame.rb
141
- - lib/renvironment.rb
142
- - lib/rexpression.rb
143
- - lib/rindexed_object.rb
144
- - lib/rlanguage.rb
145
- - lib/rlist.rb
146
- - lib/rmatrix.rb
147
- - lib/rmd_indexed_object.rb
148
- - lib/robject.rb
149
- - lib/rpkg.rb
150
- - lib/rsupport.rb
151
- - lib/rsupport_scope.rb
152
- - lib/rsymbol.rb
153
- - lib/ruby_callback.rb
154
- - lib/ruby_extensions.rb
155
- - lib/runary_operators.rb
156
- - lib/rvector.rb
191
+ - lib/util/exec_ruby.rb
157
192
  - r_requires/ggplot.rb
158
193
  - specs/all.rb
159
194
  - specs/r_dataframe.spec.rb