galaaz 0.5.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (359) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/LICENSE +0 -0
  4. data/README.md +1360 -636
  5. data/Rakefile +61 -41
  6. data/bin/galaaz-bootstrap +137 -0
  7. data/bin/galaaz-jruby +14 -0
  8. data/bin/galaaz_jruby_env.inc.sh +6 -0
  9. data/bin/gbookdown +64 -0
  10. data/bin/gknit +84 -13
  11. data/bin/gknit-draft.rb +0 -0
  12. data/bin/gstudio +5 -3
  13. data/bin/gstudio_irb.rb +0 -0
  14. data/bin/gstudio_pry.rb +0 -0
  15. data/bin/install-tinytex +6 -0
  16. data/bin/run_all_rspec +43 -0
  17. data/bin/run_example +14 -0
  18. data/bin/run_old_rspec +19 -0
  19. data/bin/run_rspec +23 -0
  20. data/bin/run_rspec_subset +38 -0
  21. data/bin/run_slow_rspec +19 -0
  22. data/blogs/R-on-Rails-Planning-Document.md +940 -0
  23. data/blogs/README.md +100 -0
  24. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +38 -66
  25. data/blogs/galaaz_ggplot/galaaz_ggplot.log +754 -0
  26. data/blogs/galaaz_ggplot/galaaz_ggplot.md +115 -155
  27. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +607 -0
  28. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
  29. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
  30. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
  31. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
  32. data/blogs/galaaz_ggplot/midwest.Rmd +3 -3
  33. data/blogs/galaaz_ggplot/midwest_external_png +0 -0
  34. data/blogs/gknit/gknit.Rmd +47 -52
  35. data/blogs/gknit/gknit.md +1430 -0
  36. data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
  37. data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
  38. data/blogs/gknit/lst.rds +0 -0
  39. data/blogs/gknit/model.rb +1 -1
  40. data/blogs/gknit/stats.bib +0 -0
  41. data/blogs/manual/include_model_local_repro.Rmd +14 -0
  42. data/blogs/manual/include_model_local_repro.md +75 -0
  43. data/blogs/manual/lst.rds +0 -0
  44. data/blogs/manual/manual.Rmd +852 -239
  45. data/blogs/manual/manual.log +1786 -0
  46. data/blogs/manual/manual.md +1360 -636
  47. data/blogs/manual/manual.tex +1883 -1161
  48. data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
  49. data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
  50. data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
  51. data/blogs/manual/model.rb +1 -1
  52. data/blogs/nse_dplyr/nse_dplyr.Rmd +84 -111
  53. data/blogs/nse_dplyr/nse_dplyr.log +928 -0
  54. data/blogs/nse_dplyr/nse_dplyr.md +198 -229
  55. data/blogs/oh_my/not_so.rb +0 -0
  56. data/blogs/oh_my/oh_my.Rmd +1234 -25
  57. data/blogs/oh_my/oh_my.log +804 -0
  58. data/blogs/oh_my/oh_my.md +1663 -86
  59. data/blogs/oh_my/oh_my.tex +821 -0
  60. data/blogs/oh_my/old.Rmd +15 -14
  61. data/blogs/ruby_plot/ruby_plot.Rmd +58 -82
  62. data/blogs/ruby_plot/ruby_plot.log +885 -0
  63. data/blogs/ruby_plot/ruby_plot.md +71 -102
  64. data/blogs/ruby_plot/ruby_plot.tex +940 -0
  65. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
  66. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
  67. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
  68. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
  69. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
  70. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
  71. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
  72. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
  73. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
  74. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
  75. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
  76. data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
  77. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  78. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  79. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  80. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  81. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  82. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  83. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  84. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  85. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  86. data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  87. data/blogs/test/test.Rmd +14 -0
  88. data/examples/50Plots_MasterList/Images/midwest-scatterplot.PNG +0 -0
  89. data/examples/50Plots_MasterList/ScatterPlot.rb +0 -0
  90. data/examples/50Plots_MasterList/scatter_plot.rb +0 -0
  91. data/examples/Bibliography/master.bib +0 -0
  92. data/examples/Bibliography/stats.bib +0 -0
  93. data/examples/R/calc.R +0 -0
  94. data/examples/R/java_interop.R +0 -0
  95. data/examples/bioconductor_deseq2_airway/Documentation/DESeq2-airway-walkthrough.md +56 -0
  96. data/examples/bioconductor_deseq2_airway/bench_galaaz_three_same_process.rb +53 -0
  97. data/examples/bioconductor_deseq2_airway/bench_r_three_same_process.R +34 -0
  98. data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb +33 -0
  99. data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz_optimized.rb +34 -0
  100. data/examples/bioconductor_deseq2_airway/deseq2_airway_minimal.R +30 -0
  101. data/examples/bioconductor_deseq2_airway/deseq2_airway_pipeline_for_bench.R +36 -0
  102. data/examples/islr/all.rb +13 -0
  103. data/examples/islr/ch2.spec.rb +37 -7
  104. data/examples/islr/ch3.spec.rb +11 -2
  105. data/examples/islr/ch3_boston.rb +27 -0
  106. data/examples/islr/ch3_multiple_regression.rb +0 -0
  107. data/examples/islr/ch6.spec.rb +24 -1
  108. data/examples/islr/x_y_rnorm.jpg +0 -0
  109. data/examples/latex_templates/Test-acm_article/acm_proc_article-sp.cls +0 -0
  110. data/examples/latex_templates/Test-acm_article/sigproc.bib +0 -0
  111. data/examples/latex_templates/Test-acs_article/acs-Test-acs_article.bib +0 -0
  112. data/examples/latex_templates/Test-acs_article/acs-my_output.bib +0 -0
  113. data/examples/latex_templates/Test-aea_article/BibFile.bib +0 -0
  114. data/examples/latex_templates/Test-aea_article/Test-aea_article.Rmd +0 -0
  115. data/examples/latex_templates/Test-aea_article/references.bib +0 -0
  116. data/examples/latex_templates/Test-amq_article/Test-amq_article.Rmd +0 -0
  117. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdfsync +0 -0
  118. data/examples/latex_templates/Test-ieee_article/IEEEtran.bst +0 -0
  119. data/examples/latex_templates/Test-ieee_article/mybibfile.bib +0 -0
  120. data/examples/latex_templates/Test-rjournal_article/RJournal.sty +0 -0
  121. data/examples/latex_templates/Test-rjournal_article/RJreferences.bib +0 -0
  122. data/examples/latex_templates/Test-rjournal_article/Test-rjournal_article.Rmd +0 -0
  123. data/examples/misc/baseball.csv +0 -0
  124. data/examples/misc/ggplot.rb +3 -2
  125. data/examples/misc/moneyball.rb +0 -0
  126. data/examples/misc/subsetting.rb +0 -0
  127. data/examples/multithread_shards_to_r/shards_to_r.rb +67 -0
  128. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.Rmd +0 -0
  129. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.Rmd +0 -0
  130. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.Rmd +0 -0
  131. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.Rmd +0 -0
  132. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/attend-grade-relationships.csv +0 -0
  133. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.Rmd +0 -0
  134. data/examples/rmarkdown/svm-xaringan-example/svm-xaringan-example.Rmd +0 -0
  135. data/examples/sthda_ggplot/README.md +0 -0
  136. data/examples/sthda_ggplot/RUN.md +41 -0
  137. data/examples/sthda_ggplot/all.rb +0 -0
  138. data/examples/sthda_ggplot/one_variable_continuous/density_gg.rb +0 -0
  139. data/examples/sthda_ggplot/one_variable_continuous/geom_area.rb +0 -0
  140. data/examples/sthda_ggplot/one_variable_continuous/geom_density.rb +2 -0
  141. data/examples/sthda_ggplot/one_variable_continuous/geom_dotplot.rb +0 -0
  142. data/examples/sthda_ggplot/one_variable_continuous/geom_freqpoly.rb +0 -0
  143. data/examples/sthda_ggplot/one_variable_continuous/geom_histogram.rb +0 -0
  144. data/examples/sthda_ggplot/one_variable_continuous/histogram_density.rb +0 -0
  145. data/examples/sthda_ggplot/one_variable_continuous/stat.rb +0 -0
  146. data/examples/sthda_ggplot/one_variable_discrete/bar.rb +0 -0
  147. data/examples/sthda_ggplot/qplots/box_violin_dot.rb +0 -0
  148. data/examples/sthda_ggplot/qplots/scatter_plots.rb +0 -0
  149. data/examples/sthda_ggplot/scatter_gg.rb +0 -0
  150. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_bin2d.rb +0 -0
  151. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_density2d.rb +0 -0
  152. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_hex.rb +0 -0
  153. data/examples/sthda_ggplot/two_variables_cont_cont/geom_point.rb +0 -0
  154. data/examples/sthda_ggplot/two_variables_cont_cont/geom_smooth.rb +0 -0
  155. data/examples/sthda_ggplot/two_variables_cont_cont/misc.rb +0 -0
  156. data/examples/sthda_ggplot/two_variables_cont_function/geom_area.rb +4 -3
  157. data/examples/sthda_ggplot/two_variables_disc_cont/geom_bar.rb +0 -0
  158. data/examples/sthda_ggplot/two_variables_disc_cont/geom_boxplot.rb +0 -0
  159. data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +0 -0
  160. data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +0 -0
  161. data/examples/sthda_ggplot/two_variables_disc_cont/geom_line.rb +0 -0
  162. data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +0 -0
  163. data/examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb +0 -0
  164. data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +0 -0
  165. data/ext/new_bridge/Makefile +46 -0
  166. data/ext/new_bridge/galaaz_gatekeeper_phase0.cpp +12 -0
  167. data/ext/new_bridge/galaaz_gatekeeper_phase1.cpp +1639 -0
  168. data/lib/R_interface/galaaz_device.R +20 -0
  169. data/lib/R_interface/include_engine.R +109 -0
  170. data/lib/R_interface/new_bridge_adapter.rb +824 -0
  171. data/lib/R_interface/r.rb +177 -25
  172. data/lib/R_interface/r_arrow.rb +113 -0
  173. data/lib/R_interface/r_libs.R +3 -3
  174. data/lib/R_interface/r_methods.rb +13 -126
  175. data/lib/R_interface/r_module_s.rb +0 -0
  176. data/lib/R_interface/rbinary_operators.rb +20 -2
  177. data/lib/R_interface/rclosure.rb +5 -1
  178. data/lib/R_interface/rdata_frame.rb +34 -70
  179. data/lib/R_interface/rdevice.rb +125 -0
  180. data/lib/R_interface/rdevices.R +0 -0
  181. data/lib/R_interface/renvironment.rb +10 -4
  182. data/lib/R_interface/rexpression.rb +5 -1
  183. data/lib/R_interface/rindexed_object.rb +41 -13
  184. data/lib/R_interface/rlanguage.rb +20 -62
  185. data/lib/R_interface/rlist.rb +115 -25
  186. data/lib/R_interface/rlogical_operators.rb +0 -0
  187. data/lib/R_interface/rmatrix.rb +2 -11
  188. data/lib/R_interface/rmd_indexed_object.rb +5 -1
  189. data/lib/R_interface/robject.rb +348 -290
  190. data/lib/R_interface/rpkg.rb +0 -0
  191. data/lib/R_interface/rsupport.rb +609 -328
  192. data/lib/R_interface/rsupport_scope.rb +2 -1
  193. data/lib/R_interface/rsymbol.rb +50 -0
  194. data/lib/R_interface/ruby_callback.rb +2 -3
  195. data/lib/R_interface/ruby_extensions.rb +225 -175
  196. data/lib/R_interface/runary_operators.rb +0 -0
  197. data/lib/R_interface/rvector.rb +147 -31
  198. data/lib/galaaz.rb +0 -0
  199. data/lib/galaaz_jruby.rb +22 -0
  200. data/lib/gknit/diagnostics.rb +50 -0
  201. data/lib/gknit/draft.rb +23 -17
  202. data/lib/gknit/include_engine.rb +15 -7
  203. data/lib/gknit/knitr_engine.rb +223 -74
  204. data/lib/gknit/rb_engine.rb +3 -3
  205. data/lib/gknit/ruby_engine.rb +0 -0
  206. data/lib/gknit.rb +1 -0
  207. data/lib/new_bridge/bootstrap/windows_bootstrap.rb +285 -0
  208. data/lib/new_bridge/envelope.rb +51 -0
  209. data/lib/new_bridge/eval_result.rb +26 -0
  210. data/lib/new_bridge/framing.rb +39 -0
  211. data/lib/new_bridge/instance_pool_client.rb +38 -0
  212. data/lib/new_bridge/r_instance_manager.rb +404 -0
  213. data/lib/new_bridge/session_client.rb +530 -0
  214. data/lib/new_bridge/tcp_framed.rb +44 -0
  215. data/lib/new_bridge.rb +9 -0
  216. data/lib/util/exec_ruby.rb +95 -20
  217. data/lib/util/inline_file.rb +35 -30
  218. data/new_bridge_specs/benchmark_phase5_5_unboxing_spec.rb +96 -0
  219. data/new_bridge_specs/eval_r_async_spec.rb +113 -0
  220. data/new_bridge_specs/integration_phase5_1_concurrent_spec.rb +50 -0
  221. data/new_bridge_specs/integration_phase5_1_eval_spec.rb +16 -0
  222. data/new_bridge_specs/integration_phase5_1_r_api_spec.rb +25 -0
  223. data/new_bridge_specs/integration_phase5_1_smoke_spec.rb +31 -0
  224. data/new_bridge_specs/integration_phase5_2_dataframe_unboxing_spec.rb +19 -0
  225. data/new_bridge_specs/integration_phase5_2_handle_eval_unboxing_spec.rb +25 -0
  226. data/new_bridge_specs/integration_phase5_3_callback_args_spec.rb +28 -0
  227. data/new_bridge_specs/integration_phase5_3_callback_error_spec.rb +22 -0
  228. data/new_bridge_specs/integration_phase5_3_callback_timeout_spec.rb +28 -0
  229. data/new_bridge_specs/integration_phase5_3_callbacks_smoke_spec.rb +22 -0
  230. data/new_bridge_specs/integration_phase5_3_edge_cases_spec.rb +52 -0
  231. data/new_bridge_specs/integration_phase5_3_nested_spec.rb +30 -0
  232. data/new_bridge_specs/integration_phase5_4_concurrent_sessions_spec.rb +53 -0
  233. data/new_bridge_specs/integration_phase5_4_nested_session_callbacks_spec.rb +49 -0
  234. data/new_bridge_specs/integration_phase5_4_session_routing_spec.rb +38 -0
  235. data/new_bridge_specs/integration_phase5_5_stress_concurrency_spec.rb +52 -0
  236. data/new_bridge_specs/integration_phase5_5_unbox_walk_spec.rb +46 -0
  237. data/new_bridge_specs/phase0_protocol_spec.rb +96 -0
  238. data/new_bridge_specs/phase1_req_ret_spec.rb +66 -0
  239. data/new_bridge_specs/phase2_multi_instance_spec.rb +67 -0
  240. data/new_bridge_specs/phase3_callbacks_spec.rb +71 -0
  241. data/new_bridge_specs/phase4_2_hardening_spec.rb +252 -0
  242. data/new_bridge_specs/phase4_3_r_instance_manager_spec.rb +85 -0
  243. data/new_bridge_specs/phase4_nested_callbacks_spec.rb +123 -0
  244. data/r_requires/ggplot.rb +0 -0
  245. data/r_requires/knitr.rb +0 -0
  246. data/specs/all.rb +15 -11
  247. data/specs/arrow_from_ruby_batches_spec.rb +50 -0
  248. data/specs/arrow_semantics_spec.rb +64 -0
  249. data/specs/bridge_concurrent_spec.rb +46 -0
  250. data/specs/bridge_nested_spec.rb +25 -0
  251. data/specs/dataframe_semantics_spec.rb +122 -0
  252. data/specs/dataframe_single_index_logical_filter_spec.rb +21 -0
  253. data/specs/dispatch_probe_cache_spec.rb +38 -0
  254. data/specs/dispatch_probe_error_class_fallback_spec.rb +20 -0
  255. data/specs/dispatch_probe_fallback_spec.rb +18 -0
  256. data/specs/environment_semantics_spec.rb +89 -0
  257. data/specs/field_access_spec.rb +31 -0
  258. data/specs/figures/bg.jpeg +0 -0
  259. data/specs/figures/bg.png +0 -0
  260. data/specs/figures/bg.svg +168 -57
  261. data/specs/figures/dose_len.png +0 -0
  262. data/specs/figures/no_args.jpeg +0 -0
  263. data/specs/figures/no_args.png +0 -0
  264. data/specs/figures/no_args.svg +168 -57
  265. data/specs/figures/width_height.jpeg +0 -0
  266. data/specs/figures/width_height.png +0 -0
  267. data/specs/figures/width_height_units1.jpeg +0 -0
  268. data/specs/figures/width_height_units1.png +0 -0
  269. data/specs/figures/width_height_units2.jpeg +0 -0
  270. data/specs/figures/width_height_units2.png +0 -0
  271. data/specs/formula_semantics_spec.rb +81 -0
  272. data/specs/galaaz_util_exec_ruby_spec.rb +85 -0
  273. data/specs/galaaz_util_inline_file_spec.rb +54 -0
  274. data/specs/gknit_cli_option_permutation_spec.rb +24 -0
  275. data/specs/gknit_include_engine_spec.rb +72 -0
  276. data/specs/gknit_install_timeout_report_spec.rb +69 -0
  277. data/specs/gknit_internal_error_report_spec.rb +57 -0
  278. data/specs/gknit_vector_map_output_spec.rb +59 -0
  279. data/specs/globalenv_guardrail_spec.rb +52 -0
  280. data/specs/language_expression_semantics_spec.rb +145 -0
  281. data/specs/list_semantics_spec.rb +111 -0
  282. data/specs/new_bridge_bulk_dataframe_transfer_spec.rb +44 -0
  283. data/specs/new_bridge_bulk_vector_transfer_spec.rb +73 -0
  284. data/specs/new_bridge_callback_timeout_spec.rb +69 -0
  285. data/specs/new_bridge_eval_r_fallback_spec.rb +55 -0
  286. data/specs/nil_null_spec.rb +42 -0
  287. data/specs/object_build_phase2_spec.rb +53 -0
  288. data/specs/phase1_callback_bridge_spec.rb +84 -0
  289. data/specs/phase2_gknit_generic_rendering_guardrail_spec.rb +46 -0
  290. data/specs/phase2_gknit_no_raw_code_leakage_spec.rb +43 -0
  291. data/specs/phase3_gknit_generic_graphics_capture_spec.rb +71 -0
  292. data/specs/plot_device_semantics_spec.rb +28 -0
  293. data/specs/plot_snapshot_semantics_spec.rb +58 -0
  294. data/specs/protocol_result_spec.rb +236 -0
  295. data/specs/r_batch_fail_fast_spec.rb +47 -0
  296. data/specs/r_bridge_bootstrap_spec.rb +11 -0
  297. data/specs/r_devices.spec.rb +1 -1
  298. data/specs/r_eval.spec.rb +16 -18
  299. data/specs/r_function.spec.rb +1 -1
  300. data/specs/r_instance_manager_spec.rb +285 -0
  301. data/specs/r_list_apply.spec.rb +15 -15
  302. data/specs/r_matrix.spec.rb +0 -0
  303. data/specs/r_nse.spec.rb +5 -5
  304. data/specs/r_object_send_dispatch_spec.rb +13 -0
  305. data/specs/r_vector_comparator_spec.rb +8 -0
  306. data/specs/r_vector_creation.spec.rb +0 -0
  307. data/specs/r_vector_functions.spec.rb +0 -0
  308. data/specs/r_vector_object.spec.rb +0 -0
  309. data/specs/r_vector_operators.spec.rb +0 -0
  310. data/specs/r_vector_structured_scalar_reads_spec.rb +35 -0
  311. data/specs/r_vector_subsetting.spec.rb +0 -0
  312. data/specs/range_helper_spec.rb +21 -0
  313. data/specs/rsupport_scope_spec.rb +28 -0
  314. data/specs/rsupport_var_name_thread_safety_spec.rb +24 -0
  315. data/specs/scalar_character_spec.rb +44 -0
  316. data/specs/scoped_symbol_dsl_refinement_spec.rb +40 -0
  317. data/specs/session_env_bridge_spec.rb +25 -0
  318. data/specs/simplecov_bootstrap_spec.rb +10 -0
  319. data/specs/spec_helper.rb +10 -0
  320. data/specs/tmp.rb +0 -0
  321. data/specs/unboxing_recursion_regression_spec.rb +30 -0
  322. data/specs/unboxing_spec.rb +49 -0
  323. data/specs/verify_callbacks.rb +42 -0
  324. data/sty/galaaz.sty +0 -0
  325. data/version.rb +1 -1
  326. metadata +194 -64
  327. data/blogs/galaaz_ggplot/galaaz_ggplot.html +0 -520
  328. data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
  329. data/blogs/galaaz_ggplot/midwest.html +0 -188
  330. data/blogs/gknit/gknit.html +0 -2266
  331. data/blogs/gknit/gknit.pdf +0 -0
  332. data/blogs/manual/manual.html +0 -4638
  333. data/blogs/manual/manual.pdf +0 -0
  334. data/blogs/manual/manual_files/figure-latex/diverging_bar.pdf +0 -0
  335. data/blogs/nse_dplyr/nse_dplyr.html +0 -878
  336. data/blogs/nse_dplyr/nse_dplyr.pdf +0 -0
  337. data/blogs/oh_my/oh_my.html +0 -568
  338. data/blogs/ruby_plot/ruby_plot.html +0 -544
  339. data/blogs/ruby_plot/ruby_plot.pdf +0 -0
  340. data/examples/latex_templates/Test-acs_article/Test-acs_article.pdf +0 -0
  341. data/examples/latex_templates/Test-aea_article/Test-aea_article.pdf +0 -0
  342. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdf +0 -0
  343. data/examples/latex_templates/Test-amq_article/pics/Figure2.pdf +0 -0
  344. data/examples/latex_templates/Test-asa_article/Test-asa_article.pdf +0 -0
  345. data/examples/latex_templates/Test-ieee_article/Test-ieee_article.pdf +0 -0
  346. data/examples/latex_templates/Test-rjournal_article/RJwrapper.pdf +0 -0
  347. data/examples/latex_templates/Test-springer_article/Test-springer_article.pdf +0 -0
  348. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.pdf +0 -0
  349. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.pdf +0 -0
  350. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.pdf +0 -0
  351. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.pdf +0 -0
  352. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.pdf +0 -0
  353. data/specs/r_dataframe.spec.rb +0 -379
  354. data/specs/r_environment.spec.rb +0 -140
  355. data/specs/r_formula.spec.rb +0 -232
  356. data/specs/r_language.spec.rb +0 -112
  357. data/specs/r_list.spec.rb +0 -293
  358. data/specs/r_plots.spec.rb +0 -72
  359. data/specs/ruby_expression.spec.rb +0 -316
@@ -0,0 +1,940 @@
1
+ % Options for packages loaded elsewhere
2
+ \PassOptionsToPackage{unicode}{hyperref}
3
+ \PassOptionsToPackage{hyphens}{url}
4
+ \documentclass[
5
+ 11pt,
6
+ ]{article}
7
+ \usepackage{xcolor}
8
+ \usepackage[margin=1in]{geometry}
9
+ \usepackage{amsmath,amssymb}
10
+ \setcounter{secnumdepth}{5}
11
+ \usepackage{iftex}
12
+ \ifPDFTeX
13
+ \usepackage[T1]{fontenc}
14
+ \usepackage[utf8]{inputenc}
15
+ \usepackage{textcomp} % provide euro and other symbols
16
+ \else % if luatex or xetex
17
+ \usepackage{unicode-math} % this also loads fontspec
18
+ \defaultfontfeatures{Scale=MatchLowercase}
19
+ \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
20
+ \fi
21
+ \usepackage{lmodern}
22
+ \ifPDFTeX\else
23
+ % xetex/luatex font selection
24
+ \fi
25
+ % Use upquote if available, for straight quotes in verbatim environments
26
+ \IfFileExists{upquote.sty}{\usepackage{upquote}}{}
27
+ \IfFileExists{microtype.sty}{% use microtype if available
28
+ \usepackage[]{microtype}
29
+ \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
30
+ }{}
31
+ \makeatletter
32
+ \@ifundefined{KOMAClassName}{% if non-KOMA class
33
+ \IfFileExists{parskip.sty}{%
34
+ \usepackage{parskip}
35
+ }{% else
36
+ \setlength{\parindent}{0pt}
37
+ \setlength{\parskip}{6pt plus 2pt minus 1pt}}
38
+ }{% if KOMA class
39
+ \KOMAoptions{parskip=half}}
40
+ \makeatother
41
+ \usepackage{color}
42
+ \usepackage{fancyvrb}
43
+ \newcommand{\VerbBar}{|}
44
+ \newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
45
+ \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
46
+ % Add ',fontsize=\small' for more characters per line
47
+ \usepackage{framed}
48
+ \definecolor{shadecolor}{RGB}{248,248,248}
49
+ \newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
50
+ \newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
51
+ \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
52
+ \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
53
+ \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
54
+ \newcommand{\BuiltInTok}[1]{#1}
55
+ \newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
56
+ \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
57
+ \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
58
+ \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
59
+ \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
60
+ \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
61
+ \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
62
+ \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
63
+ \newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
64
+ \newcommand{\ExtensionTok}[1]{#1}
65
+ \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
66
+ \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
67
+ \newcommand{\ImportTok}[1]{#1}
68
+ \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
69
+ \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
70
+ \newcommand{\NormalTok}[1]{#1}
71
+ \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
72
+ \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
73
+ \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
74
+ \newcommand{\RegionMarkerTok}[1]{#1}
75
+ \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
76
+ \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
77
+ \newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
78
+ \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
79
+ \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
80
+ \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
81
+ \usepackage{graphicx}
82
+ \makeatletter
83
+ \newsavebox\pandoc@box
84
+ \newcommand*\pandocbounded[1]{% scales image to fit in text height/width
85
+ \sbox\pandoc@box{#1}%
86
+ \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
87
+ \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
88
+ \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
89
+ \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
90
+ \else\usebox{\pandoc@box}%
91
+ \fi%
92
+ }
93
+ % Set default figure placement to htbp
94
+ \def\fps@figure{htbp}
95
+ \makeatother
96
+ \setlength{\emergencystretch}{3em} % prevent overfull lines
97
+ \providecommand{\tightlist}{%
98
+ \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
99
+ % usar portugues do Brasil
100
+ % \usepackage[brazilian]{babel}
101
+ \usepackage[utf8]{inputenc}
102
+
103
+ \usepackage{geometry}
104
+ \geometry{a4paper, top=1in}
105
+
106
+ % needed for kableExtra
107
+ \usepackage{longtable}
108
+ \usepackage{multirow}
109
+ \usepackage[table]{xcolor}
110
+ \usepackage{wrapfig}
111
+ \usepackage{float}
112
+ \usepackage{colortbl}
113
+ \usepackage{pdflscape}
114
+ \usepackage{tabu}
115
+ \usepackage{threeparttable}
116
+ \usepackage[normalem]{ulem}
117
+
118
+ \usepackage{bbm}
119
+ \usepackage{booktabs}
120
+ \usepackage{expex}
121
+
122
+ \usepackage{graphicx}
123
+
124
+ \usepackage{fancyhdr}
125
+ % set the header and foot style
126
+ % style 'fancy' adds the section name on the header
127
+ % and the page number on the footer
128
+ \pagestyle{fancy}
129
+
130
+ % style 'fancyhf' leaves header and footer empty
131
+ %\fancyhf{}
132
+
133
+ % sets the left head element to \rightmark, which contains the
134
+ % current section (\leftmark is the current chapter)
135
+ %\fancyhead[L]{\rightmark} .
136
+
137
+ % sets the right head element to the page number.
138
+ % \fancyhead[R]{\thepage}
139
+
140
+ % lets the head rule disappear.
141
+ % \renewcommand{\headrulewidth}{0pt}
142
+ % Possible selectors for the optional argument of \fancyhead/\fancyfoot
143
+ % are L (left), C (center) or R (right) for the position of the element
144
+ % and E (even) or O (odd) to distinguish even and odd pages. If you omit
145
+ % E/O the element is set for all pages.
146
+
147
+ % \usepackage{lipsum}
148
+
149
+ % make available command lastpage
150
+ \usepackage{lastpage}
151
+
152
+ % default fontsize 11pt better to add
153
+ % fontsize on the yaml header
154
+ % \usepackage[fontsize=11pt]{scrextend}
155
+
156
+ % comandos para formatar uma tabela
157
+ \usepackage{array}
158
+ \newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
159
+ \newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
160
+ \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
161
+
162
+ % necessário if we need to import other latex documents
163
+ \usepackage{import}
164
+
165
+ % Command to import an R variable to latex
166
+ \newcommand{\RtoLatex}[2]{\newcommand{#1}{#2}}
167
+
168
+ %
169
+ %\newcommand{\atraso}[1]{\color{red} \textbf {Tempo desde a Assinatura do Contrato: #1 dias}}
170
+ \usepackage{bookmark}
171
+ \IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
172
+ \urlstyle{same}
173
+ \hypersetup{
174
+ pdftitle={How to make Beautiful Ruby Plots with Galaaz},
175
+ pdfauthor={Rodrigo Botafogo; Daniel Mossé - University of Pittsburgh},
176
+ hidelinks,
177
+ pdfcreator={LaTeX via pandoc}}
178
+
179
+ \title{How to make Beautiful Ruby Plots with Galaaz}
180
+ \author{Rodrigo Botafogo \and Daniel Mossé - University of Pittsburgh}
181
+ \date{November 19th, 2018 (narrative updated for Galaaz 2.0, 2026)}
182
+
183
+ \begin{document}
184
+ \maketitle
185
+
186
+ {
187
+ \setcounter{tocdepth}{2}
188
+ \tableofcontents
189
+ }
190
+ According to Wikipedia ``Ruby is a dynamic, interpreted, reflective,
191
+ object-oriented, general-purpose programming language. It was designed
192
+ and developed in the mid-1990s by Yukihiro''Matz'' Matsumoto in Japan.''
193
+ It reached high popularity with the development of Ruby on Rails (RoR)
194
+ by David Heinemeier Hansson. RoR is a web application framework first
195
+ released around 2005. It makes extensive use of Ruby's metaprogramming
196
+ features. With RoR, Ruby became very popular. According to
197
+ \href{https://www.tiobe.com/tiobe-index/ruby/}{Ruby's Tiobe index} it
198
+ peeked in popularity around 2008, then declined until 2015 when it
199
+ started picking up again. At the time of this writing (November 2018),
200
+ the Tiobe index puts Ruby in 16th position as most popular language.
201
+
202
+ Python, a language similar to Ruby, ranks 4th in the index. Java, C and
203
+ C++ take the first three positions. Ruby is often criticized for its
204
+ focus on web applications. But Ruby can do
205
+ \href{https://github.com/markets/awesome-ruby}{much more} than just web
206
+ applications. Yet, for scientific computing, Ruby lags way behind Python
207
+ and R. Python has Django framework for web, NumPy for numerical arrays,
208
+ Pandas for data analysis. R is a free software environment for
209
+ statistical computing and graphics with thousands of libraries for data
210
+ analysis.
211
+
212
+ Until recently, there was no real perspective for Ruby to bridge this
213
+ gap. Implementing a complete scientific computing infrastructure would
214
+ take too long.
215
+
216
+ \textbf{Galaaz 2.0} couples
217
+ \textbf{\href{https://www.jruby.org/}{JRuby}} (Ruby on the JVM) with
218
+ \textbf{GNU R}---the same R distribution used for data science
219
+ everywhere. A \textbf{bridge} evaluates R from Ruby and exchanges data
220
+ between the two processes so that, from Ruby, you call R functions and
221
+ work with R objects using familiar Ruby syntax. In other words, a Ruby
222
+ programmer can use the capabilities of R without memorizing all of R's
223
+ syntax for day-to-day tasks.
224
+
225
+ An \textbf{earlier line of work} used Oracle's \textbf{GraalVM} with
226
+ \textbf{TruffleRuby} and \textbf{FastR} so that Ruby and R could share
227
+ one JVM runtime. That stack is \textbf{no longer} what Galaaz targets;
228
+ today's Galaaz is developed and tested with \textbf{JRuby + GNU R} (see
229
+ the project manual for setup and command-line tools).
230
+
231
+ Library wrapping is a usual way of bringing features from one language
232
+ into another. To improve performance, Python often wraps more efficient
233
+ C libraries. For the Python developer, the existence of such C libraries
234
+ is hidden. The problem with library wrapping is that for any new
235
+ library, there is the need to handcraft a new wrapper.
236
+
237
+ Galaaz, instead of wrapping a single C or R library, wraps the whole R
238
+ language in Ruby. Doing so, all thousands of R libraries are available
239
+ immediately to Ruby developers without any new wrapping effort.
240
+
241
+ To show the power of Galaaz, we show in this article how Ruby can use
242
+ R's ggplot2 library tranparantly bringing to Ruby the power of high
243
+ quality scientific plotting. We also show that migrating from R to Ruby
244
+ with Galaaz is a matter of small syntactic changes. By using Ruby, the R
245
+ developer can use all of Ruby's powerful object-oriented features. Also,
246
+ with Ruby, it becomes much easier to move code from the analysis phase
247
+ to the production phase.
248
+
249
+ In this article we will explore the R ToothGrowth dataset. To
250
+ illustrate, we will create some boxplots. A primer on boxplot is
251
+ available in
252
+ \href{https://towardsdatascience.com/understanding-boxplots-5e2df7bcbd51}{this
253
+ article}.
254
+
255
+ We will also create a Corporate Template ensuring that plots will have a
256
+ consistent visualization. This template is built using a Ruby module.
257
+ There is a way of building ggplot themes that will work the same as the
258
+ Ruby module. Yet, writing a new theme requires specific knowledge on
259
+ theme writing. Ruby modules are standard to the language and don't need
260
+ special knowledge.
261
+
262
+ \href{https://towardsdatascience.com/ruby-plotting-with-galaaz-an-example-of-tightly-coupling-ruby-and-r-in-graalvm-520b69e21021}{Here}
263
+ is an older article (GraalVM-era Galaaz) with a scatter plot in Ruby;
264
+ the \textbf{ideas} still apply under Galaaz 2.0 with JRuby and GNU R.
265
+
266
+ \section{gKnit}\label{gknit}
267
+
268
+ \emph{Knitr} is an application that converts text written in rmarkdown
269
+ to many different output formats. For instance, a writer can convert an
270
+ rmarkdown document to HTML, \(LaTex\), docx and many other formats.
271
+ Rmarkdown documents can contain text and \emph{code chunks}. Knitr
272
+ formats code chunks in a grayed box in the output document. It also
273
+ executes the code chunks and formats the output in a white box. Every
274
+ line of output from the execution code is preceded by `\#\#'.
275
+
276
+ Knitr allows code chunks to be in R, Python, Ruby and dozens of other
277
+ languages. Yet, while R and Python chunks can share data, in other
278
+ languages, chunks are independent. This means that a variable defined in
279
+ one chunk cannot be used in another chunk.
280
+
281
+ With \emph{gKnit} Ruby code chunks can share data.
282
+
283
+ \section{Exploring the Dataset}\label{exploring-the-dataset}
284
+
285
+ Let's start by exploring our selected dataset. ToothGrowth is an R
286
+ dataset. A dataset is like a simple excel spreadsheet, in which each
287
+ column has only one type of data. For instance one column can have
288
+ float, the other integer, and a third strings. This dataset analyzes the
289
+ length of odontoblasts (cells responsible for tooth growth) in 60 guinea
290
+ pigs, where each animal received one of three dose levels of Vitamin C
291
+ (0.5, 1, and 2 mg/day) by one of two delivery methods, orange juice OJ
292
+ or ascorbic acid (a form of vitamin C and coded as VC).
293
+
294
+ The ToothGrowth dataset contains three columns: `len', `supp' and
295
+ `dose'. Let's take a look at a few rows of this dataset. In Galaaz, R
296
+ variables are accessed by using the corresponding Ruby symbol preceeded
297
+ by the tilda (`\textasciitilde{}') function. Note in the following chunk
298
+ that `ToothGrowth' is the R variable and Ruby's `tooth\_growth' is
299
+ assigned the value of `\textasciitilde:ToothGrowth'.
300
+
301
+ \begin{Shaded}
302
+ \begin{Highlighting}[]
303
+ \CommentTok{\# Read the R ToothGrowth variable and assign it to the}
304
+ \CommentTok{\# Ruby instance variable tooth\_growth that will be }
305
+ \CommentTok{\# available to all Ruby chunks in this document.}
306
+ \NormalTok{tooth\_growth }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:ToothGrowth}
307
+ \CommentTok{\# print the first few elements of the dataset}
308
+ \FunctionTok{puts}\NormalTok{ tooth\_growth}\AttributeTok{.head}
309
+ \end{Highlighting}
310
+ \end{Shaded}
311
+
312
+ \begin{verbatim}
313
+ ## len supp dose
314
+ ## 1 4.2 VC 0.5
315
+ ## 2 11.5 VC 0.5
316
+ ## 3 7.3 VC 0.5
317
+ ## 4 5.8 VC 0.5
318
+ ## 5 6.4 VC 0.5
319
+ ## 6 10.0 VC 0.5
320
+ \end{verbatim}
321
+
322
+ Great! We've managed to read the ToothGrowth dataset and take a look at
323
+ its elements. We see here the first 6 rows of the dataset. To access a
324
+ column, follow the dataset name with a dot (`.') and the name of the
325
+ column. Also use dot notation to chain methods in usual Ruby style.
326
+
327
+ \begin{Shaded}
328
+ \begin{Highlighting}[]
329
+ \CommentTok{\# Access the tooth\_growth \textquotesingle{}len\textquotesingle{} column and print the first few}
330
+ \CommentTok{\# elements of this column with the \textquotesingle{}head\textquotesingle{} method.}
331
+ \FunctionTok{puts}\NormalTok{ tooth\_growth}\AttributeTok{.len.head}
332
+ \end{Highlighting}
333
+ \end{Shaded}
334
+
335
+ \begin{verbatim}
336
+ ## [1] 4.2 11.5 7.3 5.8 6.4 10.0
337
+ \end{verbatim}
338
+
339
+ The `dose' column contains a numeric value with either, 0.5, 1 or 2,
340
+ although the first 6 rows as seen above only contain the 0.5 values.
341
+ Even though those are number, they are better interpreted as a
342
+ \href{https://swcarpentry.github.io/r-novice-inflammation/12-supp-factors/}{factor
343
+ or cathegory}. So, let's convert our `dose' column from numeric to
344
+ `factor'. In R, the function `as.factor' is used to convert data in a
345
+ vector to factors. To use this function from Galaaz the dot (`.') in the
346
+ function name is substituted by '\_\_' (double underline). The function
347
+ `as.factor' becomes 'R.as\_\_factor' or just 'as\_\_factor' when
348
+ chaining.
349
+
350
+ \begin{Shaded}
351
+ \begin{Highlighting}[]
352
+ \CommentTok{\# convert the dose to a factor}
353
+ \NormalTok{tooth\_growth}\AttributeTok{.dose} \OperatorTok{=}\NormalTok{ tooth\_growth}\AttributeTok{.dose.as\_\_factor}
354
+ \end{Highlighting}
355
+ \end{Shaded}
356
+
357
+ Let's explore some more details of this dataset. In particular, let's
358
+ look at its dimensions, structure and summary statistics.
359
+
360
+ \begin{Shaded}
361
+ \begin{Highlighting}[]
362
+ \FunctionTok{puts}\NormalTok{ tooth\_growth}\AttributeTok{.dim}
363
+ \end{Highlighting}
364
+ \end{Shaded}
365
+
366
+ \begin{verbatim}
367
+ ## [1] 60 3
368
+ \end{verbatim}
369
+
370
+ This dataset has 60 rows, one for each subject and 3 columns, as we have
371
+ already seen.
372
+
373
+ Note that we do not need to call `puts' when using the `str' function.
374
+ This functions does not return anything and prints the structure of the
375
+ dataset as a side effect.
376
+
377
+ \begin{Shaded}
378
+ \begin{Highlighting}[]
379
+ \NormalTok{tooth\_growth}\AttributeTok{.str}
380
+ \end{Highlighting}
381
+ \end{Shaded}
382
+
383
+ Observe that both variables `supp' and `dose' are factors. The system
384
+ made variable `supp' a factor automatically, since it contais two
385
+ strings OJ and VC.
386
+
387
+ Finally, using the summary method, we get the statistical summary for
388
+ the dataset
389
+
390
+ \begin{Shaded}
391
+ \begin{Highlighting}[]
392
+ \FunctionTok{puts}\NormalTok{ tooth\_growth}\AttributeTok{.summary}
393
+ \end{Highlighting}
394
+ \end{Shaded}
395
+
396
+ \begin{verbatim}
397
+ ## len supp dose
398
+ ## Min. : 4.20 OJ:30 0.5:20
399
+ ## 1st Qu.:13.07 VC:30 1 :20
400
+ ## Median :19.25 2 :20
401
+ ## Mean :18.81
402
+ ## 3rd Qu.:25.27
403
+ ## Max. :33.90
404
+ \end{verbatim}
405
+
406
+ \section{Doing the Data Analysis}\label{doing-the-data-analysis}
407
+
408
+ \subsection{Quick plot for seing the
409
+ data}\label{quick-plot-for-seing-the-data}
410
+
411
+ Let's now create our first plot with the given data by accessing ggplot2
412
+ from Ruby. For Rubyists that have never seen or used ggplot2, here is
413
+ the description of ggplot found in its home page:
414
+
415
+ \begin{quote}
416
+ ``ggplot2 is a system for declaratively creating graphics, based on
417
+ \emph{The Grammar of Graphics}. You provide the data, tell ggplot2 how
418
+ to map variables to aesthetics, what graphical primitives to use, and it
419
+ takes care of the details.''
420
+ \end{quote}
421
+
422
+ This description might be a bit cryptic and it is best to see it at work
423
+ to understand it. Basically, in the \emph{grammar of graphics}
424
+ developers add layers of components such as grid, axis, data, title,
425
+ subtitle and also graphical primitives such as \emph{bar plot},
426
+ \emph{box plot}, to form the final graphics.
427
+
428
+ In order to make a plot, we use the `ggplot' function to the dataset. In
429
+ R, this would be written as
430
+ \texttt{ggplot(\textless{}dataset\textgreater{},\ ...)}. Galaaz gives
431
+ you the flexibility to use either
432
+ \texttt{R.ggplot(\textless{}dataset\textgreater{},\ ...)} or
433
+ \texttt{\textless{}dataset\textgreater{}.ggplot(...)}. In the graph
434
+ specification bellow, we use the second notation that looks more like
435
+ Ruby.\\
436
+ ggplot uses the `aes' method to specify x and y axes; in this case, the
437
+ `dose' on the \(x\) axis and the `length' on the \(y\) axis: `E.aes(x:
438
+ :dose, y: :len)'. To specify the type of plot add a geom to the plot.
439
+ For a boxplot, the geom is R.geom\_boxplot.
440
+
441
+ \begin{Shaded}
442
+ \begin{Highlighting}[]
443
+ \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}ggplot\textquotesingle{}}
444
+
445
+ \NormalTok{e }\OperatorTok{=}\NormalTok{ tooth\_growth}\AttributeTok{.ggplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{x:} \WarningTok{:dose}\NormalTok{, }\WarningTok{y:} \WarningTok{:len}\NormalTok{))}
446
+ \FunctionTok{print}\NormalTok{ e }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.geom\_boxplot}
447
+ \end{Highlighting}
448
+ \end{Shaded}
449
+
450
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/dose_len.png}}
451
+
452
+ Great! We've just managed to create and save our first plot in Ruby with
453
+ only four lines of code. We can now easily see with this plot a clear
454
+ trend: as the dose of the supplement is increased, so is the length of
455
+ teeth.
456
+
457
+ \subsection{Facetting the plot}\label{facetting-the-plot}
458
+
459
+ This first plot shows a trend, but our data has information about two
460
+ different forms of delivery method, either by Orange Juice OJ or by
461
+ Vitamin C VC. Let's then try to create a plot that helps us discern the
462
+ effect of each delivery method. This next plot is a \emph{facetted} plot
463
+ where each delivery method gets is own plot. On the left side, the plot
464
+ shows the OJ delivery method. On the right side, we see the VC delivery
465
+ method. To obtain this plot, we use the `R.facet\_grid' function, that
466
+ automatically creates the facets based on the delivery method factors.
467
+ The parameter to the `facet\_grid' method is a
468
+ \href{https://thomasleeper.com/Rcourse/Tutorials/formulae.html}{\emph{formula}}.
469
+
470
+ In Galaaz we give programmers the flexibility to use two different ways
471
+ to write formulas. In the first way, we use Ruby expressions and the
472
+ `.til' function. The formula `x \textasciitilde{} y', becomes `:x.til
473
+ :y'. More information on expressions can be found in
474
+ \href{https://www.rubydoc.info/gems/galaaz/}{Galaaz Manual}.
475
+
476
+ Another way of writing a formula is to use the `formula' function with
477
+ the actual formula as a string. The formula
478
+ \texttt{x\ \textasciitilde{}\ y} in R can be written as
479
+ \texttt{R.formula("x\ \textasciitilde{}\ y")}. For more complex
480
+ formulas, the use of the `formula' function is preferred.
481
+
482
+ The formula \texttt{:all.til\ :supp} indicates to the `facet\_grid'
483
+ function that it needs to facet the plot based on the \texttt{supp}
484
+ variable and split the plot vertically. Changing the formula to
485
+ \texttt{:supp.til\ :all} would split the plot horizontally.
486
+
487
+ \begin{Shaded}
488
+ \begin{Highlighting}[]
489
+ \NormalTok{base\_tooth }\OperatorTok{=}\NormalTok{ tooth\_growth}\AttributeTok{.ggplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{x:} \WarningTok{:dose}\NormalTok{, }\WarningTok{y:} \WarningTok{:len}\NormalTok{, }\WarningTok{group:} \WarningTok{:dose}\NormalTok{))}
490
+
491
+ \NormalTok{bp }\OperatorTok{=}\NormalTok{ base\_tooth }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.geom\_boxplot} \OperatorTok{+}
492
+ \CommentTok{\# Split in vertical direction}
493
+ \ConstantTok{R}\AttributeTok{.facet\_grid}\NormalTok{(}\WarningTok{:all}\AttributeTok{.til} \OperatorTok{:}\NormalTok{supp)}
494
+
495
+ \FunctionTok{puts}\NormalTok{ bp}
496
+ \end{Highlighting}
497
+ \end{Shaded}
498
+
499
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/facet_by_delivery.png}}
500
+
501
+ It now becomes clear that although both methods of delivery have a
502
+ direct impact on tooth growth, method (OJ) is non-linear having a higher
503
+ impact with smaller doses of ascorbic acid and reducing it's impact as
504
+ the dose increases. With the (VC) approach, the impact seems to be more
505
+ linear.
506
+
507
+ \subsection{Adding Color}\label{adding-color}
508
+
509
+ If we were writing about data analysis, we would make a better analysis
510
+ of the trends and improve the statistical analysis. But here we are
511
+ interested in working with ggplot in Ruby. So, let's add some color to
512
+ this plot to make the trend and comparison more visible. In the
513
+ following plot, the boxes are color coded by dose. To add color, it is
514
+ enough to add \texttt{fill:\ :dose} to the aesthetic of boxplot. With
515
+ this command each `dose' factor gets its own color.
516
+
517
+ \begin{Shaded}
518
+ \begin{Highlighting}[]
519
+ \NormalTok{bp }\OperatorTok{=}\NormalTok{ bp }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.geom\_boxplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{fill:} \WarningTok{:dose}\NormalTok{))}
520
+ \FunctionTok{puts}\NormalTok{ bp}
521
+ \end{Highlighting}
522
+ \end{Shaded}
523
+
524
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/facets_by_delivery_color.png}}
525
+
526
+ Facetting helps us compare the general trends for each delivery method.
527
+ Adding color allow us to compare specifically how each dosage impacts
528
+ the tooth growth. It is possible to observe that with smaller doses, up
529
+ to 1mg, OJ performs better than VC (red color). For 2mg, both OJ and VC
530
+ have the same median, but OJ is less disperse (blue color). For 1mg
531
+ (green color), OJ is significantly bettern than VC. By this very quick
532
+ visual analysis, it seems that OJ is a better delivery method than VC.
533
+
534
+ \subsection{Clarifying the data}\label{clarifying-the-data}
535
+
536
+ Boxplots give us a nice idea of the distribution of data, but looking at
537
+ those plots with large colored boxes leaves us wondering what else is
538
+ going on. According to Edward Tufte in Envisioning Information:
539
+
540
+ \begin{quote}
541
+ Thin data rightly prompts suspicions: ``What are they leaving out? Is
542
+ that really everything they know? What are they hiding? Is that all they
543
+ did?'' Now and then it is claimed that vacant space is ``friendly''
544
+ (anthropomorphizing an inherently murky idea) but \emph{it is not how
545
+ much empty space there is, but rather how it is used. It is not how much
546
+ information there is, but rather how effectively it is arranged.}
547
+ \end{quote}
548
+
549
+ And he states:
550
+
551
+ \begin{quote}
552
+ A most unconventional design strategy is revealed: \emph{to clarify, add
553
+ detail.}
554
+ \end{quote}
555
+
556
+ Let's use this wisdom and add yet another layer of data to our plot, so
557
+ that we clarify it with detail and do not leave large empty boxes. In
558
+ this next plot, we add data points for each of the 60 pigs in the
559
+ experiment. For that, add the function `R.geom\_point' to the plot.
560
+
561
+ \begin{Shaded}
562
+ \begin{Highlighting}[]
563
+ \CommentTok{\# Split in vertical direction}
564
+ \NormalTok{bp }\OperatorTok{=}\NormalTok{ bp }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.geom\_point}
565
+
566
+ \FunctionTok{puts}\NormalTok{ bp}
567
+ \end{Highlighting}
568
+ \end{Shaded}
569
+
570
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/facets_with_points.png}}
571
+
572
+ Now we can see the actual distribution of all the 60 subjects. Actually,
573
+ this is not totally true. We have a hard time seing all 60 subjects. It
574
+ seems that some points might be placed one over the other hiding useful
575
+ information.
576
+
577
+ But no sweat! Another layer might solve the problem. In the following
578
+ plot a new layer called `geom\_jitter' is added to the plot. Jitter adds
579
+ a small amount of random variation to the location of each point, and is
580
+ a useful way of handling overplotting caused by discreteness in smaller
581
+ datasets. This makes it easier to see all of the points and prevents
582
+ data hiding. We also add color and change the shape of the points,
583
+ making them even easier to see.
584
+
585
+ \begin{Shaded}
586
+ \begin{Highlighting}[]
587
+ \CommentTok{\# Split in vertical direction}
588
+ \FunctionTok{puts}\NormalTok{ bp }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.geom\_jitter}\NormalTok{(}\WarningTok{shape:} \DecValTok{23}\NormalTok{, }\WarningTok{color:} \StringTok{"cyan3"}\NormalTok{, }\WarningTok{size:} \DecValTok{1}\NormalTok{)}
589
+ \end{Highlighting}
590
+ \end{Shaded}
591
+
592
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/facets_with_jitter.png}}
593
+
594
+ Now we can see all 60 points in the graph. We have here a much higher
595
+ information density and we can see outliers and subjects distribution.
596
+
597
+ \section{Preparing the Plot for
598
+ Presentation}\label{preparing-the-plot-for-presentation}
599
+
600
+ We have come a long way since our first plot. As we already said, this
601
+ is not an article about data analysis and the focus is on the
602
+ integration of Ruby and ggplot. So, let's assume that the analysis is
603
+ now done. Yet, ending the analysis does not mean that the work is done.
604
+ On the contrary, the hardest part is yet to come!
605
+
606
+ After the analysis it is necessary to communicate it by making a final
607
+ plot for presentation. The last plot has all the information we want to
608
+ share, but it is not very pleasing to the eye.
609
+
610
+ \subsection{Improving Colors}\label{improving-colors}
611
+
612
+ Let's start by trying to improve colors. For now, we will not use the
613
+ jitter layer. The previous plot has three bright colors that have no
614
+ relashionship between them. Is there any obvious, or non-obvious for
615
+ that matter, interpretation for the colors? Clearly, they are just
616
+ random colors selected automatically by our software. Although those
617
+ colors helped us understand the data, for a final presentation random
618
+ colors can distract the viewer.
619
+
620
+ In the following plot we use shades function `scale\_fill\_manual' to
621
+ change the colors of the boxes and order of labels. For colors, we use
622
+ shades of blue for each dosage, with light blue (`cyan') representing
623
+ the lower dose and deep blue (`deepskyblue4') the higher dose. Also, the
624
+ legend could be improved: we use the `breaks' parameter to put the
625
+ smaller value (0.5) at the botton of the labels and the largest (2) at
626
+ the top. This ordering seems more natural and matches with the actual
627
+ order of the colors in the plot.
628
+
629
+ \begin{Shaded}
630
+ \begin{Highlighting}[]
631
+ \NormalTok{bp }\OperatorTok{=}\NormalTok{ bp }\OperatorTok{+}
632
+ \ConstantTok{R}\AttributeTok{.scale\_fill\_manual}\NormalTok{(}\WarningTok{values:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"cyan"}\NormalTok{, }\StringTok{"deepskyblue"}\NormalTok{, }\StringTok{"deepskyblue4"}\NormalTok{),}
633
+ \WarningTok{breaks:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"2"}\NormalTok{,}\StringTok{"1"}\NormalTok{,}\StringTok{"0.5"}\NormalTok{))}
634
+
635
+ \FunctionTok{puts}\NormalTok{ bp}
636
+ \end{Highlighting}
637
+ \end{Shaded}
638
+
639
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/facets_by_delivery_color2.png}}
640
+
641
+ \subsection{Violin Plot and Jitter}\label{violin-plot-and-jitter}
642
+
643
+ The boxplot with jitter did look a bit overwhelming. The next plot uses
644
+ a variation of a boxplot known as a \emph{violin plot} with jittered
645
+ data.
646
+
647
+ \href{https://en.wikipedia.org/wiki/Violin_plot}{From Wikipedia}
648
+
649
+ \begin{quote}
650
+ A violin plot is a method of plotting numeric data. It is similar to a
651
+ box plot with a rotated kernel density plot on each side.
652
+
653
+ A violin plot has four layers. The outer shape represents all possible
654
+ results, with thickness indicating how common. (Thus the thickest
655
+ section represents the mode average.) The next layer inside represents
656
+ the values that occur 95\% of the time. The next layer (if it exists)
657
+ inside represents the values that occur 50\% of the time. The central
658
+ dot represents the median average value.
659
+ \end{quote}
660
+
661
+ \begin{Shaded}
662
+ \begin{Highlighting}[]
663
+ \NormalTok{violin }\OperatorTok{=}\NormalTok{ base\_tooth }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.geom\_violin}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{fill:} \WarningTok{:dose}\NormalTok{)) }\OperatorTok{+}
664
+ \ConstantTok{R}\AttributeTok{.facet\_grid}\NormalTok{(}\WarningTok{:all}\AttributeTok{.til} \OperatorTok{:}\NormalTok{supp) }\OperatorTok{+}
665
+ \ConstantTok{R}\AttributeTok{.geom\_jitter}\NormalTok{(}\WarningTok{shape:} \DecValTok{23}\NormalTok{, }\WarningTok{color:} \StringTok{"cyan3"}\NormalTok{, }\WarningTok{size:} \DecValTok{1}\NormalTok{) }\OperatorTok{+}
666
+ \ConstantTok{R}\AttributeTok{.scale\_fill\_manual}\NormalTok{(}\WarningTok{values:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"cyan"}\NormalTok{, }\StringTok{"deepskyblue"}\NormalTok{, }\StringTok{"deepskyblue4"}\NormalTok{),}
667
+ \WarningTok{breaks:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"2"}\NormalTok{,}\StringTok{"1"}\NormalTok{,}\StringTok{"0.5"}\NormalTok{))}
668
+
669
+ \FunctionTok{puts}\NormalTok{ violin}
670
+ \end{Highlighting}
671
+ \end{Shaded}
672
+
673
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/violin_with_jitter.png}}
674
+
675
+ This plot is an alternative to the original boxplot. For the final
676
+ presentation, it is important to think which graphics will be best
677
+ understood by our audience. A violin plot is a less known plot and could
678
+ add mental overhead, yet, in my opinion, it does look a lit bit better
679
+ than the boxplot and provides even more information than the boxplot
680
+ with jitter.
681
+
682
+ \subsection{Adding Decoration}\label{adding-decoration}
683
+
684
+ Our final plot is starting to take shape, but a presentation plot should
685
+ have at least a title, labels on the axes and maybe some other
686
+ decorations. Let's start adding those. Since decoration requires more
687
+ graph area, this new plot has a `width' and `height' specification. When
688
+ there is no specification, the default values from R for width and
689
+ height are 480.
690
+
691
+ The `labs' function adds the required decoration. In this example we use
692
+ `title', `subtitle', `x' for the \(x\) axis label and `y', for the \(y\)
693
+ axis label, and `caption' for information about the plot (for clarity,
694
+ we defined a caption variable using Ruby's Here Doc style).
695
+
696
+ \begin{Shaded}
697
+ \begin{Highlighting}[]
698
+ \NormalTok{caption }\OperatorTok{=} \OperatorTok{\textless{}\textless{}{-}}\ControlFlowTok{EOT}
699
+ \DocumentationTok{Length of odontoblasts in 60 guinea pigs. }
700
+ \DocumentationTok{Each animal received one of three dose levels of vitamin C.}
701
+ \ControlFlowTok{EOT}
702
+
703
+ \NormalTok{decorations }\OperatorTok{=}
704
+ \ConstantTok{R}\AttributeTok{.labs}\NormalTok{(}\WarningTok{title:} \StringTok{"Tooth Growth: Length vs Vitamin C Dose"}\NormalTok{,}
705
+ \WarningTok{subtitle:} \StringTok{"Faceted by delivery method, OJ or VC"}\NormalTok{,}
706
+ \WarningTok{x:} \StringTok{"Dose (mg)"}\NormalTok{, }\WarningTok{y:} \StringTok{"Teeth length"}\NormalTok{,}
707
+ \WarningTok{caption:}\NormalTok{ caption)}
708
+
709
+ \FunctionTok{puts}\NormalTok{ bp }\OperatorTok{+}\NormalTok{ decorations}
710
+ \end{Highlighting}
711
+ \end{Shaded}
712
+
713
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/facets_with_decorations.png}}
714
+
715
+ \subsection{The Corp Theme}\label{the-corp-theme}
716
+
717
+ We are almost done. But the default plot configuration does not yet look
718
+ nice to the eye. We are still distracted by many aspects of the graph.
719
+ First, the back font color does not look good. Then plot background,
720
+ borders, grids all add clutter to the plot.
721
+
722
+ We will now define our corporate theme. in a module that can be
723
+ used/loaded for all plots, similar to CSS or any other style definition.
724
+
725
+ In this theme, we remove borders and grids. The background if left for
726
+ faceted plots but removed for non-faceted plots. Font colors are a shade
727
+ o blue (color: `\#00080'). Axis labels are moved near the end of the
728
+ axis and written in `bold'.
729
+
730
+ \begin{Shaded}
731
+ \begin{Highlighting}[]
732
+ \ControlFlowTok{module} \DataTypeTok{CorpTheme}
733
+
734
+ \ConstantTok{R}\AttributeTok{.install\_and\_loads} \VerbatimStringTok{\textquotesingle{}RColorBrewer\textquotesingle{}}
735
+
736
+ \CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
737
+ \CommentTok{\# face can be (1=plain, 2=bold, 3=italic, 4=bold{-}italic)}
738
+ \CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
739
+
740
+ \ControlFlowTok{def} \DecValTok{self}\AttributeTok{.text\_element}\NormalTok{(size, }\WarningTok{face:} \StringTok{"plain"}\NormalTok{, }\WarningTok{hjust:} \DecValTok{nil}\NormalTok{)}
741
+ \ConstantTok{E}\AttributeTok{.element\_text}\NormalTok{(}\WarningTok{color:} \StringTok{"\#000080"}\NormalTok{, }
742
+ \WarningTok{face:}\NormalTok{ face,}
743
+ \WarningTok{size:}\NormalTok{ size,}
744
+ \WarningTok{hjust:}\NormalTok{ hjust)}
745
+ \ControlFlowTok{end}
746
+
747
+ \CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
748
+ \CommentTok{\# Defines the plot theme (visualization). In this theme we remove major and minor}
749
+ \CommentTok{\# grids, borders and background. We also turn{-}off scientific notation.}
750
+ \CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
751
+
752
+ \ControlFlowTok{def} \DecValTok{self}\AttributeTok{.global\_theme}\NormalTok{(faceted }\OperatorTok{=} \DecValTok{false}\NormalTok{)}
753
+
754
+ \ConstantTok{R}\AttributeTok{.options}\NormalTok{(}\WarningTok{scipen:} \DecValTok{999}\NormalTok{) }\CommentTok{\# turn{-}off scientific notation like 1e+48}
755
+ \CommentTok{\# R.theme\_set(R.theme\_bw)}
756
+
757
+ \CommentTok{\# remove major grids}
758
+ \NormalTok{ gb }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{panel\_\_grid\_\_major:} \ConstantTok{E}\AttributeTok{.element\_blank}\NormalTok{())}
759
+ \CommentTok{\# remove minor grids}
760
+ \NormalTok{ gb }\OperatorTok{=}\NormalTok{ gb }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{panel\_\_grid\_\_minor:} \ConstantTok{E}\AttributeTok{.element\_blank}\NormalTok{)}
761
+ \CommentTok{\# gb = R.theme(panel\_\_grid\_\_minor: E.element\_blank)}
762
+ \CommentTok{\# remove border}
763
+ \NormalTok{ gb }\OperatorTok{=}\NormalTok{ gb }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{panel\_\_border:} \ConstantTok{E}\AttributeTok{.element\_blank}\NormalTok{)}
764
+ \CommentTok{\# remove background. When working with faceted graphs, the background makes}
765
+ \CommentTok{\# it easier to see each facet, so leave it}
766
+ \NormalTok{ gb }\OperatorTok{=}\NormalTok{ gb }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{panel\_\_background:} \ConstantTok{E}\AttributeTok{.element\_blank}\NormalTok{) }\ControlFlowTok{if} \OperatorTok{!}\NormalTok{faceted}
767
+ \CommentTok{\# Change axis font}
768
+ \NormalTok{ gb }\OperatorTok{=}\NormalTok{ gb }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{axis\_\_text:}\NormalTok{ text\_element(}\DecValTok{8}\NormalTok{))}
769
+ \CommentTok{\# change axis title font}
770
+ \NormalTok{ gb }\OperatorTok{=}\NormalTok{ gb }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{axis\_\_title:}\NormalTok{ text\_element(}\DecValTok{10}\NormalTok{, }\WarningTok{face:} \StringTok{"bold"}\NormalTok{, }\WarningTok{hjust:} \DecValTok{1}\NormalTok{))}
771
+ \CommentTok{\# change font of title}
772
+ \NormalTok{ gb }\OperatorTok{=}\NormalTok{ gb }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{title:}\NormalTok{ text\_element(}\DecValTok{12}\NormalTok{, }\WarningTok{face:} \StringTok{"bold"}\NormalTok{))}
773
+ \CommentTok{\# change font of subtitle}
774
+ \NormalTok{ gb }\OperatorTok{=}\NormalTok{ gb }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{plot\_\_subtitle:}\NormalTok{ text\_element(}\DecValTok{9}\NormalTok{))}
775
+ \CommentTok{\# change font of captions}
776
+ \NormalTok{ gb }\OperatorTok{=}\NormalTok{ gb }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.theme}\NormalTok{(}\WarningTok{plot\_\_caption:}\NormalTok{ text\_element(}\DecValTok{8}\NormalTok{))}
777
+
778
+ \ControlFlowTok{end}
779
+
780
+ \ControlFlowTok{end}
781
+ \end{Highlighting}
782
+ \end{Shaded}
783
+
784
+ \subsection{Final Box Plot}\label{final-box-plot}
785
+
786
+ We can now easily make our final boxplot and violin plot. All the layers
787
+ for the plot were added in order to expose our understanding of the data
788
+ and the need to present the result to our audience.
789
+
790
+ The final specification is just the addition of all layers build up to
791
+ this point (`bp'), plus the decorations (`decorations'), plus the
792
+ corporate theme.
793
+
794
+ Here is our final boxplot, without jitter.
795
+
796
+ \begin{Shaded}
797
+ \begin{Highlighting}[]
798
+ \FunctionTok{puts}\NormalTok{ bp }\OperatorTok{+}\NormalTok{ decorations }\OperatorTok{+} \DataTypeTok{CorpTheme}\AttributeTok{.global\_theme}\NormalTok{(}\WarningTok{faceted:} \DecValTok{true}\NormalTok{)}
799
+ \end{Highlighting}
800
+ \end{Shaded}
801
+
802
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/final_box_plot.png}}
803
+
804
+ And here is the final violin plot, with jitter and the same look and
805
+ feel of the corporate boxplot.
806
+
807
+ \begin{Shaded}
808
+ \begin{Highlighting}[]
809
+ \FunctionTok{puts}\NormalTok{ violin }\OperatorTok{+}\NormalTok{ decorations }\OperatorTok{+} \DataTypeTok{CorpTheme}\AttributeTok{.global\_theme}\NormalTok{(}\WarningTok{faceted:} \DecValTok{true}\NormalTok{)}
810
+ \end{Highlighting}
811
+ \end{Shaded}
812
+
813
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/final_violin_plot.png}}
814
+
815
+ \subsection{Another View}\label{another-view}
816
+
817
+ We now make another plot, with the same look and feel as before but
818
+ facetted by dose and not by supplement. This shows how easy it is to
819
+ create new plots by just changing small statement on the \emph{grammar
820
+ of graphics}.
821
+
822
+ \begin{Shaded}
823
+ \begin{Highlighting}[]
824
+ \NormalTok{caption }\OperatorTok{=} \OperatorTok{\textless{}\textless{}{-}}\ControlFlowTok{EOT}
825
+ \DocumentationTok{Length of odontoblasts in 60 guinea pigs. }
826
+ \DocumentationTok{Each animal received one of three dose levels of vitamin C.}
827
+ \ControlFlowTok{EOT}
828
+
829
+ \NormalTok{bp }\OperatorTok{=}\NormalTok{ tooth\_growth}\AttributeTok{.ggplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{x:} \WarningTok{:supp}\NormalTok{, }\WarningTok{y:} \WarningTok{:len}\NormalTok{, }\WarningTok{group:} \WarningTok{:supp}\NormalTok{)) }\OperatorTok{+}
830
+ \ConstantTok{R}\AttributeTok{.geom\_boxplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{fill:} \WarningTok{:supp}\NormalTok{)) }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.facet\_grid}\NormalTok{(}\WarningTok{:all}\AttributeTok{.til} \OperatorTok{:}\NormalTok{dose) }\OperatorTok{+}
831
+ \ConstantTok{R}\AttributeTok{.scale\_fill\_manual}\NormalTok{(}\WarningTok{values:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"cyan"}\NormalTok{, }\StringTok{"deepskyblue4"}\NormalTok{)) }\OperatorTok{+}
832
+ \ConstantTok{R}\AttributeTok{.labs}\NormalTok{(}\WarningTok{title:} \StringTok{"Tooth Growth: Length by Dose"}\NormalTok{,}
833
+ \WarningTok{subtitle:} \StringTok{"Faceted by dose"}\NormalTok{,}
834
+ \WarningTok{x:} \StringTok{"Delivery method"}\NormalTok{, }\WarningTok{y:} \StringTok{"Teeth length"}\NormalTok{,}
835
+ \WarningTok{caption:}\NormalTok{ caption) }\OperatorTok{+}
836
+ \DataTypeTok{CorpTheme}\AttributeTok{.global\_theme}\NormalTok{(}\WarningTok{faceted:} \DecValTok{true}\NormalTok{)}
837
+
838
+ \FunctionTok{puts}\NormalTok{ bp}
839
+ \end{Highlighting}
840
+ \end{Shaded}
841
+
842
+ \pandocbounded{\includegraphics[keepaspectratio]{ruby_plot_files/figure-latex/facet_by_dose.png}}
843
+
844
+ \section{Conclusion}\label{conclusion}
845
+
846
+ In this article, we introduce Galaaz and show how to tightly couple Ruby
847
+ and R in a way that Ruby developers do not need to be aware of the
848
+ executing R engine. For the Ruby developer the existence of R is of no
849
+ consequence, she is just coding in Ruby. On the other hand, for the R
850
+ developer, migration to Ruby is a matter of small syntactic changes with
851
+ a very gentle learning curve. As the R developer becomes more proficient
852
+ in Ruby, he can start using `classes', `modules', `procs', `lambdas'.
853
+
854
+ Trying to bring to Ruby the power of R starting from scratch is an
855
+ enormous endeavour and would probably never be accomplished. Today's
856
+ data scientists would certainly stick with either Python or R. Now, both
857
+ the Ruby and R communities can benefit from this marriage:
858
+ \textbf{Galaaz 2.0} uses \textbf{standard GNU R} for statistics and
859
+ graphics and \textbf{JRuby} for application code, threading, and the JVM
860
+ ecosystem. We presented the process to couple Ruby and R; the coupling
861
+ is implemented by the Galaaz bridge and \textbf{gKnit} for literate
862
+ documents, not by a single GraalVM polyglot runtime.
863
+
864
+ For performance, expect \textbf{ordinary GNU R} behaviour for model
865
+ fitting and plotting, while \textbf{JRuby} gives \textbf{real parallel
866
+ threads} on the Ruby side and access to Java libraries when you need
867
+ them.
868
+
869
+ This article has shown how to improve a plot step-by-step. Starting from
870
+ a very simple boxplot with all default configurations, we moved slowly
871
+ to our final plot. The important point here is not if the final plot is
872
+ actually beautiful (as beauty is in the eye of the beholder), but that
873
+ there is a process of small steps improvements that can be followed to
874
+ getting a final plot ready for presentation.
875
+
876
+ Finally, this whole article was written in rmarkdown and compiled to
877
+ HTML by \emph{gknit}, an application that wraps \emph{knitr} and allows
878
+ documenting Ruby code. This application can be of great help for any
879
+ Rubyist trying to write articles, blogs or documentation for Ruby.
880
+
881
+ \section{Installing Galaaz}\label{installing-galaaz}
882
+
883
+ \subsection{Prerequisites (Galaaz 2.0)}\label{prerequisites-galaaz-2.0}
884
+
885
+ \begin{itemize}
886
+ \tightlist
887
+ \item
888
+ \textbf{JRuby} --- Ruby on the JVM
889
+ (\href{https://www.jruby.org/}{jruby.org})
890
+ \item
891
+ A \textbf{JDK} compatible with your JRuby version
892
+ \item
893
+ \textbf{GNU R} --- \texttt{R} on your \texttt{PATH}, with
894
+ compilers/tools available if packages must be built from source
895
+ \end{itemize}
896
+
897
+ The following R packages will be automatically installed when necessary,
898
+ but could be installed prior to using gKnit if desired:
899
+
900
+ \begin{itemize}
901
+ \tightlist
902
+ \item
903
+ ggplot2
904
+ \item
905
+ gridExtra
906
+ \item
907
+ knitr
908
+ \end{itemize}
909
+
910
+ Installation of R packages requires a development environment and can be
911
+ time consuming. On Linux, the usual build tools (e.g.~a C/C++ compiler)
912
+ are typically enough. On macOS, Xcode command-line tools are commonly
913
+ required.
914
+
915
+ \subsection{Preparation}\label{preparation}
916
+
917
+ \begin{itemize}
918
+ \tightlist
919
+ \item
920
+ Install the \textbf{galaaz} gem (from RubyGems when published, or
921
+ \texttt{gem\ build} / \texttt{path:} from a checkout).
922
+ \end{itemize}
923
+
924
+ \subsection{Usage}\label{usage}
925
+
926
+ \begin{itemize}
927
+ \tightlist
928
+ \item
929
+ From the Galaaz repository (or your installed layout), render
930
+ documents with \textbf{\texttt{bin/gknit}} (see the project manual for
931
+ flags such as \texttt{-\/-output\_format\ all}).
932
+ \item
933
+ In Ruby code:
934
+ \texttt{require\ \textquotesingle{}galaaz\textquotesingle{}}
935
+ \item
936
+ For running scripts with the correct JRuby and JVM options, use
937
+ \textbf{\texttt{bin/galaaz-jruby}} as described in the manual.
938
+ \end{itemize}
939
+
940
+ \end{document}