galaaz 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +696 -270
- data/Rakefile +9 -22
- data/bin/gknit +2 -217
- data/bin/gknit_old_r +236 -0
- data/bin/grun +5 -0
- data/blogs/dev/dev.Rmd +7 -0
- data/blogs/dev/dev.html +34 -26
- data/blogs/dev/dev.md +40 -25
- data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
- data/blogs/dev/dev_files/figure-html/diverging_bar. +0 -0
- data/blogs/dev/dev_files/figure-html/diverging_bar.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +4 -4
- data/blogs/galaaz_ggplot/galaaz_ggplot.html +251 -59
- data/blogs/galaaz_ggplot/galaaz_ggplot.log +640 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.md +199 -95
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +45 -228
- data/blogs/galaaz_ggplot/midwest.png +0 -0
- data/blogs/galaaz_ggplot/scatter_plot.png +0 -0
- data/blogs/gknit/gknit.Rmd +271 -148
- data/blogs/manual/manual.Rmd +212 -0
- data/blogs/manual/manual.html +1832 -0
- data/blogs/manual/manual.md +751 -0
- data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
- data/blogs/ruby_plot/ruby_plot.Rmd +5 -69
- data/blogs/ruby_plot/ruby_plot.html +195 -236
- data/blogs/ruby_plot/ruby_plot.md +1 -261
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +38 -38
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +5 -5
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +1 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +3 -7
- data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +3 -1
- data/lib/R_interface/r.rb +12 -9
- data/lib/R_interface/r_methods.rb +2 -2
- data/lib/R_interface/rbinary_operators.rb +2 -20
- data/lib/R_interface/rdata_frame.rb +56 -9
- data/lib/R_interface/rdevices.R +0 -12
- data/lib/R_interface/rexpression.rb +0 -97
- data/lib/R_interface/rindexed_object.rb +12 -3
- data/lib/R_interface/rlanguage.rb +1 -1
- data/lib/R_interface/rlist.rb +29 -4
- data/lib/R_interface/rlogical_operators.rb +50 -0
- data/lib/R_interface/rmatrix.rb +7 -1
- data/lib/R_interface/robject.rb +29 -15
- data/lib/R_interface/rsupport.rb +74 -58
- data/lib/R_interface/rsymbol.rb +2 -1
- data/lib/R_interface/ruby_extensions.rb +11 -2
- data/lib/R_interface/rvector.rb +26 -11
- data/lib/gknit.rb +2 -0
- data/lib/gknit/include_engine.rb +57 -0
- data/lib/gknit/knitr_engine.rb +596 -50
- data/lib/gknit/rb_engine.rb +56 -0
- data/lib/gknit/ruby_engine.rb +13 -36
- data/lib/util/exec_ruby.rb +132 -21
- data/lib/util/inline_file.rb +9 -7
- data/specs/all.rb +5 -0
- data/specs/figures/bg.jpeg +0 -0
- data/specs/figures/bg.png +0 -0
- data/specs/figures/bg.svg +57 -0
- data/specs/figures/no_args.jpeg +0 -0
- data/specs/figures/no_args.png +0 -0
- data/specs/figures/no_args.svg +57 -0
- data/specs/figures/width_height.jpeg +0 -0
- data/specs/figures/width_height.png +0 -0
- data/specs/figures/width_height_units1.jpeg +0 -0
- data/specs/figures/width_height_units1.png +0 -0
- data/specs/figures/width_height_units2.jpeg +0 -0
- data/specs/figures/width_height_units2.png +0 -0
- data/specs/r_dataframe.spec.rb +29 -27
- data/specs/r_devices.spec.rb +347 -0
- data/specs/r_eval.spec.rb +10 -3
- data/specs/r_formula.spec.rb +2 -2
- data/specs/r_language.spec.rb +112 -0
- data/specs/r_list.spec.rb +174 -14
- data/specs/r_list_apply.spec.rb +17 -10
- data/specs/r_matrix.spec.rb +3 -3
- data/specs/r_vector_operators.spec.rb +13 -7
- data/specs/tmp.rb +42 -12
- data/version.rb +1 -1
- metadata +28 -24
- data/bin/gknit2 +0 -14
- data/bin/prepareR.rb +0 -3
- data/bin/tmp.py +0 -51
- data/blogs/gknit/gknit.html +0 -528
- data/blogs/gknit/gknit.md +0 -628
- data/blogs/gknit/gknit.pdf +0 -0
- data/blogs/gknit/gknit.tex +0 -745
- data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
- data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
- data/blogs/ruby_plot/figures/dose_len.png +0 -0
- data/blogs/ruby_plot/figures/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/figures/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/figures/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/figures/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/figures/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/figures/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/figures/facets_with_points.png +0 -0
- data/blogs/ruby_plot/figures/final_box_plot.png +0 -0
- data/blogs/ruby_plot/figures/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/figures/violin_with_jitter.png +0 -0
- data/lib/R/eng_ruby.R +0 -62
- data/lib/R_interface/rdevices.rb +0 -225
@@ -0,0 +1,50 @@
|
|
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
|
+
module R
|
25
|
+
|
26
|
+
module LogicalOperators
|
27
|
+
|
28
|
+
#--------------------------------------------------------------------------------------
|
29
|
+
#
|
30
|
+
#--------------------------------------------------------------------------------------
|
31
|
+
|
32
|
+
def &(other_object)
|
33
|
+
exec_bin_oper("`&`", other_object)
|
34
|
+
end
|
35
|
+
|
36
|
+
alias_method :and, :&
|
37
|
+
|
38
|
+
#--------------------------------------------------------------------------------------
|
39
|
+
#
|
40
|
+
#--------------------------------------------------------------------------------------
|
41
|
+
|
42
|
+
def |(other_object)
|
43
|
+
exec_bin_oper("`|`", other_object)
|
44
|
+
end
|
45
|
+
|
46
|
+
alias_method :or, :|
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/R_interface/rmatrix.rb
CHANGED
@@ -29,11 +29,17 @@ module R
|
|
29
29
|
|
30
30
|
class Matrix < Object
|
31
31
|
include MDIndexedObject
|
32
|
+
# binary operators
|
32
33
|
include BinaryOperators
|
33
34
|
include ExecBinOp
|
35
|
+
|
36
|
+
# unary operators
|
34
37
|
include UnaryOperators
|
35
38
|
include ExecUniOp
|
36
39
|
|
40
|
+
# logical operators. Can either be binary or unary
|
41
|
+
include LogicalOperators
|
42
|
+
|
37
43
|
#--------------------------------------------------------------------------------------
|
38
44
|
# When indexing with '[' or '[[' an R object is returned. Sometimes we need to have
|
39
45
|
# access to an umboxed Ruby element, for instance, in an numeric array, we might want
|
@@ -42,7 +48,7 @@ module R
|
|
42
48
|
# @return the Ruby element at the given index in the vector
|
43
49
|
#--------------------------------------------------------------------------------------
|
44
50
|
|
45
|
-
def
|
51
|
+
def >>(index)
|
46
52
|
@r_interop[index]
|
47
53
|
end
|
48
54
|
|
data/lib/R_interface/robject.rb
CHANGED
@@ -49,9 +49,11 @@ module R
|
|
49
49
|
#--------------------------------------------------------------------------------------
|
50
50
|
|
51
51
|
def ==(other_object)
|
52
|
-
res =
|
53
|
-
|
54
|
-
|
52
|
+
res =
|
53
|
+
R::Support.exec_function_name('identical', @r_interop,
|
54
|
+
R::Support.parse_arg(other_object))
|
55
|
+
return nil if (res.length >> 0) == 0
|
56
|
+
res >> 0
|
55
57
|
end
|
56
58
|
|
57
59
|
#--------------------------------------------------------------------------------------
|
@@ -60,7 +62,8 @@ module R
|
|
60
62
|
|
61
63
|
def eql(other_object)
|
62
64
|
# exec_bin_oper("`==`", other_object)
|
63
|
-
R::Support.exec_function_name("`==`", @r_interop,
|
65
|
+
R::Support.exec_function_name("`==`", @r_interop,
|
66
|
+
R::Support.parse_arg(other_object))
|
64
67
|
end
|
65
68
|
|
66
69
|
#--------------------------------------------------------------------------------------
|
@@ -102,8 +105,14 @@ module R
|
|
102
105
|
# puts "5"
|
103
106
|
List.new(r_interop)
|
104
107
|
elsif (R::Support.eval("typeof").call(r_interop) == "language")
|
108
|
+
# @TODO: tests are passing both when we use Language.new
|
109
|
+
# and RExpression.new. Check what should be and write
|
110
|
+
# discriminating tests.
|
111
|
+
# print "robject buid: language\n"
|
112
|
+
# R::Support.print_foreign(r_interop)
|
105
113
|
# puts "6"
|
106
114
|
Language.new(r_interop)
|
115
|
+
# RExpression.new(r_interop)
|
107
116
|
elsif (R::Support.eval("typeof").call(r_interop) == "expression")
|
108
117
|
# puts "7"
|
109
118
|
RExpression.new(r_interop)
|
@@ -124,15 +133,17 @@ module R
|
|
124
133
|
end
|
125
134
|
|
126
135
|
end
|
127
|
-
|
136
|
+
|
137
|
+
=begin
|
128
138
|
#--------------------------------------------------------------------------------------
|
129
|
-
#
|
139
|
+
# This method was moved to DataFrame. Need to check which other objects can have
|
140
|
+
# values assigned to them
|
130
141
|
#--------------------------------------------------------------------------------------
|
131
142
|
|
132
143
|
def method_missing_assign(column_name, arg)
|
133
144
|
return setR_name("`[<-`", R.empty_symbol, column_name, arg)
|
134
145
|
end
|
135
|
-
|
146
|
+
=end
|
136
147
|
#--------------------------------------------------------------------------------------
|
137
148
|
#
|
138
149
|
#--------------------------------------------------------------------------------------
|
@@ -141,6 +152,10 @@ module R
|
|
141
152
|
|
142
153
|
name = R::Support.convert_symbol2r(symbol)
|
143
154
|
|
155
|
+
# Need to raise a NoMethodError when method_missing is called by an implicit
|
156
|
+
# call to "to_ary". I'm not sure why "to_ary" is being called, but it is
|
157
|
+
raise NoMethodError if name == "to_ary"
|
158
|
+
|
144
159
|
case
|
145
160
|
when block_given?
|
146
161
|
R::Support.new_scope(symbol, self, *args, &block)
|
@@ -151,7 +166,7 @@ module R
|
|
151
166
|
# the second argument to be an environment. If the arguments are packed
|
152
167
|
# into a list, then there is no second argument and the function fails to
|
153
168
|
# use the second argument as environment
|
154
|
-
R::Support.r_evaluate(r_interop, *args)
|
169
|
+
R::Support.r_evaluate(@r_interop, *args)
|
155
170
|
when args.length == 0
|
156
171
|
# no arguments: 2 options: either a named item of the object or apply the function
|
157
172
|
# to the object
|
@@ -180,7 +195,7 @@ module R
|
|
180
195
|
args.unshift(@r_interop)
|
181
196
|
R::Support.exec_function_name(name, *args)
|
182
197
|
end
|
183
|
-
|
198
|
+
|
184
199
|
#--------------------------------------------------------------------------------------
|
185
200
|
# Sets the current object self interop pointer to the returned value of the execution
|
186
201
|
# of the given method with arguments. This method should be called when R will copy
|
@@ -195,7 +210,7 @@ module R
|
|
195
210
|
end
|
196
211
|
|
197
212
|
#--------------------------------------------------------------------------------------
|
198
|
-
#
|
213
|
+
#
|
199
214
|
#--------------------------------------------------------------------------------------
|
200
215
|
|
201
216
|
def setR_name(method_name, *args)
|
@@ -309,7 +324,7 @@ module R
|
|
309
324
|
#--------------------------------------------------------------------------------------
|
310
325
|
|
311
326
|
def pp
|
312
|
-
R.print(r_interop)
|
327
|
+
R.print(@r_interop)
|
313
328
|
end
|
314
329
|
|
315
330
|
#--------------------------------------------------------------------------------------
|
@@ -319,7 +334,6 @@ module R
|
|
319
334
|
def to_s
|
320
335
|
|
321
336
|
begin
|
322
|
-
|
323
337
|
cap = nil
|
324
338
|
cap = R::Support.capture2.call(r_interop)
|
325
339
|
str = String.new
|
@@ -328,13 +342,13 @@ module R
|
|
328
342
|
end
|
329
343
|
str << cap[cap.size - 1] if cap.size >= 1
|
330
344
|
str
|
331
|
-
|
332
345
|
rescue StandardError => e
|
333
346
|
puts e
|
334
347
|
end
|
335
348
|
|
336
349
|
end
|
337
|
-
|
350
|
+
|
338
351
|
end
|
339
|
-
|
352
|
+
|
353
|
+
|
340
354
|
end
|
data/lib/R_interface/rsupport.rb
CHANGED
@@ -72,7 +72,7 @@ module R
|
|
72
72
|
# do.call (this is what the documentation says).
|
73
73
|
# res = do.call(...);
|
74
74
|
res = invoke(...);
|
75
|
-
|
75
|
+
|
76
76
|
# print(res);
|
77
77
|
res2 = build_method(res);
|
78
78
|
# print(res2);
|
@@ -101,31 +101,7 @@ module R
|
|
101
101
|
def self.interop(object)
|
102
102
|
Truffle::Interop.foreign?(object)
|
103
103
|
end
|
104
|
-
|
105
|
-
=begin
|
106
|
-
#----------------------------------------------------------------------------------------
|
107
|
-
# Builds a quo or a formula based on the given expression. If the expression has a
|
108
|
-
# '=~' operator, then a formula should be constructed, if not, then an quo should be
|
109
|
-
# constructed
|
110
|
-
# @param expression [R::Expression]
|
111
|
-
# @return quo or formula
|
112
|
-
#----------------------------------------------------------------------------------------
|
113
|
-
|
114
|
-
def self.quo_or_formula(expression)
|
115
|
-
|
116
|
-
if expression.formula?
|
117
|
-
R.as__formula(expression.infix)
|
118
|
-
else
|
119
|
-
# add a '~' before the expression so we can parse it as an
|
120
|
-
# R expression from a string. Didn't find a good way of creating an
|
121
|
-
# expression from string.
|
122
|
-
# R.as_quosure(R.as__formula("~ #{expression.infix}"))
|
123
|
-
R.rhs(R.as__formula("~ #{expression.infix}"))
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
=end
|
128
|
-
|
104
|
+
|
129
105
|
#----------------------------------------------------------------------------------------
|
130
106
|
# @param arg [Object] A Ruby object to be converted to R to be used by an R function, or
|
131
107
|
# whatever needs it
|
@@ -139,25 +115,55 @@ module R
|
|
139
115
|
arg
|
140
116
|
when R::Object
|
141
117
|
arg.r_interop
|
118
|
+
when Numeric
|
119
|
+
R::Support.eval('c').call(arg)
|
142
120
|
when NegRange
|
143
121
|
final_value = (arg.exclude_end?)? (arg.last - 1) : arg.last
|
144
|
-
R::Support.eval(
|
122
|
+
R::Support.eval('seq').call(arg.first, final_value)
|
145
123
|
when Range
|
146
124
|
final_value = (arg.exclude_end?)? (arg.last - 1) : arg.last
|
147
|
-
R::Support.eval(
|
125
|
+
R::Support.eval('seq').call(arg.first, final_value)
|
148
126
|
when :all
|
149
127
|
R.empty_symbol
|
150
128
|
when Symbol
|
151
|
-
arg = R::Support.eval(
|
129
|
+
arg = R::Support.eval('as.name').call(arg.to_s.gsub(/__/,"."))
|
152
130
|
when Proc, Method
|
153
131
|
R::RubyCallback.build(arg)
|
154
|
-
#
|
155
|
-
#
|
156
|
-
else
|
132
|
+
# This is a Ruby argument that will be automatically converted
|
133
|
+
# by the low level Polyglot interface to R
|
134
|
+
else
|
157
135
|
arg
|
158
136
|
end
|
159
137
|
|
160
138
|
end
|
139
|
+
|
140
|
+
#----------------------------------------------------------------------------------------
|
141
|
+
# Given a hash, convert it to an R argument list
|
142
|
+
#----------------------------------------------------------------------------------------
|
143
|
+
|
144
|
+
def self.parse_hash(hsh, lst)
|
145
|
+
|
146
|
+
hsh.each_pair do |key, value|
|
147
|
+
k = key.to_s.gsub(/__/,".")
|
148
|
+
|
149
|
+
case
|
150
|
+
when (value.is_a? NotAvailable)
|
151
|
+
na_named = R::Support.eval("`names<-`").call(value.r_interop, k)
|
152
|
+
lst = R::Support.eval("c").call(lst, na_named)
|
153
|
+
when (k == 'all')
|
154
|
+
lst = R::Support.eval("`[[<-`").
|
155
|
+
call(lst, R::Support.eval('`+`').
|
156
|
+
call(R::Support.eval('length').call(lst), 1),
|
157
|
+
R::Support.parse_arg(value))
|
158
|
+
else
|
159
|
+
lst = R::Support.eval("`[[<-`").
|
160
|
+
call(lst, k, R::Support.parse_arg(value))
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
lst
|
165
|
+
|
166
|
+
end
|
161
167
|
|
162
168
|
#----------------------------------------------------------------------------------------
|
163
169
|
# Parses the Ruby arguments into a R list of R objects
|
@@ -165,40 +171,25 @@ module R
|
|
165
171
|
#----------------------------------------------------------------------------------------
|
166
172
|
|
167
173
|
def self.parse2list(*args)
|
168
|
-
|
174
|
+
|
169
175
|
params = Polyglot.eval("R", "list()")
|
170
176
|
|
171
177
|
args.each_with_index do |arg, i|
|
172
178
|
if (arg.is_a? Hash)
|
173
|
-
|
174
|
-
k = key.to_s.gsub(/__/,".")
|
175
|
-
# HAS CHANGED IN RC6... @TODO: THIS TO THE NEW API
|
176
|
-
# When evaluating to NA, Interop treats it as FALSE. This breaks
|
177
|
-
# all expectations about NA. We need to protect NA from Interop
|
178
|
-
# unboxing. Class NotAvailable
|
179
|
-
# puts a list around NA, so that no unboxing occurs. We need to treat this
|
180
|
-
# list here
|
181
|
-
if (value.is_a? NotAvailable)
|
182
|
-
# add the key as the name of the NA
|
183
|
-
na_named = R::Support.eval("`names<-`").call(value.r_interop, k)
|
184
|
-
params = R::Support.eval("c").call(params, na_named)
|
185
|
-
else
|
186
|
-
params = R::Support.eval("`[[<-`").
|
187
|
-
call(params, k, R::Support.parse_arg(value))
|
188
|
-
end
|
189
|
-
end
|
179
|
+
params = parse_hash(arg, params)
|
190
180
|
elsif (arg.is_a? NotAvailable)
|
191
181
|
params = R::Support.eval("c").call(params, arg.r_interop)
|
182
|
+
elsif (arg.is_a? NilClass)
|
183
|
+
params = R::Support.eval("`length<-`").call(params, i+1)
|
192
184
|
else
|
193
185
|
params = R::Support.eval("`[[<-`").
|
194
186
|
call(params, i+1, R::Support.parse_arg(arg))
|
195
187
|
end
|
196
188
|
end
|
197
|
-
|
189
|
+
|
198
190
|
# if the parameter is an empty list, then add the element NULL to the list
|
199
191
|
(Polyglot.eval("R", "length").call(params) == 0) ?
|
200
192
|
Polyglot.eval("R", "list").call(nil) : params
|
201
|
-
# params
|
202
193
|
|
203
194
|
end
|
204
195
|
|
@@ -253,14 +244,14 @@ module R
|
|
253
244
|
# of the output is greater than 0
|
254
245
|
if (@@exec_counter == 0)
|
255
246
|
R::Support.stop_capture.call(@@con)
|
256
|
-
|
247
|
+
=begin
|
257
248
|
if (R::Support.eval("length(r_capture) > 0")[0])
|
258
249
|
cap = R::Object.build(R::Support.eval("r_capture"))
|
259
250
|
(0...cap.size).each do |i|
|
260
251
|
puts cap << i
|
261
252
|
end
|
262
253
|
end
|
263
|
-
|
254
|
+
=end
|
264
255
|
end
|
265
256
|
|
266
257
|
rescue StandardError => e
|
@@ -278,7 +269,8 @@ module R
|
|
278
269
|
#----------------------------------------------------------------------------------------
|
279
270
|
|
280
271
|
def self.exec_function_name(function_name, *args)
|
281
|
-
# TODO: should check
|
272
|
+
# @TODO: should check all that can go wrong when calling eval(function_name) to
|
273
|
+
# raise the proper exception
|
282
274
|
f = R::Support.eval(function_name)
|
283
275
|
R::Support.exec_function(f, *args)
|
284
276
|
end
|
@@ -289,7 +281,7 @@ module R
|
|
289
281
|
|
290
282
|
def self.exec_function_i(function, *args)
|
291
283
|
pl = R::Support.parse2list(*args)
|
292
|
-
R::Support.eval("
|
284
|
+
R::Support.eval("invoke").call(function, pl)
|
293
285
|
end
|
294
286
|
|
295
287
|
#----------------------------------------------------------------------------------------
|
@@ -348,13 +340,12 @@ module R
|
|
348
340
|
#
|
349
341
|
#----------------------------------------------------------------------------------------
|
350
342
|
|
351
|
-
|
352
343
|
def self.print_str(obj)
|
353
344
|
|
354
345
|
lst = obj.as__list
|
355
346
|
puts lst
|
356
347
|
=begin
|
357
|
-
(1..lst.length
|
348
|
+
(1..lst.length >> 0).each do |i|
|
358
349
|
puts lst[[i]]
|
359
350
|
end
|
360
351
|
=end
|
@@ -384,3 +375,28 @@ end
|
|
384
375
|
|
385
376
|
require_relative 'r_module_s'
|
386
377
|
require_relative 'rsupport_scope'
|
378
|
+
|
379
|
+
|
380
|
+
=begin
|
381
|
+
#----------------------------------------------------------------------------------------
|
382
|
+
# Builds a quo or a formula based on the given expression. If the expression has a
|
383
|
+
# '=~' operator, then a formula should be constructed, if not, then an quo should be
|
384
|
+
# constructed
|
385
|
+
# @param expression [R::Expression]
|
386
|
+
# @return quo or formula
|
387
|
+
#----------------------------------------------------------------------------------------
|
388
|
+
|
389
|
+
def self.quo_or_formula(expression)
|
390
|
+
|
391
|
+
if expression.formula?
|
392
|
+
R.as__formula(expression.infix)
|
393
|
+
else
|
394
|
+
# add a '~' before the expression so we can parse it as an
|
395
|
+
# R expression from a string. Didn't find a good way of creating an
|
396
|
+
# expression from string.
|
397
|
+
# R.as_quosure(R.as__formula("~ #{expression.infix}"))
|
398
|
+
R.rhs(R.as__formula("~ #{expression.infix}"))
|
399
|
+
end
|
400
|
+
|
401
|
+
end
|
402
|
+
=end
|
data/lib/R_interface/rsymbol.rb
CHANGED
@@ -106,7 +106,8 @@ end
|
|
106
106
|
class Symbol
|
107
107
|
include R::BinaryOperators
|
108
108
|
include R::ExpBinOp
|
109
|
-
|
109
|
+
include R::LogicalOperators
|
110
|
+
|
110
111
|
#--------------------------------------------------------------------------------------
|
111
112
|
# Unary '+' converts a Ruby Symbol into an R Symbol
|
112
113
|
#--------------------------------------------------------------------------------------
|
@@ -157,6 +158,14 @@ class Symbol
|
|
157
158
|
#
|
158
159
|
#--------------------------------------------------------------------------------------
|
159
160
|
|
161
|
+
def assign2(expression)
|
162
|
+
exec_bin_oper("`=`", expression)
|
163
|
+
end
|
164
|
+
|
165
|
+
#--------------------------------------------------------------------------------------
|
166
|
+
#
|
167
|
+
#--------------------------------------------------------------------------------------
|
168
|
+
|
160
169
|
def [](index)
|
161
170
|
exec_bin_oper("`[[`", index)
|
162
171
|
end
|
@@ -169,7 +178,7 @@ class Symbol
|
|
169
178
|
|
170
179
|
if (symbol =~ /(.*)=$/)
|
171
180
|
# method_missing_assign($1, args[0])
|
172
|
-
elsif (args.length == 0 && ((R.c(symbol.to_s)._ :in, R.names(self))
|
181
|
+
elsif (args.length == 0 && ((R.c(symbol.to_s)._ :in, R.names(self)) >> 0))
|
173
182
|
return self[symbol.to_s]
|
174
183
|
end
|
175
184
|
|