galaaz 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +29 -0
- data/bin/gknit +208 -10
- data/bin/gknit2 +14 -0
- data/bin/gknit2~ +6 -0
- data/bin/prepareR.rb +3 -0
- data/bin/prepareR.rb~ +1 -0
- data/bin/tmp.py +51 -0
- data/blogs/dev/dev.Rmd +70 -0
- data/blogs/dev/dev.Rmd~ +104 -0
- data/blogs/dev/dev.html +209 -0
- data/blogs/dev/dev.md +72 -0
- data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
- data/blogs/dev/model.rb +41 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +55 -27
- data/blogs/galaaz_ggplot/galaaz_ggplot.aux +44 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.dvi +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.html +17 -4
- data/blogs/galaaz_ggplot/galaaz_ggplot.out +10 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +630 -0
- data/blogs/galaaz_ggplot/midwest.Rmd +1 -1
- data/blogs/galaaz_ggplot/midwest_external_png +13 -0
- data/blogs/galaaz_ggplot/midwest_external_png~ +1 -0
- data/blogs/gknit/gknit.Rmd +500 -0
- data/blogs/gknit/gknit.Rmd~ +184 -0
- data/blogs/gknit/gknit.Rnd~ +17 -0
- data/blogs/gknit/gknit.html +528 -0
- data/blogs/gknit/gknit.md +628 -0
- data/blogs/gknit/gknit.pdf +0 -0
- data/blogs/gknit/gknit.tex +745 -0
- 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/gknit/model.rb +41 -0
- data/blogs/gknit/model.rb~ +46 -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/blogs/ruby_plot/ruby_plot.Rmd +680 -0
- data/blogs/ruby_plot/ruby_plot.Rmd~ +215 -0
- data/blogs/ruby_plot/ruby_plot.html +563 -0
- data/blogs/ruby_plot/ruby_plot.md +731 -0
- data/blogs/ruby_plot/ruby_plot.pdf +0 -0
- data/blogs/ruby_plot/ruby_plot.tex +458 -0
- data/examples/sthda_ggplot/all.rb +0 -6
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_hex.rb +1 -1
- data/examples/sthda_ggplot/two_variables_cont_cont/misc.rb +1 -1
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_bar.rb +2 -2
- data/examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb +0 -1
- data/lib/R/eng_ruby.R +62 -0
- data/lib/R/eng_ruby.R~ +63 -0
- data/lib/R_interface/capture_plot.rb~ +23 -0
- data/lib/{R → R_interface}/expression.rb +0 -0
- data/lib/{R → R_interface}/r.rb +10 -1
- data/lib/{R → R_interface}/r.rb~ +0 -0
- data/lib/{R → R_interface}/r_methods.rb +21 -5
- data/lib/{R → R_interface}/rbinary_operators.rb +6 -1
- data/lib/R_interface/rclosure.rb +38 -0
- data/lib/{R → R_interface}/rdata_frame.rb +0 -0
- data/lib/R_interface/rdevices.R +31 -0
- data/lib/R_interface/rdevices.rb +225 -0
- data/lib/{R/rclosure.rb → R_interface/rdevices.rb~} +3 -10
- data/lib/{R → R_interface}/renvironment.rb +0 -0
- data/lib/{R → R_interface}/rexpression.rb +0 -0
- data/lib/{R → R_interface}/rindexed_object.rb +0 -0
- data/lib/{R → R_interface}/rlanguage.rb +0 -0
- data/lib/{R → R_interface}/rlist.rb +0 -0
- data/lib/{R → R_interface}/rmatrix.rb +0 -0
- data/lib/{R → R_interface}/rmd_indexed_object.rb +0 -0
- data/lib/{R → R_interface}/robject.rb +5 -0
- data/lib/{R → R_interface}/rpkg.rb +0 -0
- data/lib/{R → R_interface}/rsupport.rb +49 -13
- data/lib/{R → R_interface}/rsupport_scope.rb +0 -0
- data/lib/{R → R_interface}/rsymbol.rb +1 -0
- data/lib/{R → R_interface}/ruby_callback.rb +0 -0
- data/lib/{R → R_interface}/ruby_extensions.rb +2 -1
- data/lib/{R → R_interface}/runary_operators.rb +0 -0
- data/lib/{R → R_interface}/rvector.rb +0 -0
- data/lib/galaaz.rb +4 -2
- data/lib/gknit.rb +27 -0
- data/lib/gknit.rb~ +26 -0
- data/lib/gknit/knitr_engine.rb +120 -0
- data/lib/gknit/knitr_engine.rb~ +102 -0
- data/lib/gknit/ruby_engine.rb +70 -0
- data/lib/gknit/ruby_engine.rb~ +72 -0
- data/lib/util/exec_ruby.rb +8 -7
- data/lib/util/inline_file.rb +70 -0
- data/lib/util/inline_file.rb~ +23 -0
- data/r_requires/ggplot.rb +1 -8
- data/r_requires/knitr.rb +27 -0
- data/r_requires/knitr.rb~ +4 -0
- data/specs/r_language.spec.rb +22 -0
- data/specs/r_plots.spec.rb +72 -0
- data/specs/r_plots.spec.rb~ +37 -0
- data/specs/tmp.rb +255 -1
- data/version.rb +1 -1
- metadata +89 -39
@@ -0,0 +1,70 @@
|
|
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
|
+
# Ruby engine for processing Ruby chunks
|
25
|
+
eng_ruby = Proc.new do |options|
|
26
|
+
|
27
|
+
begin
|
28
|
+
# read the chunk code
|
29
|
+
code = R.paste(options.code, collapse: "\n") << 0
|
30
|
+
|
31
|
+
# process the chunk options
|
32
|
+
KnitrEngine.process_options(options)
|
33
|
+
|
34
|
+
tmp_fig = R.tempfile()
|
35
|
+
|
36
|
+
# opens a device for the current chunk for plot recording. Knitr provides
|
37
|
+
# method chunck_device for that, but it is a non-exported method. Galaaz
|
38
|
+
# does not yet provide a way to accessing non-exported methods, so, the ck_dv
|
39
|
+
# local method was developed that just calls chunk_device.
|
40
|
+
if (R._ck_dv(options.fig__width[1], options.fig__height[1], options.dev,
|
41
|
+
options.dev__args, options.dpi, options, tmp_fig, record: true) << 0)
|
42
|
+
|
43
|
+
# chunk requires library 'showtext'. Install and loads if not present
|
44
|
+
# FIXME: library showtext is giving error when trying to execute showtext beginning
|
45
|
+
if (!options[['fig.showtext']].is__null << 0) &&
|
46
|
+
options[['fig.showtext']] << 0
|
47
|
+
R.install_and_loads('showtext')
|
48
|
+
R.showtext
|
49
|
+
end
|
50
|
+
|
51
|
+
dv = R.dev__cur
|
52
|
+
end
|
53
|
+
|
54
|
+
# executes the code
|
55
|
+
res = GalaazUtil.exec_ruby(code)
|
56
|
+
|
57
|
+
# formats and outputs the code and results
|
58
|
+
R.engine_output(options, options.code, res)
|
59
|
+
|
60
|
+
ensure
|
61
|
+
R.dev__off(dv)
|
62
|
+
# tmp_fig.unlink
|
63
|
+
# if (keep.pars) opts_knit$set(global.pars = par(no.readonly = TRUE))
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
ruby_engine = KnitrEngine.new
|
69
|
+
ruby_engine.add(ruby: eng_ruby)
|
70
|
+
|
@@ -0,0 +1,72 @@
|
|
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
|
+
# Ruby engine for processing Ruby chunks
|
25
|
+
eng_ruby = Proc.new do |options|
|
26
|
+
|
27
|
+
begin
|
28
|
+
# read the chunk code
|
29
|
+
code = R.paste(options.code, collapse: "\n") << 0
|
30
|
+
|
31
|
+
# process the chunk options
|
32
|
+
KnitrEngine.process_options(options)
|
33
|
+
|
34
|
+
# opens a device for the current chunk for plot recording. Knitr provides
|
35
|
+
# method chunck_device for that, but it is a non-exported method. Galaaz
|
36
|
+
# does not yet provide a way to accessing non-exported methods, so, the ck_dv
|
37
|
+
# local method was developed that just calls chunk_device.
|
38
|
+
if (R._ck_dv(options.fig__width[1], options.fig__height[1], options.dev,
|
39
|
+
options.dev__args, options.dpi, options, record: true) << 0)
|
40
|
+
|
41
|
+
puts "===================================="
|
42
|
+
puts "fig.showtext is element?"
|
43
|
+
puts R.is__element('fig.showtext', options)
|
44
|
+
puts options['fig.showtext']
|
45
|
+
puts "===================================="
|
46
|
+
|
47
|
+
if (R.is__element('fig.showtext', options) << 0)
|
48
|
+
puts "==============================="
|
49
|
+
puts options.fig__showtext
|
50
|
+
puts options.fig__showtext << 0
|
51
|
+
end
|
52
|
+
|
53
|
+
R.showtext if (R.is__element('fig.showtext', options) << 0) &&
|
54
|
+
(options.fig__showtext << 0) == true
|
55
|
+
dv = R.dev__cur
|
56
|
+
end
|
57
|
+
|
58
|
+
# executes the code
|
59
|
+
res = GalaazUtil.exec_ruby(code)
|
60
|
+
|
61
|
+
# formats and outputs the code and results
|
62
|
+
R.engine_output(options, options.code, res)
|
63
|
+
|
64
|
+
ensure
|
65
|
+
R.dev__off(dv)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
ruby_engine = KnitrEngine.new
|
71
|
+
ruby_engine.add(ruby: eng_ruby)
|
72
|
+
|
data/lib/util/exec_ruby.rb
CHANGED
@@ -23,22 +23,23 @@
|
|
23
23
|
|
24
24
|
require 'stringio'
|
25
25
|
|
26
|
+
class RubyChunk
|
27
|
+
|
28
|
+
end
|
29
|
+
|
26
30
|
module GalaazUtil
|
27
31
|
|
28
32
|
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
33
|
|
34
|
+
# Set up standard output as a StringIO object.
|
35
|
+
$stdout = StringIO.new
|
36
|
+
RubyChunk.instance_eval(code)
|
35
37
|
out = $stdout.string
|
36
|
-
|
37
38
|
# return $stdout to standard output
|
38
39
|
$stdout = STDOUT
|
39
|
-
|
40
40
|
# return everything that was outputed
|
41
41
|
out
|
42
|
+
|
42
43
|
end
|
43
44
|
|
44
45
|
end
|
@@ -0,0 +1,70 @@
|
|
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 GalaazUtil
|
25
|
+
|
26
|
+
#========================================================================================
|
27
|
+
# Opens the given filename for reading and returns the file content so that it can be
|
28
|
+
# printed as a code chunk in rmarkdown
|
29
|
+
# @param filename [String] the name of the file to be found. If the file has no
|
30
|
+
# extension then '.rb' is assumed
|
31
|
+
# @param relative [String] containing either 'require_relative ' or 'require '. In the
|
32
|
+
# first case looks on the current directory, on the latter, searches the $LOAD_PATH
|
33
|
+
# @param pwd [String] Directory to look at when 'require_relative ', by default, its
|
34
|
+
# the pwd directory
|
35
|
+
#========================================================================================
|
36
|
+
|
37
|
+
def self.inline_file(filename, relative, pwd = Dir.pwd)
|
38
|
+
|
39
|
+
filename << ".rb" if File.extname(filename) == ""
|
40
|
+
file = "#{pwd}/#{filename}"
|
41
|
+
|
42
|
+
if (relative == 'require ')
|
43
|
+
$LOAD_PATH.each do |path|
|
44
|
+
begin
|
45
|
+
files = Dir.entries(path)
|
46
|
+
rescue Errno::ENOENT
|
47
|
+
next
|
48
|
+
end
|
49
|
+
|
50
|
+
if files != nil && files.include?("bigdecimal.rb")
|
51
|
+
file = "#{path}/#{filename}"
|
52
|
+
break
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if File.exist?(file)
|
58
|
+
code = ""
|
59
|
+
File.open(file, "r") do |fileObj|
|
60
|
+
while (line = fileObj.gets)
|
61
|
+
code << line
|
62
|
+
end
|
63
|
+
end
|
64
|
+
code
|
65
|
+
else
|
66
|
+
raise Errno::ENOENT, "file #{filename} not found"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|
+
|
data/r_requires/ggplot.rb
CHANGED
@@ -21,11 +21,4 @@
|
|
21
21
|
# OR MODIFICATIONS.
|
22
22
|
##########################################################################################
|
23
23
|
|
24
|
-
|
25
|
-
R.install_rlibs('ggplot2', 'grid', 'gridExtra', 'ggplotify')
|
26
|
-
|
27
|
-
# Load plotting libraries
|
28
|
-
R.library('ggplot2')
|
29
|
-
R.library('grid')
|
30
|
-
R.library('gridExtra')
|
31
|
-
R.library('ggplotify')
|
24
|
+
R.install_and_loads('ggplot2', 'grid', 'gridExtra')
|
data/r_requires/knitr.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 knitr, required package that provides needed functions
|
25
|
+
# to capture plots and generating images in diverse formats such
|
26
|
+
# as 'png', 'pdf', etc.
|
27
|
+
R.install_and_loads('knitr')
|
data/specs/r_language.spec.rb
CHANGED
@@ -101,11 +101,33 @@ describe R::Language do
|
|
101
101
|
|
102
102
|
#========================================================================================
|
103
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.
|
104
114
|
|
105
115
|
it "should create a RSymbol from a Ruby Symbol using +" do
|
106
116
|
sym = +:sym
|
107
117
|
expect sym.to_s == "sym"
|
108
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
|
109
131
|
|
110
132
|
=begin
|
111
133
|
|
@@ -0,0 +1,72 @@
|
|
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::Plots do
|
27
|
+
|
28
|
+
#----------------------------------------------------------------------------------------
|
29
|
+
context "Create a Plot" do
|
30
|
+
|
31
|
+
it "should create a bar plot" do
|
32
|
+
dev = R::Device.new('png', width: 5, height: 7, dpi: 300, record: true)
|
33
|
+
|
34
|
+
# opens de device
|
35
|
+
dev.open
|
36
|
+
# generate the bar plot
|
37
|
+
b = R.ggplot(:mpg, E.aes(:fl))
|
38
|
+
# prints the plot
|
39
|
+
print b + R.geom_bar
|
40
|
+
|
41
|
+
snap = dev.plot_snapshot
|
42
|
+
dev.save_plot(snap, 'snapshot', 'png', 5, 7, 'png', 300)
|
43
|
+
|
44
|
+
R.grid__newpage(recording: true)
|
45
|
+
|
46
|
+
# print a second bar chart
|
47
|
+
print b + R.geom_bar(fill: "steelblue", color: "steelblue") +
|
48
|
+
R.theme_minimal
|
49
|
+
|
50
|
+
# closes the device
|
51
|
+
dev.close
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should create a bar plot passing a block to the device" do
|
55
|
+
# creates the device and pass the plot spec in a block. No need to
|
56
|
+
# worry about opening and closing the device
|
57
|
+
dev = R::Device.new('svg', width: 5, height: 7, dpi: 300, record: true) {
|
58
|
+
b = R.ggplot(:mpg, E.aes(:fl))
|
59
|
+
print b + R.geom_bar
|
60
|
+
|
61
|
+
R.grid__newpage(recording: true)
|
62
|
+
|
63
|
+
# print a second bar chart
|
64
|
+
print b + R.geom_bar(fill: "steelblue", color: "steelblue") +
|
65
|
+
R.theme_minimal
|
66
|
+
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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::Plots do
|
27
|
+
|
28
|
+
#----------------------------------------------------------------------------------------
|
29
|
+
context "Create a Plot" do
|
30
|
+
|
31
|
+
it "should create a plot with ggplot" do
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|