galaaz 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +32 -0
- data/Rakefile +177 -0
- data/bin/galaaz +8 -0
- data/examples/50Plots_MasterList/scatter_plot.rb +51 -0
- data/examples/baseball.csv +1 -0
- data/examples/baseball.rb +16 -0
- data/examples/ggplot.rb +178 -0
- data/examples/islr/Figure.jpg +0 -0
- data/examples/islr/all.rb +32 -0
- data/examples/islr/ch2.spec.rb +148 -0
- data/examples/islr/ch3.spec.rb +28 -0
- data/examples/islr/ch3_boston.rb +77 -0
- data/examples/islr/ch3_multiple_regression.rb +36 -0
- data/examples/islr/ch6.spec.rb +64 -0
- data/examples/paper/paper.rb +36 -0
- data/examples/sthda_ggplot/README.md +38 -0
- data/examples/sthda_ggplot/all.rb +68 -0
- data/examples/sthda_ggplot/one_variable_continuous/density_gg.rb +52 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_area.rb +61 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_density.rb +77 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_dotplot.rb +69 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_freqpoly.rb +69 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_histogram.rb +62 -0
- data/examples/sthda_ggplot/one_variable_continuous/histogram_density.rb +55 -0
- data/examples/sthda_ggplot/one_variable_continuous/stat.rb +62 -0
- data/examples/sthda_ggplot/one_variable_discrete/bar.rb +54 -0
- data/examples/sthda_ggplot/qplots/box_violin_dot.rb +57 -0
- data/examples/sthda_ggplot/qplots/scatter_plots.rb +67 -0
- data/examples/sthda_ggplot/scatter_gg.rb +60 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_bin2d.rb +49 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_density2d.rb +64 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_hex.rb +52 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/geom_point.rb +65 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/geom_smooth.rb +66 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/misc.rb +83 -0
- data/examples/sthda_ggplot/two_variables_cont_function/geom_area.rb +63 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_bar.rb +85 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_boxplot.rb +62 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +75 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +74 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_line.rb +55 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +70 -0
- data/examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb +40 -0
- data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +108 -0
- data/examples/subsetting.rb +372 -0
- data/lib/expression.rb +45 -0
- data/lib/galaaz.rb +27 -0
- data/lib/r.rb +118 -0
- data/lib/r_methods.rb +89 -0
- data/lib/rbinary_operators.rb +226 -0
- data/lib/rclosure.rb +34 -0
- data/lib/rdata_frame.rb +63 -0
- data/lib/renvironment.rb +34 -0
- data/lib/rexpression.rb +34 -0
- data/lib/rindexed_object.rb +68 -0
- data/lib/rlanguage.rb +64 -0
- data/lib/rlist.rb +72 -0
- data/lib/rmatrix.rb +38 -0
- data/lib/rmd_indexed_object.rb +43 -0
- data/lib/robject.rb +297 -0
- data/lib/rpkg.rb +53 -0
- data/lib/rsupport.rb +292 -0
- data/lib/rsupport_scope.rb +77 -0
- data/lib/rsymbol.rb +57 -0
- data/lib/ruby_callback.rb +83 -0
- data/lib/ruby_extensions.rb +74 -0
- data/lib/runary_operators.rb +58 -0
- data/lib/rvector.rb +117 -0
- data/r_requires/ggplot.rb +31 -0
- data/specs/all.rb +45 -0
- data/specs/r_dataframe.spec.rb +181 -0
- data/specs/r_eval.spec.rb +164 -0
- data/specs/r_function.spec.rb +105 -0
- data/specs/r_language.spec.rb +135 -0
- data/specs/r_list.spec.rb +129 -0
- data/specs/r_list_apply.spec.rb +99 -0
- data/specs/r_matrix.spec.rb +83 -0
- data/specs/r_vector_creation.spec.rb +99 -0
- data/specs/r_vector_functions.spec.rb +59 -0
- data/specs/r_vector_object.spec.rb +94 -0
- data/specs/r_vector_operators.spec.rb +174 -0
- data/specs/r_vector_subsetting.spec.rb +136 -0
- data/specs/tmp.rb +134 -0
- data/version.rb +2 -0
- metadata +198 -0
data/lib/expression.rb
ADDED
@@ -0,0 +1,45 @@
|
|
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 E
|
25
|
+
|
26
|
+
#----------------------------------------------------------------------------------------
|
27
|
+
# @param symbol [Symbol]
|
28
|
+
# @param args [Array] arguments to the missing method
|
29
|
+
#----------------------------------------------------------------------------------------
|
30
|
+
|
31
|
+
def self.method_missing(symbol, *args)
|
32
|
+
name = R::Support.convert_symbol2r(symbol)
|
33
|
+
R::Language.build(name, *args)
|
34
|
+
end
|
35
|
+
|
36
|
+
#--------------------------------------------------------------------------------------
|
37
|
+
#
|
38
|
+
#--------------------------------------------------------------------------------------
|
39
|
+
|
40
|
+
def self.[](executable)
|
41
|
+
R::RubyCallback.build(executable)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
data/lib/galaaz.rb
ADDED
@@ -0,0 +1,27 @@
|
|
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 'r'
|
25
|
+
|
26
|
+
$LOAD_PATH << File.dirname(File.expand_path('..', __FILE__)) + "/r_requires"
|
27
|
+
|
data/lib/r.rb
ADDED
@@ -0,0 +1,118 @@
|
|
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'
|
data/lib/r_methods.rb
ADDED
@@ -0,0 +1,89 @@
|
|
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 Support
|
27
|
+
|
28
|
+
#--------------------------------------------------------------------------------------
|
29
|
+
# Captures the R output to a variable and returns it.
|
30
|
+
#--------------------------------------------------------------------------------------
|
31
|
+
|
32
|
+
def self.capture
|
33
|
+
|
34
|
+
Polyglot.eval("R", <<-R)
|
35
|
+
function(obj, ...) {
|
36
|
+
sink(tt <- textConnection("results","w"), split=FALSE);
|
37
|
+
print(obj, ...);
|
38
|
+
sink();
|
39
|
+
close(tt);
|
40
|
+
results
|
41
|
+
}
|
42
|
+
R
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
#--------------------------------------------------------------------------------------
|
47
|
+
# multi-dimensional indexing
|
48
|
+
#--------------------------------------------------------------------------------------
|
49
|
+
|
50
|
+
def self.md_index
|
51
|
+
Polyglot.eval("R", <<-R)
|
52
|
+
function(mdobject, ...) {
|
53
|
+
mdobject[...];
|
54
|
+
}
|
55
|
+
R
|
56
|
+
end
|
57
|
+
|
58
|
+
#--------------------------------------------------------------------------------------
|
59
|
+
# R function that returns another R function that calls back a Ruby Method or Proc
|
60
|
+
# Some R functions that receive a function as argument will test to see if their
|
61
|
+
# parameters is a function or a symbol, so the Ruby method needs to be wrapped inside
|
62
|
+
# an R function in order for it to pass this test.
|
63
|
+
#--------------------------------------------------------------------------------------
|
64
|
+
|
65
|
+
def self.ruby_callback_method
|
66
|
+
Polyglot.eval("R", <<-R)
|
67
|
+
function(rb_method) {
|
68
|
+
function(...) {
|
69
|
+
rb_method(...)
|
70
|
+
}
|
71
|
+
}
|
72
|
+
R
|
73
|
+
end
|
74
|
+
|
75
|
+
#--------------------------------------------------------------------------------------
|
76
|
+
# @bug Needed to create method row__names because dispatch is not working properly
|
77
|
+
#--------------------------------------------------------------------------------------
|
78
|
+
|
79
|
+
def self.set_row_names
|
80
|
+
Polyglot.eval("R", "function(object, x) row.names(object) <- x")
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.get_row_names
|
84
|
+
Polyglot.eval("R", "function(x) row.names(x)")
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,226 @@
|
|
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
|
+
#--------------------------------------------------------------------------------------
|
27
|
+
# Module for binary operators with normal elements: matrix, vector, etc.
|
28
|
+
#--------------------------------------------------------------------------------------
|
29
|
+
|
30
|
+
module ExecBinOp
|
31
|
+
|
32
|
+
#--------------------------------------------------------------------------------------
|
33
|
+
#
|
34
|
+
#--------------------------------------------------------------------------------------
|
35
|
+
|
36
|
+
def exec_oper(operator, other_object)
|
37
|
+
R::Support.exec_function_name(operator, @r_interop, other_object)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
#--------------------------------------------------------------------------------------
|
43
|
+
# Module for binary operators when creating an expression (call)
|
44
|
+
#--------------------------------------------------------------------------------------
|
45
|
+
|
46
|
+
module CallBinOp
|
47
|
+
|
48
|
+
#--------------------------------------------------------------------------------------
|
49
|
+
#
|
50
|
+
#--------------------------------------------------------------------------------------
|
51
|
+
|
52
|
+
def exec_oper(operator, other_object)
|
53
|
+
R::Language.build(operator, self, other_object)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
#--------------------------------------------------------------------------------------
|
59
|
+
# Module for binary operators when creating formulas
|
60
|
+
#--------------------------------------------------------------------------------------
|
61
|
+
|
62
|
+
module FormulaBinOp
|
63
|
+
#--------------------------------------------------------------------------------------
|
64
|
+
#
|
65
|
+
#--------------------------------------------------------------------------------------
|
66
|
+
|
67
|
+
def prep_object(object)
|
68
|
+
|
69
|
+
case object
|
70
|
+
when :all
|
71
|
+
'.'
|
72
|
+
when R::RSymbol, Symbol
|
73
|
+
object.to_s
|
74
|
+
when R::Language
|
75
|
+
R.deparse(object).substring(2)
|
76
|
+
when String
|
77
|
+
object
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
#--------------------------------------------------------------------------------------
|
83
|
+
#
|
84
|
+
#--------------------------------------------------------------------------------------
|
85
|
+
|
86
|
+
def exec_oper(operator, other_object, response = false)
|
87
|
+
|
88
|
+
o1 = prep_object(self)
|
89
|
+
o2 = prep_object(other_object)
|
90
|
+
|
91
|
+
response ? R.reformulate(o2, response: o1) :
|
92
|
+
R.reformulate(R.paste0(o1, operator.delete("`"), o2))
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
#--------------------------------------------------------------------------------------
|
99
|
+
# Note that binary operators work on vectors and matrices as well as scalars.
|
100
|
+
#--------------------------------------------------------------------------------------
|
101
|
+
|
102
|
+
module BinaryOperators
|
103
|
+
|
104
|
+
#--------------------------------------------------------------------------------------
|
105
|
+
# @param other_object
|
106
|
+
#--------------------------------------------------------------------------------------
|
107
|
+
|
108
|
+
def +(other_object)
|
109
|
+
exec_oper("`+`", other_object)
|
110
|
+
end
|
111
|
+
|
112
|
+
#--------------------------------------------------------------------------------------
|
113
|
+
#
|
114
|
+
#--------------------------------------------------------------------------------------
|
115
|
+
|
116
|
+
def -(other_object)
|
117
|
+
exec_oper("`-`", other_object)
|
118
|
+
end
|
119
|
+
|
120
|
+
#--------------------------------------------------------------------------------------
|
121
|
+
#
|
122
|
+
#--------------------------------------------------------------------------------------
|
123
|
+
|
124
|
+
def *(other_object)
|
125
|
+
exec_oper("`*`", other_object)
|
126
|
+
end
|
127
|
+
|
128
|
+
#--------------------------------------------------------------------------------------
|
129
|
+
#
|
130
|
+
#--------------------------------------------------------------------------------------
|
131
|
+
|
132
|
+
def /(other_object)
|
133
|
+
exec_oper("`/`", other_object)
|
134
|
+
end
|
135
|
+
|
136
|
+
#--------------------------------------------------------------------------------------
|
137
|
+
#
|
138
|
+
#--------------------------------------------------------------------------------------
|
139
|
+
|
140
|
+
def **(other_object)
|
141
|
+
exec_oper("`^`", other_object)
|
142
|
+
end
|
143
|
+
|
144
|
+
#--------------------------------------------------------------------------------------
|
145
|
+
#
|
146
|
+
#--------------------------------------------------------------------------------------
|
147
|
+
|
148
|
+
def %(other_object)
|
149
|
+
exec_oper("`%%`", other_object)
|
150
|
+
end
|
151
|
+
|
152
|
+
#--------------------------------------------------------------------------------------
|
153
|
+
#
|
154
|
+
#--------------------------------------------------------------------------------------
|
155
|
+
|
156
|
+
def ==(other_object)
|
157
|
+
exec_oper("`==`", other_object)
|
158
|
+
end
|
159
|
+
|
160
|
+
#--------------------------------------------------------------------------------------
|
161
|
+
#
|
162
|
+
#--------------------------------------------------------------------------------------
|
163
|
+
|
164
|
+
def <(other_object)
|
165
|
+
exec_oper("`<`", other_object)
|
166
|
+
end
|
167
|
+
|
168
|
+
#--------------------------------------------------------------------------------------
|
169
|
+
#
|
170
|
+
#--------------------------------------------------------------------------------------
|
171
|
+
|
172
|
+
def <=(other_object)
|
173
|
+
exec_oper("`<=`", other_object)
|
174
|
+
end
|
175
|
+
|
176
|
+
#--------------------------------------------------------------------------------------
|
177
|
+
#
|
178
|
+
#--------------------------------------------------------------------------------------
|
179
|
+
|
180
|
+
def >(other_object)
|
181
|
+
exec_oper("`>`", other_object)
|
182
|
+
end
|
183
|
+
|
184
|
+
#--------------------------------------------------------------------------------------
|
185
|
+
#
|
186
|
+
#--------------------------------------------------------------------------------------
|
187
|
+
|
188
|
+
def >=(other_object)
|
189
|
+
exec_oper("`>=`", other_object)
|
190
|
+
end
|
191
|
+
|
192
|
+
#--------------------------------------------------------------------------------------
|
193
|
+
#
|
194
|
+
#--------------------------------------------------------------------------------------
|
195
|
+
|
196
|
+
def !=(other_object)
|
197
|
+
exec_oper("`!=`", other_object)
|
198
|
+
end
|
199
|
+
|
200
|
+
#--------------------------------------------------------------------------------------
|
201
|
+
#
|
202
|
+
#--------------------------------------------------------------------------------------
|
203
|
+
|
204
|
+
def &(other_object)
|
205
|
+
R::Support.exec_function_name("`&`", @r_interop, other_object.r_interop)
|
206
|
+
end
|
207
|
+
|
208
|
+
#--------------------------------------------------------------------------------------
|
209
|
+
#
|
210
|
+
#--------------------------------------------------------------------------------------
|
211
|
+
|
212
|
+
def |(other_object)
|
213
|
+
R::Support.exec_function_name("`|`", @r_interop, other_object.r_interop)
|
214
|
+
end
|
215
|
+
|
216
|
+
#--------------------------------------------------------------------------------------
|
217
|
+
#
|
218
|
+
#--------------------------------------------------------------------------------------
|
219
|
+
|
220
|
+
def coerce(numeric)
|
221
|
+
[R.c(numeric), self]
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|