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
@@ -24,6 +24,8 @@
|
|
24
24
|
require 'galaaz'
|
25
25
|
require 'ggplot'
|
26
26
|
|
27
|
+
R.install_and_loads('Hmisc')
|
28
|
+
|
27
29
|
tooth_growth = ~:ToothGrowth
|
28
30
|
tooth_growth.dose = tooth_growth.dose.as__factor
|
29
31
|
puts tooth_growth
|
@@ -39,11 +41,9 @@ sleep(2)
|
|
39
41
|
R.grid__newpage
|
40
42
|
|
41
43
|
# Dot plot with mean points (+/- SD)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
# R.stat_summary(fun__data: "mean_sdl", fun__args: E.list(mult: 1),
|
46
|
-
# geom: "pointrange", color: "red")
|
44
|
+
print e + R.geom_dotplot(binaxis: "y", stackdir: "center") +
|
45
|
+
R.stat_summary(fun__data: "mean_sdl", fun__args: E.list(mult: 1),
|
46
|
+
geom: "pointrange", color: "red")
|
47
47
|
|
48
48
|
sleep(2)
|
49
49
|
R.grid__newpage
|
@@ -23,10 +23,7 @@
|
|
23
23
|
|
24
24
|
require 'galaaz'
|
25
25
|
require 'ggplot'
|
26
|
-
|
27
|
-
# Package Hmisc does not yet install on graalvm because of
|
28
|
-
# problems with package data.table
|
29
|
-
# Polyglot.eval("R", "library('Hmisc')")
|
26
|
+
R.install_and_loads('Hmisc')
|
30
27
|
|
31
28
|
tooth_growth = ~:ToothGrowth
|
32
29
|
tooth_growth.dose = tooth_growth.dose.as__factor
|
@@ -43,13 +40,12 @@ sleep(2)
|
|
43
40
|
R.grid__newpage
|
44
41
|
|
45
42
|
# violin plot with mean points (+/- SD)
|
46
|
-
# R.stat_summary requires Hmisc
|
47
43
|
print e + R.geom_violin(trim: false) +
|
48
44
|
R.stat_summary(fun__data: "mean_sdl", fun__args: E.list(mult: 1),
|
49
45
|
geom: "pointrange", color: "red")
|
50
46
|
|
51
|
-
|
52
|
-
|
47
|
+
sleep(2)
|
48
|
+
R.grid__newpage
|
53
49
|
|
54
50
|
# Combine with box plot
|
55
51
|
print e + R.geom_violin(trim: false) +
|
@@ -24,6 +24,8 @@
|
|
24
24
|
require 'galaaz'
|
25
25
|
require 'ggplot'
|
26
26
|
|
27
|
+
R.install_and_loads('Hmisc')
|
28
|
+
|
27
29
|
df = ~:ToothGrowth
|
28
30
|
df.dose = df.dose.as__factor
|
29
31
|
puts df.head
|
@@ -51,7 +53,7 @@ puts df3.head
|
|
51
53
|
R.awt
|
52
54
|
|
53
55
|
# Default plot
|
54
|
-
|
56
|
+
puts f + R.geom_crossbar
|
55
57
|
|
56
58
|
sleep(2)
|
57
59
|
R.grid__newpage
|
data/lib/R_interface/r.rb
CHANGED
@@ -67,7 +67,16 @@ module R
|
|
67
67
|
packages = R.c(libs)
|
68
68
|
|
69
69
|
new_packages = packages[!(packages._ :in, R.installed__packages[:all, "Package"])]
|
70
|
+
|
70
71
|
if(new_packages.size > 0)
|
72
|
+
|
73
|
+
# package 'data_table' cannot be installed by install.packages. FastR implements
|
74
|
+
# install.fastr.packages for installing 'data_table'
|
75
|
+
if ((R.c('data.table')._ :in, new_packages) >> 0)
|
76
|
+
new_packages = new_packages[!'data_table']
|
77
|
+
R.install__fastr__packages('data_table')
|
78
|
+
end
|
79
|
+
|
71
80
|
puts "The following packages are missing and will be installed:\n #{new_packages}"
|
72
81
|
R.install__packages(new_packages)
|
73
82
|
end
|
@@ -89,6 +98,9 @@ end
|
|
89
98
|
require_relative 'rbinary_operators'
|
90
99
|
# Unary operators: '!', '@-', etc
|
91
100
|
require_relative 'runary_operators'
|
101
|
+
# Logical operators
|
102
|
+
require_relative 'rlogical_operators'
|
103
|
+
|
92
104
|
# Ruby class extensions. Extends Symbol to allow the creation of
|
93
105
|
# expressions using Symbol: (:x > 10)
|
94
106
|
require_relative 'ruby_extensions'
|
@@ -121,12 +133,3 @@ require_relative 'rpkg'
|
|
121
133
|
|
122
134
|
# Class to allow R calling back into Ruby
|
123
135
|
require_relative 'ruby_callback'
|
124
|
-
|
125
|
-
# R packages and functions needed
|
126
|
-
# Requires ggplot for plotting graphics
|
127
|
-
# require 'ggplot'
|
128
|
-
# require 'knitr'
|
129
|
-
|
130
|
-
# Methods to capture a plot sent to a device
|
131
|
-
require_relative 'rdevices'
|
132
|
-
|
@@ -22,9 +22,9 @@
|
|
22
22
|
##########################################################################################
|
23
23
|
|
24
24
|
module R
|
25
|
-
|
25
|
+
|
26
26
|
module Support
|
27
|
-
|
27
|
+
|
28
28
|
#--------------------------------------------------------------------------------------
|
29
29
|
# Captures the R output to a variable and returns it.
|
30
30
|
#--------------------------------------------------------------------------------------
|
@@ -189,27 +189,9 @@ module R
|
|
189
189
|
#
|
190
190
|
#--------------------------------------------------------------------------------------
|
191
191
|
|
192
|
-
def &(other_object)
|
193
|
-
exec_bin_oper("`&`", other_object)
|
194
|
-
end
|
195
|
-
|
196
|
-
alias_method :and, :&
|
197
|
-
|
198
|
-
#--------------------------------------------------------------------------------------
|
199
|
-
#
|
200
|
-
#--------------------------------------------------------------------------------------
|
201
|
-
|
202
|
-
def |(other_object)
|
203
|
-
exec_bin_oper("`|`", other_object)
|
204
|
-
end
|
205
|
-
|
206
|
-
alias_method :or, :|
|
207
|
-
|
208
|
-
#--------------------------------------------------------------------------------------
|
209
|
-
#
|
210
|
-
#--------------------------------------------------------------------------------------
|
211
|
-
|
212
192
|
def til(other_object)
|
193
|
+
return R::Support.exec_function_name("`~`", other_object) if
|
194
|
+
((self.is_a? Symbol) && (self == :all))
|
213
195
|
exec_bin_oper("`~`", other_object)
|
214
196
|
end
|
215
197
|
|
@@ -25,8 +25,8 @@ module R
|
|
25
25
|
|
26
26
|
class DataFrame < List
|
27
27
|
include MDIndexedObject
|
28
|
-
|
29
|
-
|
28
|
+
include Enumerable
|
29
|
+
|
30
30
|
#--------------------------------------------------------------------------------------
|
31
31
|
# Calls the R.qplot adding the data: parameter
|
32
32
|
#--------------------------------------------------------------------------------------
|
@@ -39,26 +39,73 @@ module R
|
|
39
39
|
#
|
40
40
|
#--------------------------------------------------------------------------------------
|
41
41
|
|
42
|
-
def
|
42
|
+
def method_missing_assign(column_name, arg)
|
43
|
+
setR_name("`[<-`", R.empty_symbol, column_name, arg)
|
44
|
+
end
|
45
|
+
|
46
|
+
#--------------------------------------------------------------------------------------
|
47
|
+
# subset assign a vector with an index to a value
|
48
|
+
# @param index [Array] The vector index
|
49
|
+
# @param values [R::Object] The values to assign to the index. Note that
|
50
|
+
# index can span multiple
|
51
|
+
# values, for ex., R.c(2, 3, 5)
|
52
|
+
#--------------------------------------------------------------------------------------
|
53
|
+
|
54
|
+
def []=(index, values)
|
55
|
+
|
56
|
+
# dealing with double indexing function '[['
|
57
|
+
if (index.is_a? Array)
|
58
|
+
setR_name("`[[<-`", R.empty_symbol, *index, values)
|
59
|
+
else
|
60
|
+
setR_name("`[<-`", R.empty_symbol, index, values)
|
61
|
+
end
|
43
62
|
|
44
|
-
|
45
|
-
|
63
|
+
self
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
#--------------------------------------------------------------------------------------
|
68
|
+
# Goes through each row of the dataframe and return the whole row as the first element
|
69
|
+
# and the row name (Ruby string) as the second
|
70
|
+
#--------------------------------------------------------------------------------------
|
71
|
+
|
72
|
+
def each_row
|
73
|
+
|
74
|
+
# nrow is the R function that return the number of rows in the dataset. This
|
75
|
+
# function returns a R::Vector, so we need to extract its first element (<< 0)
|
76
|
+
(1..nrow >> 0).each do |i|
|
77
|
+
yield self[i, :all], self.rownames[i] >> 0
|
46
78
|
end
|
47
79
|
|
48
80
|
end
|
49
81
|
|
50
82
|
#--------------------------------------------------------------------------------------
|
51
|
-
#
|
83
|
+
# Goes through each column of the dataframe and return the whole column as the first
|
84
|
+
# element and the column name (Ruby string) as the second
|
52
85
|
#--------------------------------------------------------------------------------------
|
53
86
|
|
54
87
|
def each_column
|
55
88
|
|
56
|
-
|
57
|
-
|
89
|
+
# ncol is the R function that return the number of columns in the dataset. This
|
90
|
+
# function returns a R::Vector, so we need to extract its first element (<< 0)
|
91
|
+
(1..ncol >> 0).each do |i|
|
92
|
+
yield self[:all, i], self.names[i] >> 0
|
58
93
|
end
|
59
94
|
|
60
95
|
end
|
61
|
-
|
96
|
+
|
97
|
+
#=begin
|
98
|
+
#--------------------------------------------------------------------------------------
|
99
|
+
# @TODO Need to understand why to_ary is being called here and what the effect is of
|
100
|
+
# returning the empty array. For now, doing this returns better error messages in
|
101
|
+
# rspec
|
102
|
+
#--------------------------------------------------------------------------------------
|
103
|
+
|
104
|
+
def to_ary
|
105
|
+
[]
|
106
|
+
end
|
107
|
+
#=end
|
108
|
+
|
62
109
|
end
|
63
110
|
|
64
111
|
end
|
data/lib/R_interface/rdevices.R
CHANGED
@@ -1,15 +1,3 @@
|
|
1
|
-
#" Capture snapshot of current device.
|
2
|
-
#"
|
3
|
-
#" There's currently no way to capture when a graphics device changes,
|
4
|
-
#" except to check its contents after the evaluation of every expression.
|
5
|
-
#" This means that only the last plot of a series will be captured.
|
6
|
-
#"
|
7
|
-
#" @return \code{NULL} if plot is blank or unchanged, otherwise the output of
|
8
|
-
#" \code{\link[grDevices]{recordPlot}}.
|
9
|
-
_plot_snapshot = function() {
|
10
|
-
evaluate:::plot_snapshot()
|
11
|
-
}
|
12
|
-
|
13
1
|
# Function accessible from Galaaz to call non-exported knitr:::chunk_device function
|
14
2
|
_ck_dv = function(width, height, record = TRUE, dev, dev.args, dpi, options,
|
15
3
|
tmp = tempfile()) {
|
@@ -22,56 +22,7 @@
|
|
22
22
|
##########################################################################################
|
23
23
|
|
24
24
|
module R
|
25
|
-
=begin
|
26
|
-
#--------------------------------------------------------------------------------------
|
27
|
-
#
|
28
|
-
#--------------------------------------------------------------------------------------
|
29
|
-
|
30
|
-
class Expression
|
31
|
-
include BinaryOperators
|
32
|
-
include ExpBinOp
|
33
|
-
include UnaryOperators
|
34
|
-
include ExpUniOp
|
35
|
-
|
36
|
-
attr_reader :infix
|
37
|
-
attr_reader :prefix
|
38
|
-
attr_reader :formula
|
39
|
-
attr_accessor :environment
|
40
|
-
|
41
|
-
#--------------------------------------------------------------------------------------
|
42
|
-
#
|
43
|
-
#--------------------------------------------------------------------------------------
|
44
|
-
|
45
|
-
def to_s
|
46
|
-
@infix
|
47
|
-
end
|
48
|
-
|
49
|
-
#--------------------------------------------------------------------------------------
|
50
|
-
#
|
51
|
-
#--------------------------------------------------------------------------------------
|
52
|
-
|
53
|
-
def formula?
|
54
|
-
@formula
|
55
|
-
end
|
56
|
-
|
57
|
-
#--------------------------------------------------------------------------------------
|
58
|
-
#
|
59
|
-
#--------------------------------------------------------------------------------------
|
60
|
-
|
61
|
-
# private
|
62
|
-
|
63
|
-
#--------------------------------------------------------------------------------------
|
64
|
-
#
|
65
|
-
#--------------------------------------------------------------------------------------
|
66
|
-
|
67
|
-
def initialize(infix, formula = false)
|
68
|
-
@infix = infix
|
69
|
-
@formula = formula
|
70
|
-
@environment = R.list
|
71
|
-
end
|
72
25
|
|
73
|
-
end
|
74
|
-
=end
|
75
26
|
#--------------------------------------------------------------------------------------
|
76
27
|
#
|
77
28
|
#--------------------------------------------------------------------------------------
|
@@ -90,51 +41,3 @@ module R
|
|
90
41
|
|
91
42
|
end
|
92
43
|
|
93
|
-
#=========================================================================================
|
94
|
-
#
|
95
|
-
#=========================================================================================
|
96
|
-
=begin
|
97
|
-
module E
|
98
|
-
|
99
|
-
#----------------------------------------------------------------------------------------
|
100
|
-
# @param symbol [Symbol]
|
101
|
-
# @param args [Array] arguments to the missing method
|
102
|
-
#----------------------------------------------------------------------------------------
|
103
|
-
|
104
|
-
def self.method_missing(symbol, *args)
|
105
|
-
name = R::Support.convert_symbol2r(symbol)
|
106
|
-
|
107
|
-
params = []
|
108
|
-
args.each do |arg|
|
109
|
-
params << R::Expression.parse_expression(arg)
|
110
|
-
end
|
111
|
-
exp = "#{name}(#{params.join(", ")})"
|
112
|
-
|
113
|
-
# rhs = R.rhs(R.as__formula("~ #{exp}"))
|
114
|
-
# R.enq(rhs)
|
115
|
-
|
116
|
-
R::Expression.new(exp)
|
117
|
-
end
|
118
|
-
|
119
|
-
#=begin
|
120
|
-
#----------------------------------------------------------------------------------------
|
121
|
-
# @param symbol [Symbol]
|
122
|
-
# @param args [Array] arguments to the missing method
|
123
|
-
#----------------------------------------------------------------------------------------
|
124
|
-
|
125
|
-
def self.method_missing(symbol, *args)
|
126
|
-
name = R::Support.convert_symbol2r(symbol)
|
127
|
-
R::Language.build(name, *args)
|
128
|
-
end
|
129
|
-
#=end
|
130
|
-
|
131
|
-
#--------------------------------------------------------------------------------------
|
132
|
-
#
|
133
|
-
#--------------------------------------------------------------------------------------
|
134
|
-
|
135
|
-
def self.[](executable)
|
136
|
-
R::RubyCallback.build(executable)
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
=end
|
@@ -35,8 +35,9 @@ module R
|
|
35
35
|
#--------------------------------------------------------------------------------------
|
36
36
|
|
37
37
|
def [](index)
|
38
|
+
|
39
|
+
# dealing with double indexing function '[['
|
38
40
|
if (index.is_a? Array)
|
39
|
-
# R::Support.exec_function_name("`[[`", @r_interop, R.internal_eval(:c, *index))
|
40
41
|
R::Support.exec_function(R::Support.dbk_index, @r_interop,
|
41
42
|
R.internal_eval(:c, *index))
|
42
43
|
else
|
@@ -53,8 +54,16 @@ module R
|
|
53
54
|
#--------------------------------------------------------------------------------------
|
54
55
|
|
55
56
|
def []=(index, values)
|
56
|
-
|
57
|
+
|
58
|
+
# dealing with double indexing function '[['
|
59
|
+
if (index.is_a? Array)
|
60
|
+
setR_name("`[[<-`", *index, values)
|
61
|
+
else
|
62
|
+
setR_name("`[<-`", index, values)
|
63
|
+
end
|
64
|
+
|
57
65
|
self
|
66
|
+
|
58
67
|
end
|
59
68
|
|
60
69
|
#--------------------------------------------------------------------------------------
|
@@ -62,7 +71,7 @@ module R
|
|
62
71
|
#--------------------------------------------------------------------------------------
|
63
72
|
|
64
73
|
def size
|
65
|
-
length
|
74
|
+
length >> 0
|
66
75
|
end
|
67
76
|
|
68
77
|
end
|
data/lib/R_interface/rlist.rb
CHANGED
@@ -38,6 +38,31 @@ module R
|
|
38
38
|
R::Support.exec_function_name("`+`", @r_interop, other_object.r_interop)
|
39
39
|
end
|
40
40
|
|
41
|
+
#--------------------------------------------------------------------------------------
|
42
|
+
#
|
43
|
+
#--------------------------------------------------------------------------------------
|
44
|
+
|
45
|
+
def method_missing_assign(elmt_name, arg)
|
46
|
+
setR_name("`[[<-`", elmt_name, arg)
|
47
|
+
end
|
48
|
+
|
49
|
+
#--------------------------------------------------------------------------------------
|
50
|
+
# When indexing with '[' or '[[' an R object is returned. Sometimes we need to have
|
51
|
+
# access to an umboxed Ruby element, for instance, in an numeric array, we might want
|
52
|
+
# to receive the actual number that can be used in a Ruby method. In this case, we
|
53
|
+
# use the '<<' operator.
|
54
|
+
# @return the Ruby element at the given index in the vector
|
55
|
+
#--------------------------------------------------------------------------------------
|
56
|
+
|
57
|
+
def >>(index)
|
58
|
+
raise IndexError.new("index #{index} out of list bounds: 0...#{index - 1}") if
|
59
|
+
(index > (length - 1) >> 0)
|
60
|
+
raise ArgumentError.new("Indexed element is not a vector") if
|
61
|
+
!self[[index + 1]].is_a? R::Vector
|
62
|
+
return nil if (self[[index + 1]].is__null >> 0)
|
63
|
+
self[[index + 1]] >> 0
|
64
|
+
end
|
65
|
+
|
41
66
|
#--------------------------------------------------------------------------------------
|
42
67
|
# Each cannot return a Enumerator because R is single threaded. When this restriction
|
43
68
|
# is removed, make each return self.to_enum
|
@@ -46,8 +71,8 @@ module R
|
|
46
71
|
def each
|
47
72
|
|
48
73
|
# length is a R::Vector, in order to extract its size as a Ruby number we need to
|
49
|
-
# use the
|
50
|
-
(1..length
|
74
|
+
# use the >> operator
|
75
|
+
(1..length >> 0).each do |i|
|
51
76
|
yield self[[i]]
|
52
77
|
end
|
53
78
|
|
@@ -59,8 +84,8 @@ module R
|
|
59
84
|
|
60
85
|
def each_with_index
|
61
86
|
|
62
|
-
(1..length
|
63
|
-
yield self[i], i
|
87
|
+
(1..length >> 0).each do |i|
|
88
|
+
yield self[[i]], i
|
64
89
|
end
|
65
90
|
|
66
91
|
end
|