galaaz 0.4.2 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +25 -0
- data/Rakefile +8 -0
- data/bin/gknit +9 -5
- data/bin/gstudio +4 -2
- data/bin/gstudio.rb +32 -2
- data/blogs/dev/dev.html +219 -34
- data/blogs/dev/dev.md +26 -26
- data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
- data/blogs/dev/dev_files/figure-html/diverging_bar.png +0 -0
- data/blogs/dplyr/dplyr.rb +63 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +38 -26
- data/blogs/galaaz_ggplot/galaaz_ggplot.aux +16 -17
- data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +65 -31
- data/blogs/oh_my/not_so.rb +2342 -0
- data/blogs/oh_my/oh_my.Rmd +493 -0
- data/blogs/oh_my/oh_my.html +680 -0
- data/blogs/oh_my/oh_my.md +597 -0
- data/blogs/oh_my/old.Rmd +2100 -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/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/blogs/ruby_plot/ruby_plot.Rmd +147 -122
- data/blogs/ruby_plot/ruby_plot.Rmd_external_figs +662 -0
- data/blogs/ruby_plot/ruby_plot.html +49 -54
- data/blogs/ruby_plot/ruby_plot.md +147 -122
- data/blogs/ruby_plot/ruby_plot.pdf +0 -0
- data/blogs/ruby_plot/ruby_plot.tex +776 -157
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +57 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.svg +106 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.svg +110 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.svg +174 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.svg +236 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.svg +296 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.svg +236 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.svg +218 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.svg +128 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.svg +150 -0
- data/examples/islr/ch2.spec.rb +21 -18
- data/examples/islr/ch3_boston.rb +14 -5
- data/examples/islr/ch3_multiple_regression.rb +2 -3
- data/examples/islr/ch6.spec.rb +1 -1
- data/examples/islr/x_y_rnorm.jpg +0 -0
- data/lib/R_interface/r.rb +14 -10
- data/lib/R_interface/r_libs.R +9 -0
- data/lib/R_interface/r_methods.rb +77 -6
- data/lib/R_interface/{expression.rb → r_module_s.rb} +13 -14
- data/lib/R_interface/rbinary_operators.rb +58 -71
- data/lib/R_interface/rdata_frame.rb +2 -1
- data/lib/R_interface/rdevices.R +4 -0
- data/lib/R_interface/rdevices.rb +1 -1
- data/lib/R_interface/renvironment.rb +34 -1
- data/lib/R_interface/rexpression.rb +108 -2
- data/lib/R_interface/rindexed_object.rb +3 -1
- data/lib/R_interface/rlanguage.rb +18 -2
- data/lib/R_interface/rmatrix.rb +14 -0
- data/lib/R_interface/rmd_indexed_object.rb +5 -1
- data/lib/R_interface/robject.rb +61 -23
- data/lib/R_interface/rsupport.rb +111 -53
- data/lib/R_interface/rsymbol.rb +6 -5
- data/lib/R_interface/ruby_extensions.rb +130 -4
- data/lib/R_interface/runary_operators.rb +35 -3
- data/lib/R_interface/rvector.rb +1 -0
- data/lib/galaaz.rb +0 -2
- data/lib/gknit/knitr_engine.rb +58 -4
- data/lib/gknit/ruby_engine.rb +5 -6
- data/lib/util/exec_ruby.rb +55 -9
- data/specs/all.rb +13 -3
- data/specs/figures/dose_len.png +0 -0
- data/specs/r_dataframe.spec.rb +49 -26
- data/specs/r_environment.spec.rb +140 -0
- data/specs/r_eval.spec.rb +0 -15
- data/specs/r_formula.spec.rb +232 -0
- data/specs/r_function.spec.rb +7 -8
- data/specs/r_list.spec.rb +4 -0
- data/specs/r_list_apply.spec.rb +11 -11
- data/specs/r_matrix.spec.rb +3 -3
- data/specs/{r_plots.spec.rb~ → r_nse.spec.rb} +29 -6
- data/specs/r_vector_creation.spec.rb +6 -0
- data/specs/r_vector_object.spec.rb +2 -2
- data/specs/r_vector_operators.spec.rb +3 -3
- data/specs/r_vector_subsetting.spec.rb +4 -4
- data/specs/ruby_expression.spec.rb +324 -0
- data/specs/tmp.rb +12 -524
- data/sty/galaaz.sty +71 -0
- data/version.rb +1 -1
- metadata +31 -41
- data/bin/gknit2~ +0 -6
- data/bin/ogk~ +0 -4
- data/bin/prepareR.rb~ +0 -1
- data/blogs/dev/dev.Rmd~ +0 -104
- data/blogs/galaaz_ggplot/galaaz_ggplot.dvi +0 -0
- data/blogs/galaaz_ggplot/midwest_external_png~ +0 -1
- data/blogs/gknit/gknit.Rmd~ +0 -184
- data/blogs/gknit/gknit.Rnd~ +0 -17
- data/blogs/gknit/model.rb~ +0 -46
- data/blogs/ruby_plot/ruby_plot.Rmd~ +0 -215
- data/examples/islr/Figure.jpg +0 -0
- data/examples/misc/moneyball.rb~ +0 -16
- data/examples/misc/subsetting.rb~ +0 -372
- data/lib/R/eng_ruby.R~ +0 -63
- data/lib/R_interface/capture_plot.rb~ +0 -23
- data/lib/R_interface/r.rb~ +0 -121
- data/lib/R_interface/rdevices.rb~ +0 -27
- data/lib/gknit.rb~ +0 -26
- data/lib/gknit/knitr_engine.rb~ +0 -102
- data/lib/gknit/ruby_engine.rb~ +0 -72
- data/lib/util/inline_file.rb~ +0 -23
- data/r_requires/knitr.rb~ +0 -4
- data/specs/r_language.spec.rb +0 -157
data/r_requires/knitr.rb~
DELETED
data/specs/r_language.spec.rb
DELETED
@@ -1,157 +0,0 @@
|
|
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
|
-
|
26
|
-
describe R::Language do
|
27
|
-
|
28
|
-
#========================================================================================
|
29
|
-
context "Working with symbols" do
|
30
|
-
|
31
|
-
it "should convert a Ruby Symbol to an R Symbol with '+'" do
|
32
|
-
a = +:cyl
|
33
|
-
expect(a.is_a? R::RSymbol).to eq true
|
34
|
-
expect a.to_s == "cyl"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should assign to an R symbol and retrieve from it" do
|
38
|
-
R.cyl = 10
|
39
|
-
expect ~:cyl == 10
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should allow calling evaluate on the symbol" do
|
43
|
-
R.cyl = 10
|
44
|
-
expect R.eval(~:cyl) == 10
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
#========================================================================================
|
50
|
-
context "When creating Calls" do
|
51
|
-
|
52
|
-
it "binary operators should apply to symbols" do
|
53
|
-
# this behaviour is a bit different from R's. In R this would raise an error
|
54
|
-
# with cyl not found
|
55
|
-
expect (:cyl + 5).to_s == '.Primitive("+")(cyl, 5L)'
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should properly coerce to language" do
|
59
|
-
expect (5 + 5).to_s == '.Primitive("+")(5L, cyl)'
|
60
|
-
end
|
61
|
-
|
62
|
-
# Formula objects are special and are very similar to quoted expressions, but
|
63
|
-
# they are not really quoted since trying to call R.typeof(<formula>) will
|
64
|
-
# evaluate the formula. We add methods .typeof and .rclass in the Ruby class
|
65
|
-
it "formula have typeof and rclass" do
|
66
|
-
call = :cyl + 5
|
67
|
-
expect call.typeof == "language"
|
68
|
-
expect call.rclass == "call"
|
69
|
-
end
|
70
|
-
|
71
|
-
it "during calls creation, only symbols are unevaluated" do
|
72
|
-
# 5 * 10 evaluate to 50 in the call
|
73
|
-
expect(:cyl + 5 * 10).to_s == '.Primitive("+")(cyl, 50L)'
|
74
|
-
# define a variable x
|
75
|
-
x = 20
|
76
|
-
# x is not quoted in the expression
|
77
|
-
expect(:cyl + 5 * x).to_s == '.Primitive("+")(cyl, 100L)'
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
#========================================================================================
|
83
|
-
|
84
|
-
context "Executing R expressions" do
|
85
|
-
|
86
|
-
it "should eval an R expression in the context of a list" do
|
87
|
-
ct = R.list(a: 10, b: 20, c: 30)
|
88
|
-
exp = :a + :b * :c
|
89
|
-
expect R.eval(exp, ct) == 610
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should eval an R function in the context of a list" do
|
93
|
-
R.x = 5
|
94
|
-
expect R.eval(:x + 10) == 15
|
95
|
-
ct = R.list(x: 20)
|
96
|
-
expect R.eval(:x + 10, ct) == 30
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
#========================================================================================
|
103
|
-
context "When working with Formulas" do
|
104
|
-
# When working with formulas, Ruby symbols such be preceded by the '+' function.
|
105
|
-
# If you want to make a formula such as 'a ~ b' in R, then this should be written
|
106
|
-
# as '+:a =~ +:b'. When, in an binary operation, the Ruby symbol will be converted
|
107
|
-
# to an R symbol. The formula '+:a =~ +:b', can also be written as '+:a =~ :b'. Be
|
108
|
-
# careful, however, when using the Ruby symbol without the '+' since in a more complex
|
109
|
-
# formula, Ruby's precedence rules might not result in what is expected. As an example
|
110
|
-
# '+:a =~ :b * +:c' crashes with the error 'b' not found, since '*' has precedence over
|
111
|
-
# '=~' and this is equivalent to '+:a =~ (:b * +:c)' and there is no sense in
|
112
|
-
# multiplying a Ruby symbol. The recomendation is to always use the '+' function
|
113
|
-
# before the Ruby symbol.
|
114
|
-
|
115
|
-
it "should create a RSymbol from a Ruby Symbol using +" do
|
116
|
-
sym = +:sym
|
117
|
-
expect sym.to_s == "sym"
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should create a formula with '.' by using the ':all' keyword" do
|
121
|
-
# this formula is interpreted as 'supp ~ .'
|
122
|
-
formula = +:supp =~ :all
|
123
|
-
expect formula.rclass == "formula"
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should create a formula with '.' by using the ':all' keyword in the lhs" do
|
127
|
-
# this formula is interpreted as '. ~ supp'
|
128
|
-
formula = +:all =~ +:supp
|
129
|
-
expect formula.rclass == "formula"
|
130
|
-
end
|
131
|
-
|
132
|
-
=begin
|
133
|
-
|
134
|
-
it "should create a formula without the lhs" do
|
135
|
-
pending "formulas need to be reimplemented"
|
136
|
-
formula = ~(:cyl + :exp)
|
137
|
-
expect formula.to_s == '~.Primitive("+")(cyl, exp)'
|
138
|
-
expect formula.typeof == 'language'
|
139
|
-
expect formula.rclass == 'formula'
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should create formulas with the '=~' operator" do
|
143
|
-
formula = (:cyl =~ :exp)
|
144
|
-
expect(formula.to_s) == '.Primitive("~")(cyl, exp)'
|
145
|
-
expect formula.typeof == 'language'
|
146
|
-
expect formula.rclass == 'formula'
|
147
|
-
|
148
|
-
formula2 = (:cyl =~ :exp + :exp2 - :exp3)
|
149
|
-
expect formula2.to_s == 'cyl ~ .Primitive("-")(.Primitive("+")(exp, exp2), exp3)'
|
150
|
-
expect formula.typeof == 'language'
|
151
|
-
expect formula.rclass == 'formula'
|
152
|
-
end
|
153
|
-
=end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|