galaaz 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +3575 -118
  3. data/Rakefile +21 -4
  4. data/bin/gknit +152 -6
  5. data/bin/gknit-draft +105 -0
  6. data/bin/gknit-draft.rb +28 -0
  7. data/bin/gknit_Rscript +127 -0
  8. data/bin/grun +27 -1
  9. data/bin/gstudio +47 -4
  10. data/bin/{gstudio.rb → gstudio_irb.rb} +0 -0
  11. data/bin/gstudio_pry.rb +7 -0
  12. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +3 -12
  13. data/blogs/galaaz_ggplot/galaaz_ggplot.html +77 -222
  14. data/blogs/galaaz_ggplot/galaaz_ggplot.md +4 -31
  15. data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
  16. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
  17. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
  18. data/blogs/galaaz_ggplot/midwest.Rmd +1 -9
  19. data/blogs/gknit/gknit.Rmd +232 -123
  20. data/blogs/{dev/dev.html → gknit/gknit.html} +1897 -33
  21. data/blogs/gknit/gknit.pdf +0 -0
  22. data/blogs/gknit/lst.rds +0 -0
  23. data/blogs/gknit/stats.bib +27 -0
  24. data/blogs/manual/lst.rds +0 -0
  25. data/blogs/manual/manual.Rmd +1893 -47
  26. data/blogs/manual/manual.html +3153 -347
  27. data/blogs/manual/manual.md +3575 -118
  28. data/blogs/manual/manual.pdf +0 -0
  29. data/blogs/manual/manual.tex +4026 -0
  30. data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
  31. data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
  32. data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
  33. data/blogs/manual/manual_files/figure-latex/diverging_bar.pdf +0 -0
  34. data/blogs/{dev → manual}/model.rb +0 -0
  35. data/blogs/nse_dplyr/nse_dplyr.Rmd +849 -0
  36. data/blogs/nse_dplyr/nse_dplyr.html +878 -0
  37. data/blogs/nse_dplyr/nse_dplyr.md +1198 -0
  38. data/blogs/nse_dplyr/nse_dplyr.pdf +0 -0
  39. data/blogs/oh_my/oh_my.html +274 -386
  40. data/blogs/oh_my/oh_my.md +208 -205
  41. data/blogs/ruby_plot/ruby_plot.Rmd +64 -84
  42. data/blogs/ruby_plot/ruby_plot.html +235 -208
  43. data/blogs/ruby_plot/ruby_plot.md +239 -34
  44. data/blogs/ruby_plot/ruby_plot.pdf +0 -0
  45. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
  46. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
  47. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
  48. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
  49. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
  50. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
  51. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
  52. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
  53. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
  54. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
  55. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
  56. data/examples/Bibliography/master.bib +50 -0
  57. data/examples/Bibliography/stats.bib +72 -0
  58. data/examples/islr/ch2.spec.rb +1 -1
  59. data/examples/islr/ch3_boston.rb +4 -4
  60. data/examples/islr/x_y_rnorm.jpg +0 -0
  61. data/examples/latex_templates/Test-acm_article/Makefile +16 -0
  62. data/examples/latex_templates/Test-acm_article/Test-acm_article.Rmd +65 -0
  63. data/examples/latex_templates/Test-acm_article/acm_proc_article-sp.cls +1670 -0
  64. data/examples/latex_templates/Test-acm_article/sensys-abstract.cls +703 -0
  65. data/examples/latex_templates/Test-acm_article/sigproc.bib +59 -0
  66. data/examples/latex_templates/Test-acs_article/Test-acs_article.Rmd +260 -0
  67. data/examples/latex_templates/Test-acs_article/Test-acs_article.pdf +0 -0
  68. data/examples/latex_templates/Test-acs_article/acs-Test-acs_article.bib +11 -0
  69. data/examples/latex_templates/Test-acs_article/acs-my_output.bib +11 -0
  70. data/examples/latex_templates/Test-acs_article/acstest.bib +17 -0
  71. data/examples/latex_templates/Test-aea_article/AEA.cls +1414 -0
  72. data/examples/latex_templates/Test-aea_article/BibFile.bib +0 -0
  73. data/examples/latex_templates/Test-aea_article/Test-aea_article.Rmd +108 -0
  74. data/examples/latex_templates/Test-aea_article/Test-aea_article.pdf +0 -0
  75. data/examples/latex_templates/Test-aea_article/aea.bst +1269 -0
  76. data/examples/latex_templates/Test-aea_article/multicol.sty +853 -0
  77. data/examples/latex_templates/Test-aea_article/references.bib +0 -0
  78. data/examples/latex_templates/Test-aea_article/setspace.sty +546 -0
  79. data/examples/latex_templates/Test-amq_article/Test-amq_article.Rmd +256 -0
  80. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdf +0 -0
  81. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdfsync +3397 -0
  82. data/examples/latex_templates/Test-amq_article/pics/Figure2.pdf +0 -0
  83. data/examples/latex_templates/Test-ams_article/Test-ams_article.Rmd +215 -0
  84. data/examples/latex_templates/Test-ams_article/amstest.bib +436 -0
  85. data/examples/latex_templates/Test-asa_article/Test-asa_article.Rmd +153 -0
  86. data/examples/latex_templates/Test-asa_article/Test-asa_article.pdf +0 -0
  87. data/examples/latex_templates/Test-asa_article/agsm.bst +1353 -0
  88. data/examples/latex_templates/Test-asa_article/bibliography.bib +233 -0
  89. data/examples/latex_templates/Test-ieee_article/IEEEtran.bst +2409 -0
  90. data/examples/latex_templates/Test-ieee_article/IEEEtran.cls +6346 -0
  91. data/examples/latex_templates/Test-ieee_article/Test-ieee_article.Rmd +175 -0
  92. data/examples/latex_templates/Test-ieee_article/Test-ieee_article.pdf +0 -0
  93. data/examples/latex_templates/Test-ieee_article/mybibfile.bib +20 -0
  94. data/examples/latex_templates/Test-rjournal_article/RJournal.sty +335 -0
  95. data/examples/latex_templates/Test-rjournal_article/RJreferences.bib +18 -0
  96. data/examples/latex_templates/Test-rjournal_article/RJwrapper.pdf +0 -0
  97. data/examples/latex_templates/Test-rjournal_article/Test-rjournal_article.Rmd +52 -0
  98. data/examples/latex_templates/Test-springer_article/Test-springer_article.Rmd +65 -0
  99. data/examples/latex_templates/Test-springer_article/Test-springer_article.pdf +0 -0
  100. data/examples/latex_templates/Test-springer_article/bibliography.bib +26 -0
  101. data/examples/latex_templates/Test-springer_article/spbasic.bst +1658 -0
  102. data/examples/latex_templates/Test-springer_article/spmpsci.bst +1512 -0
  103. data/examples/latex_templates/Test-springer_article/spphys.bst +1443 -0
  104. data/examples/latex_templates/Test-springer_article/svglov3.clo +113 -0
  105. data/examples/latex_templates/Test-springer_article/svjour3.cls +1431 -0
  106. data/examples/misc/moneyball.rb +1 -1
  107. data/examples/misc/subsetting.rb +37 -37
  108. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.Rmd +73 -0
  109. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.pdf +0 -0
  110. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.Rmd +382 -0
  111. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.pdf +0 -0
  112. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.Rmd +164 -0
  113. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.pdf +0 -0
  114. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.Rmd +92 -0
  115. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.pdf +0 -0
  116. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/attend-grade-relationships.csv +482 -0
  117. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.Rmd +280 -0
  118. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.pdf +0 -0
  119. data/examples/rmarkdown/svm-xaringan-example/svm-xaringan-example.Rmd +386 -0
  120. data/lib/R_interface/r.rb +2 -2
  121. data/lib/R_interface/r_libs.R +6 -1
  122. data/lib/R_interface/r_methods.rb +12 -2
  123. data/lib/R_interface/rdata_frame.rb +8 -17
  124. data/lib/R_interface/rindexed_object.rb +1 -2
  125. data/lib/R_interface/rlist.rb +1 -0
  126. data/lib/R_interface/robject.rb +20 -23
  127. data/lib/R_interface/rpkg.rb +15 -6
  128. data/lib/R_interface/rsupport.rb +13 -19
  129. data/lib/R_interface/ruby_extensions.rb +14 -18
  130. data/lib/R_interface/rvector.rb +0 -12
  131. data/lib/gknit.rb +2 -0
  132. data/lib/gknit/draft.rb +105 -0
  133. data/lib/gknit/knitr_engine.rb +6 -37
  134. data/lib/util/exec_ruby.rb +22 -84
  135. data/lib/util/inline_file.rb +7 -3
  136. data/specs/figures/bg.jpeg +0 -0
  137. data/specs/figures/bg.png +0 -0
  138. data/specs/figures/bg.svg +2 -2
  139. data/specs/figures/dose_len.png +0 -0
  140. data/specs/figures/no_args.jpeg +0 -0
  141. data/specs/figures/no_args.png +0 -0
  142. data/specs/figures/no_args.svg +2 -2
  143. data/specs/figures/width_height.jpeg +0 -0
  144. data/specs/figures/width_height.png +0 -0
  145. data/specs/figures/width_height_units1.jpeg +0 -0
  146. data/specs/figures/width_height_units1.png +0 -0
  147. data/specs/figures/width_height_units2.jpeg +0 -0
  148. data/specs/figures/width_height_units2.png +0 -0
  149. data/specs/r_dataframe.spec.rb +184 -11
  150. data/specs/r_list.spec.rb +4 -4
  151. data/specs/r_list_apply.spec.rb +11 -10
  152. data/specs/ruby_expression.spec.rb +3 -11
  153. data/specs/tmp.rb +106 -34
  154. data/version.rb +1 -1
  155. metadata +96 -33
  156. data/bin/gknit_old_r +0 -236
  157. data/blogs/dev/dev.Rmd +0 -77
  158. data/blogs/dev/dev.md +0 -87
  159. data/blogs/dev/dev_files/figure-html/bubble-1.png +0 -0
  160. data/blogs/dev/dev_files/figure-html/diverging_bar. +0 -0
  161. data/blogs/dev/dev_files/figure-html/diverging_bar.png +0 -0
  162. data/blogs/dplyr/dplyr.rb +0 -63
  163. data/blogs/galaaz_ggplot/galaaz_ggplot.aux +0 -43
  164. data/blogs/galaaz_ggplot/galaaz_ggplot.log +0 -640
  165. data/blogs/galaaz_ggplot/galaaz_ggplot.out +0 -10
  166. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +0 -481
  167. data/blogs/galaaz_ggplot/midwest.png +0 -0
  168. data/blogs/galaaz_ggplot/scatter_plot.png +0 -0
  169. data/blogs/ruby_plot/ruby_plot.Rmd_external_figs +0 -662
  170. data/blogs/ruby_plot/ruby_plot.tex +0 -1077
  171. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +0 -57
  172. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.svg +0 -106
  173. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.svg +0 -110
  174. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.svg +0 -174
  175. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.svg +0 -236
  176. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.svg +0 -296
  177. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.svg +0 -236
  178. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.svg +0 -218
  179. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.svg +0 -128
  180. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.svg +0 -150
  181. data/examples/paper/paper.rb +0 -36
@@ -1,10 +0,0 @@
1
- \BOOKMARK [1][-]{section.1}{\376\377\000I\000n\000t\000r\000o\000d\000u\000c\000t\000i\000o\000n}{}% 1
2
- \BOOKMARK [2][-]{subsection.1.1}{\376\377\000W\000h\000a\000t\000\040\000d\000o\000e\000s\000\040\000G\000a\000l\000a\000a\000z\000\040\000m\000e\000a\000n}{section.1}% 2
3
- \BOOKMARK [1][-]{section.2}{\376\377\000G\000a\000l\000a\000a\000z\000\040\000D\000e\000m\000o}{}% 3
4
- \BOOKMARK [2][-]{subsection.2.1}{\376\377\000P\000r\000e\000r\000e\000q\000u\000i\000s\000i\000t\000e\000s}{section.2}% 4
5
- \BOOKMARK [2][-]{subsection.2.2}{\376\377\000P\000r\000e\000p\000a\000r\000a\000t\000i\000o\000n}{section.2}% 5
6
- \BOOKMARK [2][-]{subsection.2.3}{\376\377\000R\000u\000n\000n\000i\000n\000g\000\040\000t\000h\000e\000\040\000d\000e\000m\000o}{section.2}% 6
7
- \BOOKMARK [2][-]{subsection.2.4}{\376\377\000R\000u\000n\000n\000i\000n\000g\000\040\000o\000t\000h\000e\000r\000\040\000d\000e\000m\000o\000s}{section.2}% 7
8
- \BOOKMARK [1][-]{section.3}{\376\377\000T\000h\000e\000\040\000d\000e\000m\000o\000\040\000c\000o\000d\000e}{}% 8
9
- \BOOKMARK [1][-]{section.4}{\376\377\000A\000n\000\040\000e\000x\000t\000e\000n\000s\000i\000o\000n\000\040\000t\000o\000\040\000t\000h\000e\000\040\000e\000x\000a\000m\000p\000l\000e}{}% 9
10
- \BOOKMARK [1][-]{section.5}{\376\377\000C\000o\000n\000c\000l\000u\000s\000i\000o\000n}{}% 10
@@ -1,481 +0,0 @@
1
- \documentclass[11pt,]{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={Ruby Plotting with Galaaz},
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{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
42
- \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
43
- \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
44
- \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
45
- \newcommand{\BuiltInTok}[1]{#1}
46
- \newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
47
- \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
48
- \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
49
- \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
50
- \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
51
- \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
52
- \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
53
- \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
54
- \newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
55
- \newcommand{\ExtensionTok}[1]{#1}
56
- \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
57
- \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
58
- \newcommand{\ImportTok}[1]{#1}
59
- \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
60
- \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
61
- \newcommand{\NormalTok}[1]{#1}
62
- \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
63
- \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
64
- \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
65
- \newcommand{\RegionMarkerTok}[1]{#1}
66
- \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
67
- \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
68
- \newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
69
- \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
70
- \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
71
- \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#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{Ruby Plotting with Galaaz}
118
- \pretitle{\vspace{\droptitle}\centering\huge}
119
- \posttitle{\par}
120
- \subtitle{An example of tightly coupling Ruby and R in GraalVM}
121
- \author{Rodrigo Botafogo}
122
- \preauthor{\centering\large\emph}
123
- \postauthor{\par}
124
- \predate{\centering\large\emph}
125
- \postdate{\par}
126
- \date{16 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
- % needed for 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
-
153
- \usepackage{fancyhdr}
154
- % set the header and foot style
155
- % style 'fancy' adds the section name on the header
156
- % and the page number on the footer
157
- \pagestyle{fancy}
158
-
159
- % style 'fancyhf' leaves header and footer empty
160
- %\fancyhf{}
161
-
162
- % sets the left head element to \rightmark, which contains the
163
- % current section (\leftmark is the current chapter)
164
- %\fancyhead[L]{\rightmark} .
165
-
166
- % sets the right head element to the page number.
167
- % \fancyhead[R]{\thepage}
168
-
169
- % lets the head rule disappear.
170
- % \renewcommand{\headrulewidth}{0pt}
171
- % Possible selectors for the optional argument of \fancyhead/\fancyfoot
172
- % are L (left), C (center) or R (right) for the position of the element
173
- % and E (even) or O (odd) to distinguish even and odd pages. If you omit
174
- % E/O the element is set for all pages.
175
-
176
- % \usepackage{lipsum}
177
-
178
- % make available command lastpage
179
- \usepackage{lastpage}
180
-
181
- % default fontsize 11pt better to add
182
- % fontsize on the yaml header
183
- % \usepackage[fontsize=11pt]{scrextend}
184
-
185
- % comandos para formatar uma tabela
186
- \usepackage{array}
187
- \newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
188
- \newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
189
- \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
190
-
191
- % necessário if we need to import other latex documents
192
- \usepackage{import}
193
-
194
- % Command to import an R variable to latex
195
- \newcommand{\RtoLatex}[2]{\newcommand{#1}{#2}}
196
-
197
- %
198
- %\newcommand{\atraso}[1]{\color{red} \textbf {Tempo desde a Assinatura do Contrato: #1 dias}}
199
-
200
- \begin{document}
201
- \maketitle
202
-
203
- {
204
- \setcounter{tocdepth}{2}
205
- \tableofcontents
206
- }
207
- \hypertarget{introduction}{%
208
- \section{Introduction}\label{introduction}}
209
-
210
- Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful
211
- language, with a large community, a very large set of libraries and
212
- great for web development. However, it lacks libraries for data science,
213
- statistics, scientific plotting and machine learning. On the other hand,
214
- R is considered one of the most powerful languages for solving all of
215
- the above problems. Maybe the strongest competitor to R is Python with
216
- libraries such as NumPy, Panda, SciPy, SciKit-Learn and a couple more.
217
-
218
- With Galaaz we do not intend to re-implement any of the scientific
219
- libraries in R, we allow for very tight coupling between the two
220
- languages to the point that the Ruby developer does not need to know
221
- that there is an R engine running. For this to happen we use new
222
- technologies provided by Oracle: GraalVM, TruffleRuby and FastR:
223
-
224
- \begin{verbatim}
225
- GraalVM is a universal virtual machine for running applications
226
- written in JavaScript, Python 3, Ruby, R, JVM-based languages like Java,
227
- Scala, Kotlin, and LLVM-based languages such as C and C++.
228
-
229
- GraalVM removes the isolation between programming languages and enables
230
- interoperability in a shared runtime. It can run either standalone or in
231
- the context of OpenJDK, Node.js, Oracle Database, or MySQL.
232
-
233
- GraalVM allows you to write polyglot applications with a seamless way to
234
- pass values from one language to another. With GraalVM there is no copying
235
- or marshaling necessary as it is with other polyglot systems. This lets
236
- you achieve high performance when language boundaries are crossed. Most
237
- of the time there is no additional cost for crossing a language boundary
238
- at all.
239
-
240
- Often developers have to make uncomfortable compromises that require them
241
- to rewrite their software in other languages. For example:
242
-
243
- * “That library is not available in my language. I need to rewrite it.”
244
- * “That language would be the perfect fit for my problem, but we cannot
245
- run it in our environment.”
246
- * “That problem is already solved in my language, but the language is
247
- too slow.”
248
-
249
- With GraalVM we aim to allow developers to freely choose the right language
250
- for the task at hand without making compromises.
251
- \end{verbatim}
252
-
253
- Interested readers should also check out the following sites:
254
-
255
- \begin{itemize}
256
- \tightlist
257
- \item
258
- \href{https://www.graalvm.org/}{GraalVM Home}
259
- \item
260
- \href{https://github.com/oracle/truffleruby}{TruffleRuby}
261
- \item
262
- \href{https://github.com/oracle/fastr}{FastR}
263
- \item
264
- \href{https://medium.com/graalvm/faster-r-with-fastr-4b8db0e0dceb}{Faster
265
- R with FastR}
266
- \end{itemize}
267
-
268
- \hypertarget{what-does-galaaz-mean}{%
269
- \subsection{What does Galaaz mean}\label{what-does-galaaz-mean}}
270
-
271
- Galaaz is the Portuguese name for ``Galahad''. From Wikipedia:
272
-
273
- \begin{verbatim}
274
- Sir Galahad (sometimes referred to as Galeas or Galath),
275
- in Arthurian legend, is a knight of King Arthur's Round Table and one
276
- of the three achievers of the Holy Grail. He is the illegitimate son
277
- of Sir Lancelot and Elaine of Corbenic, and is renowned for his
278
- gallantry and purity as the most perfect of all knights. Emerging quite
279
- late in the medieval Arthurian tradition, Sir Galahad first appears in the
280
- Lancelot–Grail cycle, and his story is taken up in later works such as
281
- the Post-Vulgate Cycle and Sir Thomas Malory's Le Morte d'Arthur.
282
- His name should not be mistaken with Galehaut, a different knight from
283
- Arthurian legend.
284
- \end{verbatim}
285
-
286
- \hypertarget{galaaz-demo}{%
287
- \section{Galaaz Demo}\label{galaaz-demo}}
288
-
289
- \hypertarget{prerequisites}{%
290
- \subsection{Prerequisites}\label{prerequisites}}
291
-
292
- \begin{itemize}
293
- \tightlist
294
- \item
295
- GraalVM (\textgreater{}= rc7)
296
- \item
297
- TruffleRuby
298
- \item
299
- FastR
300
- \end{itemize}
301
-
302
- The following R packages will be automatically installed when necessary,
303
- but could be installed prior to the demo if desired:
304
-
305
- \begin{itemize}
306
- \tightlist
307
- \item
308
- ggplot2
309
- \item
310
- gridExtra
311
- \end{itemize}
312
-
313
- Installation of R packages requires a development environment. In Linux,
314
- the gnu compiler and tools should be enough. I am not sure what is
315
- needed on the Mac.
316
-
317
- In order to run the `specs' the following Ruby package is necessary:
318
-
319
- \begin{itemize}
320
- \tightlist
321
- \item
322
- gem install rspec
323
- \end{itemize}
324
-
325
- \hypertarget{preparation}{%
326
- \subsection{Preparation}\label{preparation}}
327
-
328
- \begin{itemize}
329
- \tightlist
330
- \item
331
- gem install galaaz
332
- \end{itemize}
333
-
334
- \hypertarget{running-the-demo}{%
335
- \subsection{Running the demo}\label{running-the-demo}}
336
-
337
- The ggplot for this demos was extracted from:
338
- \url{http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html}.
339
-
340
- On the console do
341
-
342
- \begin{verbatim}
343
- > galaaz master_list:scatter_plot
344
- \end{verbatim}
345
-
346
- \hypertarget{running-other-demos}{%
347
- \subsection{Running other demos}\label{running-other-demos}}
348
-
349
- Doing on the console
350
-
351
- \begin{verbatim}
352
- > galaaz -T
353
- \end{verbatim}
354
-
355
- will show a list with all available demos. To run any of the demos in
356
- the list, substitute the call to `rake' to `galaaz'. For instance, one
357
- of the examples in the list is `rake sthda:bar'. In order to run this
358
- example just do `galaaz sthda:bar'. Doing `galaaz sthda:all' will run
359
- all demos in the sthda cathegory. Some of the examples require `rspec'
360
- do be available. To install `rspec' just do `gem install rspec'.
361
-
362
- \hypertarget{the-demo-code}{%
363
- \section{The demo code}\label{the-demo-code}}
364
-
365
- The following is the Ruby code and plot for the above example. There is
366
- a small difference between the code in the example and the code bellow.
367
- If the example is ran, the plot will appear on the screen, bellow, we
368
- generate an `svg' image and then include it in this document. In order
369
- to generate and image, the R.svg device is used. To generate the plot on
370
- the screen, use the R.awt device, as commented on the code.
371
-
372
- \begin{figure}
373
- \centering
374
- \includegraphics[width=0.7\textwidth,height=\textheight]{midwest.png}
375
- \caption{Midwest Plot}
376
- \end{figure}
377
-
378
- In R, the code to generate this plot is the following
379
-
380
- \begin{Shaded}
381
- \begin{Highlighting}[]
382
- \CommentTok{# install.packages("ggplot2")}
383
- \CommentTok{# load package and data}
384
- \KeywordTok{options}\NormalTok{(}\DataTypeTok{scipen=}\DecValTok{999}\NormalTok{) }\CommentTok{# turn-off scientific notation like 1e+48}
385
- \KeywordTok{library}\NormalTok{(ggplot2)}
386
- \KeywordTok{theme_set}\NormalTok{(}\KeywordTok{theme_bw}\NormalTok{()) }\CommentTok{# pre-set the bw theme.}
387
- \KeywordTok{data}\NormalTok{(}\StringTok{"midwest"}\NormalTok{, }\DataTypeTok{package =} \StringTok{"ggplot2"}\NormalTok{)}
388
- \CommentTok{# midwest <- read.csv("http://goo.gl/G1K41K") # bkup data source}
389
-
390
- \CommentTok{# Scatterplot}
391
- \NormalTok{gg <-}\StringTok{ }\KeywordTok{ggplot}\NormalTok{(midwest, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x=}\NormalTok{area, }\DataTypeTok{y=}\NormalTok{poptotal)) }\OperatorTok{+}\StringTok{ }
392
- \StringTok{ }\KeywordTok{geom_point}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{col=}\NormalTok{state, }\DataTypeTok{size=}\NormalTok{popdensity)) }\OperatorTok{+}\StringTok{ }
393
- \StringTok{ }\KeywordTok{geom_smooth}\NormalTok{(}\DataTypeTok{method=}\StringTok{"loess"}\NormalTok{, }\DataTypeTok{se=}\NormalTok{F) }\OperatorTok{+}\StringTok{ }
394
- \StringTok{ }\KeywordTok{xlim}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\FloatTok{0.1}\NormalTok{)) }\OperatorTok{+}\StringTok{ }
395
- \StringTok{ }\KeywordTok{ylim}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\DecValTok{500000}\NormalTok{)) }\OperatorTok{+}\StringTok{ }
396
- \StringTok{ }\KeywordTok{labs}\NormalTok{(}\DataTypeTok{subtitle=}\StringTok{"Area Vs Population"}\NormalTok{, }
397
- \DataTypeTok{y=}\StringTok{"Population"}\NormalTok{, }
398
- \DataTypeTok{x=}\StringTok{"Area"}\NormalTok{, }
399
- \DataTypeTok{title=}\StringTok{"Scatterplot"}\NormalTok{, }
400
- \DataTypeTok{caption =} \StringTok{"Source: midwest"}\NormalTok{)}
401
-
402
- \KeywordTok{plot}\NormalTok{(gg)}
403
- \end{Highlighting}
404
- \end{Shaded}
405
-
406
- Note that both codes are very similar. The Ruby code requires the use of
407
- ``R.'' before calling any functions, for instance R function
408
- `geom\_point' becomes `R.geom\_point' in Ruby. R named parameters such
409
- as (col = state, size = popdensity), become in Ruby (col: :state, size:
410
- :popdensity).
411
-
412
- One last point that needs to be observed is the call to the `aes'
413
- function. In Ruby instead of doing `R.aes', we use `E.aes'. The
414
- explanation of why E.aes is needed is an advanced topic in R and depends
415
- on what is know as Non-standard Evaluation (NSE) in R. In short,
416
- function `aes' is lazily evaluated in R, i.e., in R when calling
417
- geom\_point(aes(col=state, size=popdensity)), function geom\_point
418
- receives as argument something similar to a string containing
419
- `aes(col=state, size=popdensity)', and the aes function will be
420
- evaluated inside the geom\_point function. In Ruby, there is no Lazy
421
- evaluation and doing R.aes would try to evaluate aes immediately. In
422
- order to delay the evaluation of function aes we need to use E.aes. The
423
- interested reader on NSE in R is directed to
424
- \url{http://adv-r.had.co.nz/Computing-on-the-language.html}.
425
-
426
- \hypertarget{an-extension-to-the-example}{%
427
- \section{An extension to the
428
- example}\label{an-extension-to-the-example}}
429
-
430
- If both codes are so similar, then why would one use Ruby instead of R
431
- and what good is galaaz after all?
432
-
433
- Ruby is a modern OO language with numerous very useful constructs such
434
- as classes, modules, blocks, procs, etc. The example above focus on the
435
- coupling of both languages, and does not show the use of other Ruby
436
- constructs. In the following example, we will show a more complex
437
- example using other Ruby constructs. This is certainly not a very well
438
- written and robust Ruby code, but it give the idea of how Ruby and R are
439
- strongly coupled.
440
-
441
- Let's imagine that we work in a corporation that has its plot themes.
442
- So, it has defined a `CorpTheme' module. Plots in this corporation
443
- should not have grids, numbers in labels should not use scientific
444
- notation and the preferred color is blue.
445
-
446
- We now define a ScatterPlot class:
447
-
448
- And this is the final code for making the scatter plot with the midwest
449
- data
450
-
451
- \begin{figure}
452
- \centering
453
- \includegraphics[width=0.7\textwidth,height=\textheight]{scatter_plot.png}
454
- \caption{Midwest Plot with `glm' function and modified theme}
455
- \end{figure}
456
-
457
- \hypertarget{conclusion}{%
458
- \section{Conclusion}\label{conclusion}}
459
-
460
- R is a very powerful language for statistical analysis, data analytics,
461
- machine learning, plotting and many other scientific applications with a
462
- very large package ecosystem. However R is often considered hard to
463
- learn and lacking modern computer languages constructs such as object
464
- oriented classes, modules, lambdas, etc. For this reason, many
465
- developers have started or switched from R to Python.
466
-
467
- With Galaaz, R programmers can almost transparently migrate from R to
468
- Ruby, since syntax is almost identical and they have fastR as the R
469
- engine. FastR, by most benchmarks, can be orders of magnitude faster
470
- than Gnu R. Further, by using Galaaz the R developer can start (slowly
471
- if needed) using all of Ruby's constructs and libraries that nicely
472
- complement R packages.
473
-
474
- For the Ruby developer, Galaaz allows the immediate use of R functions
475
- completely transparently. As shown in the second example above, class
476
- ScatterPlot completely hides all the details an R calls from the Ruby
477
- developer, furthermore Galaaz is powered by TruffleRuby that can also be
478
- orders of magnitude faster than MRI Ruby.
479
-
480
-
481
- \end{document}