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
Binary file
|
@@ -0,0 +1,458 @@
|
|
1
|
+
\documentclass[]{article}
|
2
|
+
\usepackage{lmodern}
|
3
|
+
\usepackage{amssymb,amsmath}
|
4
|
+
\usepackage{ifxetex,ifluatex}
|
5
|
+
\usepackage{fixltx2e} % provides \textsubscript
|
6
|
+
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
|
7
|
+
\usepackage[T1]{fontenc}
|
8
|
+
\usepackage[utf8]{inputenc}
|
9
|
+
\else % if luatex or xelatex
|
10
|
+
\ifxetex
|
11
|
+
\usepackage{mathspec}
|
12
|
+
\else
|
13
|
+
\usepackage{fontspec}
|
14
|
+
\fi
|
15
|
+
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
|
16
|
+
\fi
|
17
|
+
% use upquote if available, for straight quotes in verbatim environments
|
18
|
+
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
|
19
|
+
% use microtype if available
|
20
|
+
\IfFileExists{microtype.sty}{%
|
21
|
+
\usepackage{microtype}
|
22
|
+
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
|
23
|
+
}{}
|
24
|
+
\usepackage[margin=1in]{geometry}
|
25
|
+
\usepackage{hyperref}
|
26
|
+
\hypersetup{unicode=true,
|
27
|
+
pdftitle={High Quality Scientific Plotting with Ruby in GraalVM},
|
28
|
+
pdfauthor={Rodrigo Botafogo},
|
29
|
+
pdfborder={0 0 0},
|
30
|
+
breaklinks=true}
|
31
|
+
\urlstyle{same} % don't use monospace font for urls
|
32
|
+
\usepackage{color}
|
33
|
+
\usepackage{fancyvrb}
|
34
|
+
\newcommand{\VerbBar}{|}
|
35
|
+
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
|
36
|
+
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
|
37
|
+
% Add ',fontsize=\small' for more characters per line
|
38
|
+
\usepackage{framed}
|
39
|
+
\definecolor{shadecolor}{RGB}{248,248,248}
|
40
|
+
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
|
41
|
+
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
|
42
|
+
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
|
43
|
+
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
44
|
+
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
45
|
+
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
46
|
+
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
|
47
|
+
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
48
|
+
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
|
49
|
+
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
50
|
+
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
51
|
+
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
52
|
+
\newcommand{\ImportTok}[1]{#1}
|
53
|
+
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
|
54
|
+
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
55
|
+
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
56
|
+
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
57
|
+
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
|
58
|
+
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
|
59
|
+
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
|
60
|
+
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
|
61
|
+
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
|
62
|
+
\newcommand{\BuiltInTok}[1]{#1}
|
63
|
+
\newcommand{\ExtensionTok}[1]{#1}
|
64
|
+
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
|
65
|
+
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
|
66
|
+
\newcommand{\RegionMarkerTok}[1]{#1}
|
67
|
+
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
68
|
+
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
69
|
+
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
|
70
|
+
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
|
71
|
+
\newcommand{\NormalTok}[1]{#1}
|
72
|
+
\usepackage{graphicx,grffile}
|
73
|
+
\makeatletter
|
74
|
+
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
|
75
|
+
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
|
76
|
+
\makeatother
|
77
|
+
% Scale images if necessary, so that they will not overflow the page
|
78
|
+
% margins by default, and it is still possible to overwrite the defaults
|
79
|
+
% using explicit options in \includegraphics[width, height, ...]{}
|
80
|
+
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
|
81
|
+
\IfFileExists{parskip.sty}{%
|
82
|
+
\usepackage{parskip}
|
83
|
+
}{% else
|
84
|
+
\setlength{\parindent}{0pt}
|
85
|
+
\setlength{\parskip}{6pt plus 2pt minus 1pt}
|
86
|
+
}
|
87
|
+
\setlength{\emergencystretch}{3em} % prevent overfull lines
|
88
|
+
\providecommand{\tightlist}{%
|
89
|
+
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
|
90
|
+
\setcounter{secnumdepth}{5}
|
91
|
+
% Redefines (sub)paragraphs to behave more like sections
|
92
|
+
\ifx\paragraph\undefined\else
|
93
|
+
\let\oldparagraph\paragraph
|
94
|
+
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
|
95
|
+
\fi
|
96
|
+
\ifx\subparagraph\undefined\else
|
97
|
+
\let\oldsubparagraph\subparagraph
|
98
|
+
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
|
99
|
+
\fi
|
100
|
+
|
101
|
+
%%% Use protect on footnotes to avoid problems with footnotes in titles
|
102
|
+
\let\rmarkdownfootnote\footnote%
|
103
|
+
\def\footnote{\protect\rmarkdownfootnote}
|
104
|
+
|
105
|
+
%%% Change title format to be more compact
|
106
|
+
\usepackage{titling}
|
107
|
+
|
108
|
+
% Create subtitle command for use in maketitle
|
109
|
+
\newcommand{\subtitle}[1]{
|
110
|
+
\posttitle{
|
111
|
+
\begin{center}\large#1\end{center}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
\setlength{\droptitle}{-2em}
|
116
|
+
|
117
|
+
\title{High Quality Scientific Plotting with Ruby in GraalVM}
|
118
|
+
\pretitle{\vspace{\droptitle}\centering\huge}
|
119
|
+
\posttitle{\par}
|
120
|
+
\subtitle{Also: Allowing R to use classes, modules, blocks, etc.}
|
121
|
+
\author{Rodrigo Botafogo}
|
122
|
+
\preauthor{\centering\large\emph}
|
123
|
+
\postauthor{\par}
|
124
|
+
\predate{\centering\large\emph}
|
125
|
+
\postdate{\par}
|
126
|
+
\date{19 October 2018}
|
127
|
+
|
128
|
+
% usar portugues do Brasil
|
129
|
+
% \usepackage[brazilian]{babel}
|
130
|
+
\usepackage[utf8]{inputenc}
|
131
|
+
|
132
|
+
\usepackage{geometry}
|
133
|
+
\geometry{a4paper, top=1in}
|
134
|
+
|
135
|
+
% necessários para uso com kableExtra
|
136
|
+
\usepackage{longtable}
|
137
|
+
\usepackage{multirow}
|
138
|
+
\usepackage[table]{xcolor}
|
139
|
+
\usepackage{wrapfig}
|
140
|
+
\usepackage{float}
|
141
|
+
\usepackage{colortbl}
|
142
|
+
\usepackage{pdflscape}
|
143
|
+
\usepackage{tabu}
|
144
|
+
\usepackage{threeparttable}
|
145
|
+
\usepackage[normalem]{ulem}
|
146
|
+
|
147
|
+
\usepackage{bbm}
|
148
|
+
\usepackage{booktabs}
|
149
|
+
\usepackage{expex}
|
150
|
+
|
151
|
+
\usepackage{graphicx}
|
152
|
+
\usepackage{fancyhdr}
|
153
|
+
\pagestyle{fancy}
|
154
|
+
\fancyhf{}
|
155
|
+
|
156
|
+
\usepackage{lipsum}
|
157
|
+
|
158
|
+
% disponibilizar o comando lastpage
|
159
|
+
\usepackage{lastpage}
|
160
|
+
|
161
|
+
% tamanho do font padrão 11pt
|
162
|
+
\usepackage[fontsize=10pt]{scrextend}
|
163
|
+
|
164
|
+
% comandos para formatar uma tabela
|
165
|
+
\usepackage{array}
|
166
|
+
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
167
|
+
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
168
|
+
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
169
|
+
|
170
|
+
% necessário para importar outros arquivos latex
|
171
|
+
\usepackage{import}
|
172
|
+
|
173
|
+
\newcommand{\RtoLatex}[2]{\newcommand{#1}{#2}}
|
174
|
+
%\newcommand{\atraso}[1]{\color{red} \textbf {Tempo desde a Assinatura do Contrato: #1 dias}}
|
175
|
+
|
176
|
+
\begin{document}
|
177
|
+
\maketitle
|
178
|
+
|
179
|
+
\section{Introduction}\label{introduction}
|
180
|
+
|
181
|
+
Ruby is a dynamic, interpreted, reflective, object-oriented,
|
182
|
+
general-purpose programming language. It was designed and developed in
|
183
|
+
the mid-1990s by Yukihiro ``Matz'' Matsumoto in Japan. It reached high
|
184
|
+
popularity with the development of Ruby on Rails (RoR) by David
|
185
|
+
Heinemeier Hansson. RoR is a web application framework which was first
|
186
|
+
release circa 2005 and makes extensive use of Ruby's metaprogramming
|
187
|
+
features. With the advend of RoR, Ruby became extremely popular and it
|
188
|
+
peeked in popularity around 2008 according to the Tiobe index
|
189
|
+
(\url{https://www.tiobe.com/tiobe-index/ruby/}). From 2008 to 2015, it's
|
190
|
+
popularity declined consistently and then started picking up again
|
191
|
+
during the next 3 years. At the time of this writing (November 2018),
|
192
|
+
Ruby is ranked 16th in the Tiobe index.
|
193
|
+
|
194
|
+
Python, considered a similar language to Ruby with similar features
|
195
|
+
ranks 4th in the index. The first three positions are taken by Java, C
|
196
|
+
and C++. One criticism often heard about Ruby, is that it is useful only
|
197
|
+
for web applications while Python, with similar features has more
|
198
|
+
diverse libraries, being useful for web applications with the Django
|
199
|
+
framework, but also for scientific applications such as statistics, data
|
200
|
+
analysis, big data, biology, etc. This criticism is by no way wrong.
|
201
|
+
Although Ruby can do much more than just web applications:
|
202
|
+
\url{https://github.com/markets/awesome-ruby}, for scientific computing,
|
203
|
+
Ruby lags way behind Python and R, the two most prestigous languages in
|
204
|
+
the field, with R being prefered by statisticians while Python is
|
205
|
+
prefered by everyone else, because of it's gentle learning curve and
|
206
|
+
more ``natural'' programming paradigm.
|
207
|
+
|
208
|
+
Until recently, there was no real perspective for Ruby to bridge this
|
209
|
+
gap and have even the most basic scientific computing infrastructure.
|
210
|
+
Comes GraalVM into the picture:
|
211
|
+
|
212
|
+
\begin{verbatim}
|
213
|
+
GraalVM is a universal virtual machine for running applications written in JavaScript,
|
214
|
+
Python 3, Ruby, R, JVM-based languages like Java, Scala, Kotlin, and LLVM-based languages
|
215
|
+
such as C and C++.
|
216
|
+
|
217
|
+
GraalVM removes the isolation between programming languages and enables interoperability in a
|
218
|
+
shared runtime. It can run either standalone or in the context of OpenJDK, Node.js,
|
219
|
+
Oracle Database, or MySQL.
|
220
|
+
|
221
|
+
GraalVM allows you to write polyglot applications with a seamless way to pass values from one
|
222
|
+
language to another. With GraalVM there is no copying or marshaling necessary as it is with
|
223
|
+
other polyglot systems. This lets you achieve high performance when language boundaries are
|
224
|
+
crossed. Most of the time there is no additional cost for crossing a language boundary at all.
|
225
|
+
|
226
|
+
Often developers have to make uncomfortable compromises that require them to rewrite
|
227
|
+
their software in other languages. For example:
|
228
|
+
|
229
|
+
* “That library is not available in my language. I need to rewrite it.”
|
230
|
+
* “That language would be the perfect fit for my problem, but we cannot run it
|
231
|
+
in our environment.”
|
232
|
+
* “That problem is already solved in my language, but the language is too slow.”
|
233
|
+
|
234
|
+
With GraalVM we aim to allow developers to freely choose the right language for the task at
|
235
|
+
hand without making compromises.
|
236
|
+
\end{verbatim}
|
237
|
+
|
238
|
+
As stated above, GraalVM is a \emph{universal} virtual machine that
|
239
|
+
allows Ruby and R (and other languages) to run on the same environment.
|
240
|
+
GraalVM allows polyglot applications to \emph{seamlessly} interact with
|
241
|
+
one another and pass values from one language to the other. Based on
|
242
|
+
GraalVM, the Galaaz project was started. Galaaz indends to tightly
|
243
|
+
couple Ruby and R and allow those languages to \emph{seamlessly}
|
244
|
+
interact in a way that the user will be unaware of such interaction.
|
245
|
+
|
246
|
+
Library wrapping is an usual way of bringing features from one library
|
247
|
+
into another language. For instance, whenever Python needs to perform
|
248
|
+
operations efficiently, C libraries are wrapped in Python. For the
|
249
|
+
Python developer, the existence of such C library is of no concern. The
|
250
|
+
problem with library wrapping is that for any new library of interest,
|
251
|
+
there is the need to hand craft a new wrapper. With Galaaz, the same
|
252
|
+
concept of wrapping was done, but instead of wrapping a single C or R
|
253
|
+
library, Galaaz wraps the whole of the R language. Doing so, all
|
254
|
+
thousands of R libraries are immediately available to Ruby developers
|
255
|
+
and any new library developed in R will also become available without
|
256
|
+
requiring a new wrapping effort.
|
257
|
+
|
258
|
+
In this article, the graphing ggplot2 library from R will be accessed by
|
259
|
+
Ruby transparently, bringing to Ruby the power of high quality
|
260
|
+
scientific plotting. It might seem, from the exposed above, that Galaaz
|
261
|
+
mainly benefits Ruby developers and might be of no consequence to the R
|
262
|
+
developer. This article will however show that migrating from R to Ruby
|
263
|
+
with Galaaz is a matter of small syntactic changes. Furthermore, R lacks
|
264
|
+
some fundamental constructs for code reuse and large system
|
265
|
+
construction. Using Galaaz, the R developer can easily migrate to a
|
266
|
+
powerful OO language, at virtually no cost and then, as needs requires,
|
267
|
+
she can add them to her toolbox.
|
268
|
+
|
269
|
+
In this article we will explore the R ToothGrowth dataset. In doing so,
|
270
|
+
we will create some plots. Furthermore we will create a ``Corporate
|
271
|
+
Template'' for our plots ensuring that any plot of the same type will
|
272
|
+
have a consistent visualisation.
|
273
|
+
|
274
|
+
\section{gKnit}\label{gknit}
|
275
|
+
|
276
|
+
This document was written using rmarkdown and the corresponding HTML was
|
277
|
+
generated by the gKnit application. gKnit is a wrapper around the
|
278
|
+
powerful `knitr' application which converts rmarkdown text to many
|
279
|
+
different output formats such as HTML, Latex, docx, etc. The gKnit tool
|
280
|
+
is still under active development and will soon be released.
|
281
|
+
|
282
|
+
In rmarkdown, text and code can be part of the same document, and code
|
283
|
+
blocks are marked with a special markup. Interested readers can easily
|
284
|
+
google `knitr' and `rmarkdown'. in gKnit, each Ruby block is evaluated
|
285
|
+
independently and `eval' in Ruby creates a new scope, so, in order for a
|
286
|
+
variable defined in a block to be accessible in another block, it has to
|
287
|
+
be a global variable, preceded by the `\$' sign.
|
288
|
+
|
289
|
+
\section{Exploring the Dataset}\label{exploring-the-dataset}
|
290
|
+
|
291
|
+
Let start by exploring our selected dataset. In this dataset the
|
292
|
+
response is the length of odontoblasts (cells responsible for tooth
|
293
|
+
growth) in 60 guinea pigs. Each animal received one of three dose levels
|
294
|
+
of vitamin C (0.5, 1, and 2 mg/day) by one of two delivery methods,
|
295
|
+
orange juice or ascorbic acid (a form of vitamin C and coded as VC).
|
296
|
+
|
297
|
+
In Galaaz, in order to have access to an R variable pointed by an R
|
298
|
+
symbol we use the corresponding Ruby symbol preceeded by the tilda
|
299
|
+
(`\textasciitilde{}') function.
|
300
|
+
|
301
|
+
\begin{Shaded}
|
302
|
+
\begin{Highlighting}[]
|
303
|
+
\CommentTok{# Read the R ToothGrowth variable and assign it to the}
|
304
|
+
\CommentTok{# Ruby tooth_growth variable}
|
305
|
+
\DataTypeTok{$tooth_growth}\NormalTok{ = ~}\StringTok{:ToothGrowth}
|
306
|
+
\CommentTok{# convert the dose to a factor}
|
307
|
+
\DataTypeTok{$tooth_growth}\NormalTok{.dose = }\DataTypeTok{$tooth_growth}\NormalTok{.dose.as__factor}
|
308
|
+
|
309
|
+
\CommentTok{# print the first few elements of the dataset}
|
310
|
+
\NormalTok{puts }\DataTypeTok{$tooth_growth}\NormalTok{.head}
|
311
|
+
\end{Highlighting}
|
312
|
+
\end{Shaded}
|
313
|
+
|
314
|
+
\begin{verbatim}
|
315
|
+
## len supp dose
|
316
|
+
## 1 4.2 VC 0.5
|
317
|
+
## 2 11.5 VC 0.5
|
318
|
+
## 3 7.3 VC 0.5
|
319
|
+
## 4 5.8 VC 0.5
|
320
|
+
## 5 6.4 VC 0.5
|
321
|
+
## 6 10.0 VC 0.5
|
322
|
+
\end{verbatim}
|
323
|
+
|
324
|
+
Great! We've managed to read the ToothGrowth dataset and take a look at
|
325
|
+
its elements. Observe that we have three columns in this dataset: `len',
|
326
|
+
`supp' and `dose'. Accessing a column, for example the `len' column, is
|
327
|
+
done by doing `\$tooth\_growth.len'.
|
328
|
+
|
329
|
+
Let's explore some more details of this dataset. In particular, let's
|
330
|
+
look at its dimensions, structure and summary statistics.
|
331
|
+
|
332
|
+
\begin{Shaded}
|
333
|
+
\begin{Highlighting}[]
|
334
|
+
\NormalTok{puts }\DataTypeTok{$tooth_growth}\NormalTok{.dim}
|
335
|
+
\CommentTok{# chdck why NULL}
|
336
|
+
\NormalTok{puts R.str(}\StringTok{:ToothGrowth}\NormalTok{)}
|
337
|
+
\NormalTok{puts }\DataTypeTok{$tooth_growth}\NormalTok{.summary}
|
338
|
+
\end{Highlighting}
|
339
|
+
\end{Shaded}
|
340
|
+
|
341
|
+
\begin{verbatim}
|
342
|
+
## [1] 60 3
|
343
|
+
## NULL
|
344
|
+
## len supp dose
|
345
|
+
## Min. : 4.20 OJ:30 0.5:20
|
346
|
+
## 1st Qu.:13.07 VC:30 1 :20
|
347
|
+
## Median :19.25 2 :20
|
348
|
+
## Mean :18.81
|
349
|
+
## 3rd Qu.:25.27
|
350
|
+
## Max. :33.90
|
351
|
+
\end{verbatim}
|
352
|
+
|
353
|
+
Let's now create our first plot with the given data by accessing ggplot2
|
354
|
+
from Ruby. For Rubyist that have never seen or used ggplot2, here is the
|
355
|
+
description found on ggplot home page:
|
356
|
+
|
357
|
+
\begin{verbatim}
|
358
|
+
"ggplot2 is a system for declaratively creating graphics, based on _The Grammar of Graphics_.
|
359
|
+
You provide the data, tell ggplot2 how to map variables to aesthetics, what graphical
|
360
|
+
primitives to use, and it takes care of the details."
|
361
|
+
\end{verbatim}
|
362
|
+
|
363
|
+
This description might be a bit cryptic and it is best to see it at work
|
364
|
+
to understand it. Basically, in the \emph{grammar of graphics} each
|
365
|
+
component of the plot such as the grid, the axis, the data, title,
|
366
|
+
subtitle, etc. is added to the plot in layers to form the final
|
367
|
+
graphics.
|
368
|
+
|
369
|
+
In this plot bellow, the `dose' is plotted on the `x' axis and the tooth
|
370
|
+
length on the `y' axis. Note the specification in the the `aes' method:
|
371
|
+
`E.aes(x: :dose, y: :len)', where `:dose' is the `dose' column of the
|
372
|
+
dataset and `:len' the `len' column. The `aes' method is the
|
373
|
+
\emph{aesthetics} for this plot. Then, to this layer, the
|
374
|
+
`geom\_boxplot' is added and the whole plot is printed.
|
375
|
+
|
376
|
+
Note also that we have a call to `R.png' before plotting and
|
377
|
+
'R.dev\_\_off' after the print statement. `R.png' opens a `png' device
|
378
|
+
for writing the plot. When 'R.dev\_\_off' is called, the device is
|
379
|
+
closed and a `png' file is created. If no name is given to the `png'
|
380
|
+
function, a file named `Rplot' is generated, where is the number of the
|
381
|
+
plot. So, this first plot is called `Rplot001.png'. We can then include
|
382
|
+
the generated `png' file in this document, by adding an rmarkdown
|
383
|
+
directive.
|
384
|
+
|
385
|
+
\begin{Shaded}
|
386
|
+
\begin{Highlighting}[]
|
387
|
+
\NormalTok{require }\StringTok{'ggplot'}
|
388
|
+
|
389
|
+
\NormalTok{R.png}
|
390
|
+
|
391
|
+
\NormalTok{e = }\DataTypeTok{$tooth_growth}\NormalTok{.ggplot(E.aes(}\StringTok{x: :dose}\NormalTok{, }\StringTok{y: :len}\NormalTok{))}
|
392
|
+
\NormalTok{print e + R.geom_boxplot}
|
393
|
+
|
394
|
+
\NormalTok{R.dev__off}
|
395
|
+
\end{Highlighting}
|
396
|
+
\end{Shaded}
|
397
|
+
|
398
|
+
\begin{figure}
|
399
|
+
\centering
|
400
|
+
\includegraphics{Rplot001.png}
|
401
|
+
\caption{ToothGrowth}
|
402
|
+
\end{figure}
|
403
|
+
|
404
|
+
We've just managed to generate our first plot in Ruby with only two
|
405
|
+
lines of code. This plot, however, if far from being pleasing to the
|
406
|
+
eye.
|
407
|
+
|
408
|
+
\section{Conclusion}\label{conclusion}
|
409
|
+
|
410
|
+
\section{Installing Galaaz}\label{installing-galaaz}
|
411
|
+
|
412
|
+
\subsection{Prerequisites}\label{prerequisites}
|
413
|
+
|
414
|
+
\begin{itemize}
|
415
|
+
\tightlist
|
416
|
+
\item
|
417
|
+
GraalVM (\textgreater{}= rc8)
|
418
|
+
\item
|
419
|
+
TruffleRuby
|
420
|
+
\item
|
421
|
+
FastR
|
422
|
+
\end{itemize}
|
423
|
+
|
424
|
+
The following R packages will be automatically installed when necessary,
|
425
|
+
but could be installed prior to using gKnit if desired:
|
426
|
+
|
427
|
+
\begin{itemize}
|
428
|
+
\tightlist
|
429
|
+
\item
|
430
|
+
ggplot2
|
431
|
+
\item
|
432
|
+
gridExtra
|
433
|
+
\item
|
434
|
+
knitr
|
435
|
+
\end{itemize}
|
436
|
+
|
437
|
+
Installation of R packages requires a development environment and can be
|
438
|
+
time consuming. In Linux, the gnu compiler and tools should be enough. I
|
439
|
+
am not sure what is needed on the Mac.
|
440
|
+
|
441
|
+
\subsection{Preparation}\label{preparation}
|
442
|
+
|
443
|
+
\begin{itemize}
|
444
|
+
\tightlist
|
445
|
+
\item
|
446
|
+
gem install galaaz
|
447
|
+
\end{itemize}
|
448
|
+
|
449
|
+
\subsection{Usage}\label{usage}
|
450
|
+
|
451
|
+
\begin{itemize}
|
452
|
+
\tightlist
|
453
|
+
\item
|
454
|
+
gknit
|
455
|
+
\end{itemize}
|
456
|
+
|
457
|
+
|
458
|
+
\end{document}
|