galaaz 0.5.0 → 2.1.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 (378) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/LICENSE +0 -0
  4. data/README.md +1416 -667
  5. data/Rakefile +68 -41
  6. data/bin/galaaz-bootstrap +137 -0
  7. data/bin/galaaz-jruby +11 -0
  8. data/bin/galaaz-ruby +16 -0
  9. data/bin/galaaz_jruby_env.inc.sh +6 -0
  10. data/bin/galaaz_ruby_env.inc.sh +36 -0
  11. data/bin/gbookdown +63 -0
  12. data/bin/gknit +83 -13
  13. data/bin/gknit-draft.rb +0 -0
  14. data/bin/gstudio +5 -3
  15. data/bin/gstudio_irb.rb +0 -0
  16. data/bin/gstudio_pry.rb +0 -0
  17. data/bin/install-tinytex +6 -0
  18. data/bin/run_all_rspec +44 -0
  19. data/bin/run_example +17 -0
  20. data/bin/run_old_rspec +20 -0
  21. data/bin/run_rspec +24 -0
  22. data/bin/run_rspec_subset +38 -0
  23. data/bin/run_slow_rspec +20 -0
  24. data/blogs/R-on-Rails-Planning-Document.md +940 -0
  25. data/blogs/README.md +100 -0
  26. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +38 -66
  27. data/blogs/galaaz_ggplot/galaaz_ggplot.log +754 -0
  28. data/blogs/galaaz_ggplot/galaaz_ggplot.md +115 -155
  29. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +607 -0
  30. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-gfm/midwest_rb.png +0 -0
  31. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-gfm/scatter_plot_rb.png +0 -0
  32. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
  33. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
  34. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
  35. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
  36. data/blogs/galaaz_ggplot/midwest.Rmd +3 -3
  37. data/blogs/galaaz_ggplot/midwest_external_png +0 -0
  38. data/blogs/gknit/gknit.Rmd +47 -52
  39. data/blogs/gknit/gknit.md +1430 -0
  40. data/blogs/gknit/gknit_files/figure-gfm/bubble-1.png +0 -0
  41. data/blogs/gknit/gknit_files/figure-gfm/diverging_bar.png +0 -0
  42. data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
  43. data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
  44. data/blogs/gknit/lst.rds +0 -0
  45. data/blogs/gknit/model.rb +1 -1
  46. data/blogs/gknit/stats.bib +0 -0
  47. data/blogs/manual/include_model_local_repro.Rmd +14 -0
  48. data/blogs/manual/include_model_local_repro.md +75 -0
  49. data/blogs/manual/lst.rds +0 -0
  50. data/blogs/manual/manual.Rmd +855 -239
  51. data/blogs/manual/manual.log +1786 -0
  52. data/blogs/manual/manual.md +1416 -667
  53. data/blogs/manual/manual.tex +1883 -1161
  54. data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
  55. data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
  56. data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
  57. data/blogs/manual/model.rb +1 -1
  58. data/blogs/nse_dplyr/nse_dplyr.Rmd +84 -111
  59. data/blogs/nse_dplyr/nse_dplyr.log +928 -0
  60. data/blogs/nse_dplyr/nse_dplyr.md +198 -229
  61. data/blogs/oh_my/not_so.rb +0 -0
  62. data/blogs/oh_my/oh_my.Rmd +1234 -25
  63. data/blogs/oh_my/oh_my.log +804 -0
  64. data/blogs/oh_my/oh_my.md +1663 -86
  65. data/blogs/oh_my/oh_my.tex +821 -0
  66. data/blogs/oh_my/old.Rmd +15 -14
  67. data/blogs/ruby_plot/ruby_plot.Rmd +58 -82
  68. data/blogs/ruby_plot/ruby_plot.log +885 -0
  69. data/blogs/ruby_plot/ruby_plot.md +71 -102
  70. data/blogs/ruby_plot/ruby_plot.tex +940 -0
  71. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/dose_len.png +0 -0
  72. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/facet_by_delivery.png +0 -0
  73. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/facet_by_dose.png +0 -0
  74. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/facets_by_delivery_color.png +0 -0
  75. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/facets_by_delivery_color2.png +0 -0
  76. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/facets_with_decorations.png +0 -0
  77. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/facets_with_jitter.png +0 -0
  78. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/facets_with_points.png +0 -0
  79. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/final_box_plot.png +0 -0
  80. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/final_violin_plot.png +0 -0
  81. data/blogs/ruby_plot/ruby_plot_files/figure-gfm/violin_with_jitter.png +0 -0
  82. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
  83. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
  84. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
  85. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
  86. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
  87. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
  88. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
  89. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
  90. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
  91. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
  92. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
  93. data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
  94. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  95. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  96. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  97. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  98. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  99. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  100. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  101. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  102. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  103. data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  104. data/blogs/test/test.Rmd +14 -0
  105. data/blogs/test/test.md +10 -0
  106. data/examples/50Plots_MasterList/Images/midwest-scatterplot.PNG +0 -0
  107. data/examples/50Plots_MasterList/ScatterPlot.rb +2 -1
  108. data/examples/50Plots_MasterList/scatter_plot.rb +1 -0
  109. data/examples/Bibliography/master.bib +0 -0
  110. data/examples/Bibliography/stats.bib +0 -0
  111. data/examples/R/calc.R +0 -0
  112. data/examples/R/java_interop.R +0 -0
  113. data/examples/bioconductor_deseq2_airway/Documentation/DESeq2-airway-walkthrough.md +56 -0
  114. data/examples/bioconductor_deseq2_airway/bench_galaaz_three_same_process.rb +54 -0
  115. data/examples/bioconductor_deseq2_airway/bench_r_three_same_process.R +34 -0
  116. data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb +34 -0
  117. data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz_optimized.rb +35 -0
  118. data/examples/bioconductor_deseq2_airway/deseq2_airway_minimal.R +30 -0
  119. data/examples/bioconductor_deseq2_airway/deseq2_airway_pipeline_for_bench.R +36 -0
  120. data/examples/islr/all.rb +14 -0
  121. data/examples/islr/ch2.spec.rb +38 -7
  122. data/examples/islr/ch3.spec.rb +12 -2
  123. data/examples/islr/ch3_boston.rb +28 -0
  124. data/examples/islr/ch3_multiple_regression.rb +1 -0
  125. data/examples/islr/ch6.spec.rb +25 -1
  126. data/examples/islr/x_y_rnorm.jpg +0 -0
  127. data/examples/latex_templates/Test-acm_article/acm_proc_article-sp.cls +0 -0
  128. data/examples/latex_templates/Test-acm_article/sigproc.bib +0 -0
  129. data/examples/latex_templates/Test-acs_article/acs-Test-acs_article.bib +0 -0
  130. data/examples/latex_templates/Test-acs_article/acs-my_output.bib +0 -0
  131. data/examples/latex_templates/Test-aea_article/BibFile.bib +0 -0
  132. data/examples/latex_templates/Test-aea_article/Test-aea_article.Rmd +0 -0
  133. data/examples/latex_templates/Test-aea_article/references.bib +0 -0
  134. data/examples/latex_templates/Test-amq_article/Test-amq_article.Rmd +0 -0
  135. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdfsync +0 -0
  136. data/examples/latex_templates/Test-ieee_article/IEEEtran.bst +0 -0
  137. data/examples/latex_templates/Test-ieee_article/mybibfile.bib +0 -0
  138. data/examples/latex_templates/Test-rjournal_article/RJournal.sty +0 -0
  139. data/examples/latex_templates/Test-rjournal_article/RJreferences.bib +0 -0
  140. data/examples/latex_templates/Test-rjournal_article/Test-rjournal_article.Rmd +0 -0
  141. data/examples/misc/baseball.csv +0 -0
  142. data/examples/misc/ggplot.rb +5 -3
  143. data/examples/misc/moneyball.rb +1 -0
  144. data/examples/misc/subsetting.rb +1 -0
  145. data/examples/multithread_shards_to_r/shards_to_r.rb +68 -0
  146. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.Rmd +0 -0
  147. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.Rmd +0 -0
  148. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.Rmd +0 -0
  149. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.Rmd +0 -0
  150. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/attend-grade-relationships.csv +0 -0
  151. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.Rmd +0 -0
  152. data/examples/rmarkdown/svm-xaringan-example/svm-xaringan-example.Rmd +0 -0
  153. data/examples/sthda_ggplot/README.md +0 -0
  154. data/examples/sthda_ggplot/RUN.md +41 -0
  155. data/examples/sthda_ggplot/all.rb +1 -0
  156. data/examples/sthda_ggplot/one_variable_continuous/density_gg.rb +1 -0
  157. data/examples/sthda_ggplot/one_variable_continuous/geom_area.rb +1 -0
  158. data/examples/sthda_ggplot/one_variable_continuous/geom_density.rb +3 -0
  159. data/examples/sthda_ggplot/one_variable_continuous/geom_dotplot.rb +1 -0
  160. data/examples/sthda_ggplot/one_variable_continuous/geom_freqpoly.rb +1 -0
  161. data/examples/sthda_ggplot/one_variable_continuous/geom_histogram.rb +1 -0
  162. data/examples/sthda_ggplot/one_variable_continuous/histogram_density.rb +1 -0
  163. data/examples/sthda_ggplot/one_variable_continuous/stat.rb +1 -0
  164. data/examples/sthda_ggplot/one_variable_discrete/bar.rb +1 -0
  165. data/examples/sthda_ggplot/qplots/box_violin_dot.rb +1 -0
  166. data/examples/sthda_ggplot/qplots/scatter_plots.rb +1 -0
  167. data/examples/sthda_ggplot/scatter_gg.rb +1 -0
  168. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_bin2d.rb +1 -0
  169. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_density2d.rb +1 -0
  170. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_hex.rb +1 -0
  171. data/examples/sthda_ggplot/two_variables_cont_cont/geom_point.rb +1 -0
  172. data/examples/sthda_ggplot/two_variables_cont_cont/geom_smooth.rb +1 -0
  173. data/examples/sthda_ggplot/two_variables_cont_cont/misc.rb +1 -0
  174. data/examples/sthda_ggplot/two_variables_cont_function/geom_area.rb +5 -3
  175. data/examples/sthda_ggplot/two_variables_disc_cont/geom_bar.rb +1 -0
  176. data/examples/sthda_ggplot/two_variables_disc_cont/geom_boxplot.rb +1 -0
  177. data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +1 -0
  178. data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +1 -0
  179. data/examples/sthda_ggplot/two_variables_disc_cont/geom_line.rb +1 -0
  180. data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +1 -0
  181. data/examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb +1 -0
  182. data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +1 -0
  183. data/ext/new_bridge/Makefile +46 -0
  184. data/ext/new_bridge/galaaz_gatekeeper_phase0.cpp +12 -0
  185. data/ext/new_bridge/galaaz_gatekeeper_phase1.cpp +1639 -0
  186. data/lib/R_interface/galaaz_device.R +20 -0
  187. data/lib/R_interface/include_engine.R +109 -0
  188. data/lib/R_interface/new_bridge_adapter.rb +824 -0
  189. data/lib/R_interface/r.rb +177 -25
  190. data/lib/R_interface/r_arrow.rb +113 -0
  191. data/lib/R_interface/r_libs.R +3 -3
  192. data/lib/R_interface/r_methods.rb +13 -126
  193. data/lib/R_interface/r_module_s.rb +0 -0
  194. data/lib/R_interface/rbinary_operators.rb +20 -2
  195. data/lib/R_interface/rclosure.rb +5 -1
  196. data/lib/R_interface/rdata_frame.rb +34 -70
  197. data/lib/R_interface/rdevice.rb +125 -0
  198. data/lib/R_interface/rdevices.R +0 -0
  199. data/lib/R_interface/renvironment.rb +10 -4
  200. data/lib/R_interface/rexpression.rb +5 -1
  201. data/lib/R_interface/rindexed_object.rb +41 -13
  202. data/lib/R_interface/rlanguage.rb +20 -62
  203. data/lib/R_interface/rlist.rb +115 -25
  204. data/lib/R_interface/rlogical_operators.rb +0 -0
  205. data/lib/R_interface/rmatrix.rb +2 -11
  206. data/lib/R_interface/rmd_indexed_object.rb +5 -1
  207. data/lib/R_interface/robject.rb +348 -290
  208. data/lib/R_interface/rpkg.rb +0 -0
  209. data/lib/R_interface/rsupport.rb +609 -328
  210. data/lib/R_interface/rsupport_scope.rb +2 -1
  211. data/lib/R_interface/rsymbol.rb +50 -0
  212. data/lib/R_interface/ruby_callback.rb +2 -3
  213. data/lib/R_interface/ruby_extensions.rb +225 -175
  214. data/lib/R_interface/runary_operators.rb +0 -0
  215. data/lib/R_interface/rvector.rb +162 -31
  216. data/lib/galaaz.rb +0 -0
  217. data/lib/galaaz_jruby.rb +22 -0
  218. data/lib/galaaz_ruby.rb +34 -0
  219. data/lib/gknit/diagnostics.rb +50 -0
  220. data/lib/gknit/draft.rb +23 -17
  221. data/lib/gknit/include_engine.rb +15 -7
  222. data/lib/gknit/knitr_engine.rb +223 -74
  223. data/lib/gknit/rb_engine.rb +3 -3
  224. data/lib/gknit/ruby_engine.rb +0 -0
  225. data/lib/gknit.rb +1 -0
  226. data/lib/new_bridge/bootstrap/windows_bootstrap.rb +285 -0
  227. data/lib/new_bridge/envelope.rb +51 -0
  228. data/lib/new_bridge/eval_result.rb +26 -0
  229. data/lib/new_bridge/framing.rb +39 -0
  230. data/lib/new_bridge/instance_pool_client.rb +38 -0
  231. data/lib/new_bridge/r_instance_manager.rb +404 -0
  232. data/lib/new_bridge/session_client.rb +530 -0
  233. data/lib/new_bridge/tcp_framed.rb +44 -0
  234. data/lib/new_bridge.rb +9 -0
  235. data/lib/util/exec_ruby.rb +95 -20
  236. data/lib/util/inline_file.rb +35 -30
  237. data/new_bridge_specs/benchmark_phase5_5_unboxing_spec.rb +96 -0
  238. data/new_bridge_specs/eval_r_async_spec.rb +113 -0
  239. data/new_bridge_specs/integration_phase5_1_concurrent_spec.rb +50 -0
  240. data/new_bridge_specs/integration_phase5_1_eval_spec.rb +16 -0
  241. data/new_bridge_specs/integration_phase5_1_r_api_spec.rb +25 -0
  242. data/new_bridge_specs/integration_phase5_1_smoke_spec.rb +31 -0
  243. data/new_bridge_specs/integration_phase5_2_dataframe_unboxing_spec.rb +19 -0
  244. data/new_bridge_specs/integration_phase5_2_handle_eval_unboxing_spec.rb +25 -0
  245. data/new_bridge_specs/integration_phase5_3_callback_args_spec.rb +28 -0
  246. data/new_bridge_specs/integration_phase5_3_callback_error_spec.rb +22 -0
  247. data/new_bridge_specs/integration_phase5_3_callback_timeout_spec.rb +28 -0
  248. data/new_bridge_specs/integration_phase5_3_callbacks_smoke_spec.rb +22 -0
  249. data/new_bridge_specs/integration_phase5_3_edge_cases_spec.rb +52 -0
  250. data/new_bridge_specs/integration_phase5_3_nested_spec.rb +30 -0
  251. data/new_bridge_specs/integration_phase5_4_concurrent_sessions_spec.rb +53 -0
  252. data/new_bridge_specs/integration_phase5_4_nested_session_callbacks_spec.rb +49 -0
  253. data/new_bridge_specs/integration_phase5_4_session_routing_spec.rb +38 -0
  254. data/new_bridge_specs/integration_phase5_5_stress_concurrency_spec.rb +52 -0
  255. data/new_bridge_specs/integration_phase5_5_unbox_walk_spec.rb +46 -0
  256. data/new_bridge_specs/phase0_protocol_spec.rb +96 -0
  257. data/new_bridge_specs/phase1_req_ret_spec.rb +66 -0
  258. data/new_bridge_specs/phase2_multi_instance_spec.rb +67 -0
  259. data/new_bridge_specs/phase3_callbacks_spec.rb +71 -0
  260. data/new_bridge_specs/phase4_2_hardening_spec.rb +252 -0
  261. data/new_bridge_specs/phase4_3_r_instance_manager_spec.rb +85 -0
  262. data/new_bridge_specs/phase4_nested_callbacks_spec.rb +123 -0
  263. data/r_requires/ggplot.rb +0 -0
  264. data/r_requires/knitr.rb +0 -0
  265. data/specs/all.rb +15 -11
  266. data/specs/arrow_from_ruby_batches_spec.rb +50 -0
  267. data/specs/arrow_semantics_spec.rb +64 -0
  268. data/specs/bridge_concurrent_spec.rb +46 -0
  269. data/specs/bridge_nested_spec.rb +25 -0
  270. data/specs/dataframe_semantics_spec.rb +122 -0
  271. data/specs/dataframe_single_index_logical_filter_spec.rb +21 -0
  272. data/specs/dispatch_probe_cache_spec.rb +38 -0
  273. data/specs/dispatch_probe_error_class_fallback_spec.rb +20 -0
  274. data/specs/dispatch_probe_fallback_spec.rb +18 -0
  275. data/specs/environment_semantics_spec.rb +89 -0
  276. data/specs/field_access_spec.rb +31 -0
  277. data/specs/figures/bg.jpeg +0 -0
  278. data/specs/figures/bg.png +0 -0
  279. data/specs/figures/bg.svg +168 -57
  280. data/specs/figures/dose_len.png +0 -0
  281. data/specs/figures/no_args.jpeg +0 -0
  282. data/specs/figures/no_args.png +0 -0
  283. data/specs/figures/no_args.svg +168 -57
  284. data/specs/figures/width_height.jpeg +0 -0
  285. data/specs/figures/width_height.png +0 -0
  286. data/specs/figures/width_height_units1.jpeg +0 -0
  287. data/specs/figures/width_height_units1.png +0 -0
  288. data/specs/figures/width_height_units2.jpeg +0 -0
  289. data/specs/figures/width_height_units2.png +0 -0
  290. data/specs/formula_semantics_spec.rb +81 -0
  291. data/specs/galaaz_util_exec_ruby_spec.rb +85 -0
  292. data/specs/galaaz_util_inline_file_spec.rb +54 -0
  293. data/specs/gknit_cli_option_permutation_spec.rb +24 -0
  294. data/specs/gknit_include_engine_spec.rb +72 -0
  295. data/specs/gknit_install_timeout_report_spec.rb +69 -0
  296. data/specs/gknit_internal_error_report_spec.rb +57 -0
  297. data/specs/gknit_vector_map_output_spec.rb +59 -0
  298. data/specs/globalenv_guardrail_spec.rb +52 -0
  299. data/specs/language_expression_semantics_spec.rb +145 -0
  300. data/specs/list_semantics_spec.rb +111 -0
  301. data/specs/new_bridge_bulk_dataframe_transfer_spec.rb +44 -0
  302. data/specs/new_bridge_bulk_vector_transfer_spec.rb +73 -0
  303. data/specs/new_bridge_callback_timeout_spec.rb +69 -0
  304. data/specs/new_bridge_eval_r_fallback_spec.rb +55 -0
  305. data/specs/nil_null_spec.rb +42 -0
  306. data/specs/object_build_phase2_spec.rb +53 -0
  307. data/specs/phase1_callback_bridge_spec.rb +84 -0
  308. data/specs/phase2_gknit_generic_rendering_guardrail_spec.rb +46 -0
  309. data/specs/phase2_gknit_no_raw_code_leakage_spec.rb +43 -0
  310. data/specs/phase3_gknit_generic_graphics_capture_spec.rb +71 -0
  311. data/specs/plot_device_semantics_spec.rb +28 -0
  312. data/specs/plot_snapshot_semantics_spec.rb +58 -0
  313. data/specs/protocol_result_spec.rb +236 -0
  314. data/specs/r_batch_fail_fast_spec.rb +47 -0
  315. data/specs/r_bridge_bootstrap_spec.rb +11 -0
  316. data/specs/r_devices.spec.rb +1 -1
  317. data/specs/r_eval.spec.rb +16 -18
  318. data/specs/r_function.spec.rb +1 -1
  319. data/specs/r_instance_manager_spec.rb +285 -0
  320. data/specs/r_list_apply.spec.rb +15 -15
  321. data/specs/r_matrix.spec.rb +0 -0
  322. data/specs/r_nse.spec.rb +5 -5
  323. data/specs/r_object_send_dispatch_spec.rb +13 -0
  324. data/specs/r_vector_comparator_spec.rb +8 -0
  325. data/specs/r_vector_creation.spec.rb +0 -0
  326. data/specs/r_vector_functions.spec.rb +0 -0
  327. data/specs/r_vector_object.spec.rb +0 -0
  328. data/specs/r_vector_operators.spec.rb +0 -0
  329. data/specs/r_vector_structured_scalar_reads_spec.rb +35 -0
  330. data/specs/r_vector_subsetting.spec.rb +0 -0
  331. data/specs/range_helper_spec.rb +21 -0
  332. data/specs/rsupport_scope_spec.rb +28 -0
  333. data/specs/rsupport_var_name_thread_safety_spec.rb +24 -0
  334. data/specs/scalar_character_spec.rb +44 -0
  335. data/specs/scoped_symbol_dsl_refinement_spec.rb +40 -0
  336. data/specs/session_env_bridge_spec.rb +25 -0
  337. data/specs/simplecov_bootstrap_spec.rb +10 -0
  338. data/specs/spec_helper.rb +10 -0
  339. data/specs/tmp.rb +0 -0
  340. data/specs/unboxing_recursion_regression_spec.rb +30 -0
  341. data/specs/unboxing_spec.rb +49 -0
  342. data/specs/verify_callbacks.rb +42 -0
  343. data/sty/galaaz.sty +0 -0
  344. data/version.rb +1 -1
  345. metadata +219 -63
  346. data/blogs/galaaz_ggplot/galaaz_ggplot.html +0 -520
  347. data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
  348. data/blogs/galaaz_ggplot/midwest.html +0 -188
  349. data/blogs/gknit/gknit.html +0 -2266
  350. data/blogs/gknit/gknit.pdf +0 -0
  351. data/blogs/manual/manual.html +0 -4638
  352. data/blogs/manual/manual.pdf +0 -0
  353. data/blogs/manual/manual_files/figure-latex/diverging_bar.pdf +0 -0
  354. data/blogs/nse_dplyr/nse_dplyr.html +0 -878
  355. data/blogs/nse_dplyr/nse_dplyr.pdf +0 -0
  356. data/blogs/oh_my/oh_my.html +0 -568
  357. data/blogs/ruby_plot/ruby_plot.html +0 -544
  358. data/blogs/ruby_plot/ruby_plot.pdf +0 -0
  359. data/examples/latex_templates/Test-acs_article/Test-acs_article.pdf +0 -0
  360. data/examples/latex_templates/Test-aea_article/Test-aea_article.pdf +0 -0
  361. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdf +0 -0
  362. data/examples/latex_templates/Test-amq_article/pics/Figure2.pdf +0 -0
  363. data/examples/latex_templates/Test-asa_article/Test-asa_article.pdf +0 -0
  364. data/examples/latex_templates/Test-ieee_article/Test-ieee_article.pdf +0 -0
  365. data/examples/latex_templates/Test-rjournal_article/RJwrapper.pdf +0 -0
  366. data/examples/latex_templates/Test-springer_article/Test-springer_article.pdf +0 -0
  367. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.pdf +0 -0
  368. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.pdf +0 -0
  369. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.pdf +0 -0
  370. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.pdf +0 -0
  371. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.pdf +0 -0
  372. data/specs/r_dataframe.spec.rb +0 -379
  373. data/specs/r_environment.spec.rb +0 -140
  374. data/specs/r_formula.spec.rb +0 -232
  375. data/specs/r_language.spec.rb +0 -112
  376. data/specs/r_list.spec.rb +0 -293
  377. data/specs/r_plots.spec.rb +0 -72
  378. data/specs/ruby_expression.spec.rb +0 -316
@@ -1,34 +1,43 @@
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
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
7
13
  \usepackage[T1]{fontenc}
8
14
  \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}
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
16
24
  \fi
17
- % use upquote if available, for straight quotes in verbatim environments
25
+ % Use upquote if available, for straight quotes in verbatim environments
18
26
  \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
27
+ \IfFileExists{microtype.sty}{% use microtype if available
28
+ \usepackage[]{microtype}
29
+ \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
23
30
  }{}
24
- \usepackage[margin=1in]{geometry}
25
- \usepackage{hyperref}
26
- \hypersetup{unicode=true,
27
- pdftitle={Galaaz Manual},
28
- pdfauthor={Rodrigo Botafogo},
29
- pdfborder={0 0 0},
30
- breaklinks=true}
31
- \urlstyle{same} % don't use monospace font for urls
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
32
41
  \usepackage{color}
33
42
  \usepackage{fancyvrb}
34
43
  \newcommand{\VerbBar}{|}
@@ -38,94 +47,99 @@
38
47
  \usepackage{framed}
39
48
  \definecolor{shadecolor}{RGB}{248,248,248}
40
49
  \newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
41
- \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
42
- \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
43
- \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
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}}
44
53
  \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
45
- \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
46
- \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
54
+ \newcommand{\BuiltInTok}[1]{#1}
47
55
  \newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
48
- \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
49
- \newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
50
- \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
51
- \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
52
- \newcommand{\ImportTok}[1]{#1}
53
56
  \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
54
- \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
55
- \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
56
57
  \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
57
- \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
58
- \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
59
- \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
58
+ \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
60
59
  \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
61
- \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
62
- \newcommand{\BuiltInTok}[1]{#1}
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}}}
63
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}}
64
73
  \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
65
- \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
66
74
  \newcommand{\RegionMarkerTok}[1]{#1}
67
- \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#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}}
68
80
  \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
69
- \newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
70
- \newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
71
- \newcommand{\NormalTok}[1]{#1}
72
- \usepackage{longtable,booktabs}
73
- \usepackage{graphicx,grffile}
81
+ \usepackage{longtable,booktabs,array}
82
+ \newcounter{none} % for unnumbered tables
83
+ \usepackage{calc} % for calculating minipage widths
84
+ % Correct order of tables after \paragraph or \subparagraph
85
+ \usepackage{etoolbox}
74
86
  \makeatletter
75
- \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
76
- \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
87
+ \patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
77
88
  \makeatother
78
- % Scale images if necessary, so that they will not overflow the page
79
- % margins by default, and it is still possible to overwrite the defaults
80
- % using explicit options in \includegraphics[width, height, ...]{}
81
- \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
82
- \IfFileExists{parskip.sty}{%
83
- \usepackage{parskip}
84
- }{% else
85
- \setlength{\parindent}{0pt}
86
- \setlength{\parskip}{6pt plus 2pt minus 1pt}
89
+ % Allow footnotes in longtable head/foot
90
+ \IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
91
+ \makesavenoteenv{longtable}
92
+ \usepackage{graphicx}
93
+ \makeatletter
94
+ \newsavebox\pandoc@box
95
+ \newcommand*\pandocbounded[1]{% scales image to fit in text height/width
96
+ \sbox\pandoc@box{#1}%
97
+ \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
98
+ \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
99
+ \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
100
+ \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
101
+ \else\usebox{\pandoc@box}%
102
+ \fi%
87
103
  }
88
- \setlength{\emergencystretch}{3em} % prevent overfull lines
104
+ % Set default figure placement to htbp
105
+ \def\fps@figure{htbp}
106
+ \makeatother
107
+ % definitions for citeproc citations
108
+ \NewDocumentCommand\citeproctext{}{}
109
+ \NewDocumentCommand\citeproc{mm}{%
110
+ \begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
111
+ \makeatletter
112
+ % allow citations to break across lines
113
+ \let\@cite@ofmt\@firstofone
114
+ % avoid brackets around text for \cite:
115
+ \def\@biblabel#1{}
116
+ \def\@cite#1#2{{#1\if@tempswa , #2\fi}}
117
+ \makeatother
118
+ \newlength{\cslhangindent}
119
+ \setlength{\cslhangindent}{1.5em}
120
+ \newlength{\csllabelwidth}
121
+ \setlength{\csllabelwidth}{3em}
122
+ \newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
123
+ {\begin{list}{}{%
124
+ \setlength{\itemindent}{0pt}
125
+ \setlength{\leftmargin}{0pt}
126
+ \setlength{\parsep}{0pt}
127
+ % turn on hanging indent if param 1 is 1
128
+ \ifodd #1
129
+ \setlength{\leftmargin}{\cslhangindent}
130
+ \setlength{\itemindent}{-1\cslhangindent}
131
+ \fi
132
+ % set entry spacing
133
+ \setlength{\itemsep}{#2\baselineskip}}}
134
+ {\end{list}}
135
+ \usepackage{calc}
136
+ \newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
137
+ \newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
138
+ \newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{\strut#1\strut}}
139
+ \newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
140
+ \setlength{\emergencystretch}{3em} % prevent overfull lines
89
141
  \providecommand{\tightlist}{%
90
142
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
91
- \setcounter{secnumdepth}{5}
92
- % Redefines (sub)paragraphs to behave more like sections
93
- \ifx\paragraph\undefined\else
94
- \let\oldparagraph\paragraph
95
- \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
96
- \fi
97
- \ifx\subparagraph\undefined\else
98
- \let\oldsubparagraph\subparagraph
99
- \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
100
- \fi
101
-
102
- %%% Use protect on footnotes to avoid problems with footnotes in titles
103
- \let\rmarkdownfootnote\footnote%
104
- \def\footnote{\protect\rmarkdownfootnote}
105
-
106
- %%% Change title format to be more compact
107
- \usepackage{titling}
108
-
109
- % Create subtitle command for use in maketitle
110
- \newcommand{\subtitle}[1]{
111
- \posttitle{
112
- \begin{center}\large#1\end{center}
113
- }
114
- }
115
-
116
- \setlength{\droptitle}{-2em}
117
-
118
- \title{Galaaz Manual}
119
- \pretitle{\vspace{\droptitle}\centering\huge}
120
- \posttitle{\par}
121
- \subtitle{How to tightly couple Ruby and R in GraalVM}
122
- \author{Rodrigo Botafogo}
123
- \preauthor{\centering\large\emph}
124
- \postauthor{\par}
125
- \predate{\centering\large\emph}
126
- \postdate{\par}
127
- \date{2019}
128
-
129
143
  % usar portugues do Brasil
130
144
  % \usepackage[brazilian]{babel}
131
145
  \usepackage[utf8]{inputenc}
@@ -211,6 +225,25 @@
211
225
  \usepackage[normalem]{ulem}
212
226
  \usepackage{makecell}
213
227
  \usepackage{xcolor}
228
+ \usepackage{bookmark}
229
+ \IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
230
+ \urlstyle{same}
231
+ \hypersetup{
232
+ pdftitle={Galaaz Manual},
233
+ pdfauthor={Rodrigo Botafogo},
234
+ hidelinks,
235
+ pdfcreator={LaTeX via pandoc}}
236
+
237
+ \title{Galaaz Manual}
238
+ \usepackage{etoolbox}
239
+ \makeatletter
240
+ \providecommand{\subtitle}[1]{% add subtitle to \maketitle
241
+ \apptocmd{\@title}{\par {\large #1 \par}}{}{}
242
+ }
243
+ \makeatother
244
+ \subtitle{Coupling Ruby (JRuby) and GNU R for data science}
245
+ \author{Rodrigo Botafogo}
246
+ \date{2026}
214
247
 
215
248
  \begin{document}
216
249
  \maketitle
@@ -226,8 +259,10 @@ language, with a large community, a very large set of libraries and
226
259
  great for web development. However, it lacks libraries for data science,
227
260
  statistics, scientific plotting and machine learning. On the other hand,
228
261
  R is considered one of the most powerful languages for solving all of
229
- the above problems. Maybe the strongest competitor to R is Python with
230
- libraries such as NumPy, Panda, SciPy, SciKit-Learn and a couple more.
262
+ the above problems. \textbf{Python} is a strong competitor: NumPy,
263
+ pandas, SciPy, and scikit-learn are widely used building blocks, and
264
+ \textbf{PyPI} hosts many thousands of other packages for numerical work,
265
+ machine learning, and beyond.
231
266
 
232
267
  With Galaaz we do not intend to re-implement any of the scientific
233
268
  libraries in R, we allow for very tight coupling between the two
@@ -236,77 +271,52 @@ that there is an R engine running.
236
271
 
237
272
  According to Wikipedia ``Ruby is a dynamic, interpreted, reflective,
238
273
  object-oriented, general-purpose programming language. It was designed
239
- and developed in the mid-1990s by Yukihiro''Matz" Matsumoto in Japan."
274
+ and developed in the mid-1990s by Yukihiro''Matz'' Matsumoto in Japan.''
240
275
  It reached high popularity with the development of Ruby on Rails (RoR)
241
276
  by David Heinemeier Hansson. RoR is a web application framework first
242
277
  released around 2005. It makes extensive use of Ruby's metaprogramming
243
278
  features. With RoR, Ruby became very popular. According to
244
- \href{https://www.tiobe.com/tiobe-index/ruby/}{Ruby's Tiobe index} it
245
- peeked in popularity around 2008, then declined until 2015 when it
246
- started picking up again. At the time of this writing (November 2018),
247
- the Tiobe index puts Ruby in 16th position as most popular language.
279
+ \href{https://www.tiobe.com/tiobe-index/ruby/}{Ruby's place in the TIOBE
280
+ index} it peaked in popularity around 2008, then declined until 2015
281
+ when it started picking up again. Ruby remains a significant language in
282
+ web development and general-purpose scripting.
248
283
 
249
284
  Python, a language similar to Ruby, ranks 4th in the index. Java, C and
250
285
  C++ take the first three positions. Ruby is often criticized for its
251
286
  focus on web applications. But Ruby can do
252
287
  \href{https://github.com/markets/awesome-ruby}{much more} than just web
253
- applications. Yet, for scientific computing, Ruby lags way behind Python
254
- and R. Python has Django framework for web, NumPy for numerical arrays,
255
- Pandas for data analysis. R is a free software environment for
256
- statistical computing and graphics with thousands of libraries for data
257
- analysis.
288
+ applications. Yet, for scientific computing, Ruby lags behind Python and
289
+ R. Python offers Django and similar frameworks for the web, plus NumPy,
290
+ pandas, and a deep catalog of science and ML libraries. R is a free
291
+ software environment for statistical computing and graphics with
292
+ thousands of libraries for data analysis.
258
293
 
259
294
  Until recently, there was no real perspective for Ruby to bridge this
260
295
  gap. Implementing a complete scientific computing infrastructure would
261
- take too long. Enters \href{https://www.graalvm.org/}{Oracle's GraalVM}:
262
-
263
- \begin{quote}
264
- GraalVM is a universal virtual machine for running applications written
265
- in JavaScript, Python 3, Ruby, R, JVM-based languages like Java, Scala,
266
- Kotlin, and LLVM-based languages such as C and C++.
267
-
268
- GraalVM removes the isolation between programming languages and enables
269
- interoperability in a shared runtime. It can run either standalone or in
270
- the context of OpenJDK, Node.js, Oracle Database, or MySQL.
271
-
272
- GraalVM allows you to write polyglot applications with a seamless way to
273
- pass values from one language to another. With GraalVM there is no
274
- copying or marshaling necessary as it is with other polyglot systems.
275
- This lets you achieve high performance when language boundaries are
276
- crossed. Most of the time there is no additional cost for crossing a
277
- language boundary at all.
278
-
279
- Often developers have to make uncomfortable compromises that require
280
- them to rewrite their software in other languages. For example:
281
-
282
- \begin{itemize}
283
- \tightlist
284
- \item
285
- That library is not available in my language. I need to rewrite it.
286
- \item
287
- That language would be the perfect fit for my problem, but we cannot
288
- run it in our environment.
289
- \item
290
- That problem is already solved in my language, but the language is too
291
- slow.
292
- \end{itemize}
293
-
294
- With GraalVM we aim to allow developers to freely choose the right
295
- language for the task at hand without making compromises.
296
- \end{quote}
297
-
298
- As stated above, GraalVM is a \emph{universal} virtual machine that
299
- allows Ruby and R (and other languages) to run on the same environment.
300
- GraalVM allows polyglot applications to \emph{seamlessly} interact with
301
- one another and pass values from one language to the other. Although a
302
- great idea, GraalVM still requires application writers to know several
303
- languages. To eliminate that requirement, we built Galaaz, a gem for
304
- Ruby, to tightly couple Ruby and R and allow those languages to interact
305
- in a way that the user will be unaware of such interaction. In other
306
- words, a Ruby programmer will be able to use all the capabilities of R
307
- without knowing the R syntax.
308
-
309
- Library wrapping is a usual way of bringing features from one language
296
+ take too long.
297
+
298
+ \textbf{Galaaz 2.0} couples \textbf{JRuby} (Ruby on the JVM) with
299
+ \textbf{GNU R}---the same R you use for CRAN and Bioconductor. Ruby and
300
+ R run in \textbf{separate processes}; the \textbf{Galaaz bridge} sends
301
+ requests to R and returns results to Ruby. From your point of view you
302
+ still write Ruby: \texttt{R.c(...)},
303
+ \texttt{R.library(\textquotesingle{}ggplot2\textquotesingle{})},
304
+ \texttt{\textasciitilde{}:mtcars}, and dplyr-style chains on R objects.
305
+ You do not need to learn R syntax to get a lot done, though reading R
306
+ documentation for individual packages remains useful.
307
+
308
+ Earlier experiments with Galaaz used Oracle's \textbf{GraalVM} with
309
+ TruffleRuby and FastR so that Ruby and R could share one runtime. That
310
+ path is no longer the focus: \textbf{standard GNU R} gives full
311
+ compatibility with the R package ecosystem (including compiled
312
+ extensions and Bioconductor) while JRuby gives a mature Ruby with
313
+ \textbf{real multithreading} for application and I/O code.
314
+
315
+ The bridge handles \textbf{communication and typing} between the two
316
+ worlds; large tables can also flow through \textbf{Apache Arrow} on the
317
+ R side when you use the optional helpers described later in this manual.
318
+
319
+ Library wrapping is a common way to bring features from one language
310
320
  into another. To improve performance, Python often wraps more efficient
311
321
  C libraries. For the Python developer, the existence of such C libraries
312
322
  is hidden. The problem with library wrapping is that for any new
@@ -333,65 +343,314 @@ His name should not be mistaken with Galehaut, a different knight from
333
343
  Arthurian legend.
334
344
  \end{verbatim}
335
345
 
346
+ \section{\texorpdfstring{Command-line tools
347
+ (\texttt{bin/})}{Command-line tools (bin/)}}\label{command-line-tools-bin}
348
+
349
+ The Galaaz repository ships many helpers under \textbf{\texttt{bin/}}.
350
+ When working from a \textbf{clone}, call them as
351
+ \textbf{\texttt{bin/\textless{}name\textgreater{}}} from the project
352
+ root (or \texttt{./bin/\textless{}name\textgreater{}}). If you install
353
+ the \textbf{gem}, only a subset is guaranteed on your \texttt{PATH} (see
354
+ the gemspec: \textbf{\texttt{galaaz}}, \textbf{\texttt{gstudio}},
355
+ \textbf{\texttt{gknit}}, \textbf{\texttt{grun}},
356
+ \textbf{\texttt{gknit-draft}}); for development and CI, prefer the
357
+ \textbf{\texttt{bin/}} copies so JVM flags and paths stay correct.
358
+
359
+ Below, \textbf{current (Galaaz 2.0 + JRuby + GNU R)} means the tool is
360
+ wired to \textbf{\texttt{jruby}} and
361
+ \textbf{\texttt{bin/galaaz\_jruby\_env.inc.sh}} (or equivalent logic in
362
+ Ruby via \texttt{lib/galaaz\_jruby.rb}). \textbf{Legacy} means the
363
+ script still targets \textbf{GraalVM} polyglot Ruby / FastR-era
364
+ invocation and is \textbf{not} expected to work on a typical JRuby-only
365
+ setup.
366
+
367
+ \textbf{Table layout:} names in the first column are
368
+ \textbf{\texttt{bin/}} filenames (run as
369
+ \texttt{bin/\textless{}name\textgreater{}} from the repo root). Long
370
+ options and examples sit \textbf{outside} the tables so PDF columns stay
371
+ readable.
372
+
373
+ \begin{verbatim}
374
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
375
+ ## resized.
376
+ \end{verbatim}
377
+
378
+ \begingroup\fontsize{9}{11}\selectfont
379
+
380
+ \begin{longtable}[t]{>{\raggedright\arraybackslash}p{2.5cm}>{\raggedright\arraybackslash}p{9.5cm}>{\raggedright\arraybackslash}p{2.8cm}}
381
+ \toprule
382
+ Script & Role & 2.0?\\
383
+ \midrule
384
+ galaaz-bootstrap & WSL2 helper: Docker checks; optional TinyTeX or poppler for gKnit PDF. & Yes*\\
385
+ galaaz-jruby & JRuby with repo lib/ on LOAD\_PATH and required JVM flags (e.g. Arrow). & Yes\\
386
+ galaaz\_jruby\_env.inc.sh & Sourced by bash wrappers; sets GALAAZ\_REQUIRED\_JRUBY\_J\_ARGS. & Yes†\\
387
+ install-tinytex & Install TinyTeX for PDF output. & Yes\\
388
+ \bottomrule
389
+ \end{longtable}
390
+ \endgroup{}
391
+
392
+ * Where WSL/Docker apply. \textbf{\texttt{galaaz-bootstrap} flags:}
393
+ \texttt{-\/-check}, \texttt{-\/-apply}, \texttt{-\/-runtime}
394
+ (\texttt{docker} \textbar{} \texttt{local} \textbar{} \texttt{auto}),
395
+ \texttt{-\/-{[}no-{]}prompt-doc-tools}.
396
+
397
+ † Not run directly.
398
+
399
+ \textbf{\texttt{galaaz-jruby} examples} (from repo root):
400
+
401
+ \begin{Shaded}
402
+ \begin{Highlighting}[]
403
+ \NormalTok{bin/galaaz{-}jruby my\_script.rb}
404
+ \NormalTok{bin/galaaz{-}jruby {-}S rspec}
405
+ \end{Highlighting}
406
+ \end{Shaded}
407
+
408
+ \subsection{Interactive use, examples, and
409
+ Rake}\label{interactive-use-examples-and-rake}
410
+
411
+ \begin{verbatim}
412
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
413
+ ## resized.
414
+ \end{verbatim}
415
+
416
+ \begingroup\fontsize{9}{11}\selectfont
417
+
418
+ \begin{longtable}[t]{>{\raggedright\arraybackslash}p{2.5cm}>{\raggedright\arraybackslash}p{9.5cm}>{\raggedright\arraybackslash}p{2.8cm}}
419
+ \toprule
420
+ Script & Role & 2.0?\\
421
+ \midrule
422
+ gstudio & IRB or Pry with Galaaz preloaded (JRuby + JVM flags). & Yes\\
423
+ run\_example & Run one Ruby file using the same JRuby/JVM setup as tests. & Yes\\
424
+ galaaz & Forward arguments to rake (needs rake; usually JRuby). & Yes\\
425
+ \bottomrule
426
+ \end{longtable}
427
+ \endgroup{}
428
+
429
+ \subsection{gKnit and document drafts}\label{gknit-and-document-drafts}
430
+
431
+ \begin{verbatim}
432
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
433
+ ## resized.
434
+ \end{verbatim}
435
+
436
+ \begingroup\fontsize{9}{11}\selectfont
437
+
438
+ \begin{longtable}[t]{>{\raggedright\arraybackslash}p{2.5cm}>{\raggedright\arraybackslash}p{9.5cm}>{\raggedright\arraybackslash}p{2.8cm}}
439
+ \toprule
440
+ Script & Role & 2.0?\\
441
+ \midrule
442
+ gknit & Knit .Rmd via JRuby and R Markdown render. & Yes\\
443
+ gknit-draft & Drafts from rticles-style templates; wrapper still uses legacy polyglot ruby. & Legacy\\
444
+ gknit-draft.rb & Ruby entry: GKnit.draft (use with JRuby + LOAD\_PATH). & JRuby\\
445
+ gknit\_Rscript & Polyglot Rscript launcher; hard-coded LOAD\_PATH sample. & No\\
446
+ \bottomrule
447
+ \end{longtable}
448
+ \endgroup{}
449
+
450
+ \textbf{\texttt{gknit} CLI} (see \texttt{gknit\ -h}):
451
+ \texttt{-\/-output\_format}, \texttt{-\/-output\_file},
452
+ \texttt{-\/-output\_dir}, \texttt{-\/-bridge\_timeout\_sec},
453
+ \texttt{-\/-callback\_timeout\_ms}. If \texttt{-\/-output\_format} is
454
+ omitted, the \textbf{first} YAML \texttt{output:} target wins.
455
+
456
+ Prefer \textbf{\texttt{galaaz-jruby}} for \textbf{\texttt{gknit-draft}}
457
+ workflows until that wrapper matches the \textbf{\texttt{gknit}} stack.
458
+
459
+ \subsection{Tests}\label{tests}
460
+
461
+ \begin{verbatim}
462
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
463
+ ## resized.
464
+ \end{verbatim}
465
+
466
+ \begingroup\fontsize{9}{11}\selectfont
467
+
468
+ \begin{longtable}[t]{>{\raggedright\arraybackslash}p{2.5cm}>{\raggedright\arraybackslash}p{9.5cm}>{\raggedright\arraybackslash}p{2.8cm}}
469
+ \toprule
470
+ Script & Role & 2.0?\\
471
+ \midrule
472
+ run\_rspec & Top-level specs/*\_spec.rb with spec\_helper (see docs/testing.md). & Yes\\
473
+ run\_all\_rspec & Compile ext/new\_bridge; run specs/ and new\_bridge\_specs/ together. & Yes\\
474
+ run\_slow\_rspec & Suites under slow-specs/ (read script header for spec\_helper). & Yes\\
475
+ run\_old\_rspec & Legacy suites under old\_specs/. & Yes\\
476
+ run\_rspec\_subset & Numbered subset 1–18 (Documentation/Spec\_Subsets.md). & Yes\\
477
+ \bottomrule
478
+ \end{longtable}
479
+ \endgroup{}
480
+
481
+ \subsection{Other}\label{other}
482
+
483
+ \begin{verbatim}
484
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
485
+ ## resized.
486
+ \end{verbatim}
487
+
488
+ \begingroup\fontsize{9}{11}\selectfont
489
+
490
+ \begin{longtable}[t]{>{\raggedright\arraybackslash}p{2.5cm}>{\raggedright\arraybackslash}p{9.5cm}>{\raggedright\arraybackslash}p{2.8cm}}
491
+ \toprule
492
+ Script & Role & 2.0?\\
493
+ \midrule
494
+ grun & Graal-era launcher: polyglot ruby with --jvm. Use galaaz-jruby -S instead. & No\\
495
+ gstudio\_irb.rb / gstudio\_pry.rb & Loaded by gstudio; not meant to be run standalone. & Yes\\
496
+ \bottomrule
497
+ \end{longtable}
498
+ \endgroup{}
499
+
500
+ For day-to-day \textbf{2.0} use, rely on
501
+ \textbf{\texttt{bin/galaaz-jruby}}, \textbf{\texttt{bin/gstudio}},
502
+ \textbf{\texttt{bin/gknit}}, \textbf{\texttt{bin/run\_example}},
503
+ \textbf{\texttt{bin/run\_rspec}} /
504
+ \textbf{\texttt{bin/run\_all\_rspec}}, and
505
+ \textbf{\texttt{bin/galaaz-bootstrap}} on WSL when using Dockerized R.
506
+ Treat \textbf{\texttt{grun}}, \textbf{\texttt{gknit\_Rscript}}, and the
507
+ polyglot \textbf{\texttt{ruby}} invocation in
508
+ \textbf{\texttt{gknit-draft}} as \textbf{legacy} until they are ported
509
+ to the same JRuby path as \textbf{\texttt{gknit}}.
510
+
336
511
  \section{System Compatibility}\label{system-compatibility}
337
512
 
513
+ Typical development and CI targets:
514
+
338
515
  \begin{itemize}
339
516
  \tightlist
340
517
  \item
341
- Oracle Linux 7
342
- \item
343
- Ubuntu 18.04 LTS
518
+ \textbf{Linux} --- recent Ubuntu LTS or comparable distributions
519
+ (x86\_64).
344
520
  \item
345
- Ubuntu 16.04 LTS
521
+ \textbf{macOS} --- recent releases with JRuby and GNU R available.
346
522
  \item
347
- Fedora 28
348
- \item
349
- macOS 10.14 (Mojave)
350
- \item
351
- macOS 10.13 (High Sierra)
523
+ \textbf{Windows} --- use \textbf{WSL2} (same Linux stack as above);
524
+ native Windows is not the primary target.
352
525
  \end{itemize}
353
526
 
527
+ The native \textbf{gatekeeper} component under \texttt{ext/new\_bridge}
528
+ is built with \texttt{make} and a C++ toolchain; see the project
529
+ \texttt{README} if compilation fails on your platform.
530
+
354
531
  \section{Dependencies}\label{dependencies}
355
532
 
356
533
  \begin{itemize}
357
534
  \tightlist
358
535
  \item
359
- TruffleRuby
536
+ \textbf{JRuby} --- Ruby implementation on the JVM (Galaaz 2.0 is
537
+ developed and tested with JRuby).
538
+ \item
539
+ A \textbf{Java runtime} (JDK) compatible with your JRuby version.
540
+ \item
541
+ \textbf{GNU R} --- \texttt{R} on your \texttt{PATH}, with ability to
542
+ install packages (CRAN / Bioconductor as needed).
543
+ \item
544
+ \textbf{Ruby gems} --- from the Galaaz repository,
545
+ \texttt{bundle\ install} (see the \texttt{Gemfile} / gemspec).
360
546
  \item
361
- FastR
547
+ Optional: \textbf{Docker} --- if you run R in a container (common on
548
+ WSL2); see bootstrap below.
549
+ \item
550
+ Optional R packages for examples in this manual ---
551
+ e.g.~\texttt{ggplot2}, \texttt{dplyr}, \texttt{knitr},
552
+ \texttt{kableExtra}, \texttt{arrow}, Bioconductor tools such as
553
+ \textbf{DESeq2} (installed the usual R way).
362
554
  \end{itemize}
363
555
 
364
556
  \section{Installation}\label{installation}
365
557
 
366
- \begin{itemize}
558
+ From a clone of the Galaaz repository:
559
+
560
+ \begin{enumerate}
561
+ \def\labelenumi{\arabic{enumi}.}
367
562
  \tightlist
368
563
  \item
369
- Install GrallVM (\url{http://www.graalvm.org/})
564
+ Install \textbf{JRuby} and \textbf{GNU R} using your preferred package
565
+ manager or Ruby version manager.
370
566
  \item
371
- Install Ruby (gu install Ruby)
567
+ Install \textbf{bundler} if needed, then run
568
+ \textbf{\texttt{bundle\ install}} in the repository root.
372
569
  \item
373
- Install FastR (gu install R)
570
+ Build the bridge native code:
571
+ \textbf{\texttt{make\ -C\ ext/new\_bridge\ all}} (or
572
+ \textbf{\texttt{rake\ compile\_gatekeeper}}).
374
573
  \item
375
- Install rake if you want to run the specs and examples (gem install
376
- rake)
377
- \end{itemize}
574
+ Run Ruby scripts with the project load path and JVM flags the project
575
+ expects --- the \textbf{\texttt{bin/galaaz-jruby}} wrapper sources
576
+ \textbf{\texttt{bin/galaaz\_jruby\_env.inc.sh}} and adds
577
+ \textbf{\texttt{-I\ lib}}. This matters especially for \textbf{Apache
578
+ Arrow} integration (see \texttt{docs/testing.md}).
579
+ \item
580
+ Ensure \textbf{\texttt{R}} starts GNU R and can install packages
581
+ (network access to CRAN mirrors when you first call
582
+ \texttt{R.install\_and\_loads}).
583
+ \end{enumerate}
378
584
 
379
- \section{Usage}\label{usage}
585
+ For \textbf{gKnit}, \textbf{knitr}, \textbf{rmarkdown}, and LaTeX (PDF
586
+ output), install the corresponding R packages and a TeX distribution if
587
+ you need PDF; the repository includes helpers such as
588
+ \textbf{\texttt{bin/install-tinytex}} where appropriate.
380
589
 
381
- \begin{itemize}
590
+ A \textbf{table of all \texttt{bin/} scripts} (bootstrap, JRuby wrapper,
591
+ gstudio, gknit, test runners, and which ones are legacy) is in the
592
+ section \textbf{Command-line tools (\texttt{bin/})} earlier in this
593
+ manual.
594
+
595
+ \subsection{Windows + WSL2 (optional: Docker / R in a
596
+ container)}\label{windows-wsl2-optional-docker-r-in-a-container}
597
+
598
+ If you run Galaaz on Windows through WSL2 and want containerized R
599
+ instances, Docker Desktop is the supported setup.
600
+
601
+ \begin{enumerate}
602
+ \def\labelenumi{\arabic{enumi}.}
382
603
  \tightlist
383
604
  \item
384
- Interactive shell: use `gstudio' on the command line
385
- \end{itemize}
605
+ Install Docker Desktop on Windows:
606
+
607
+ \begin{itemize}
608
+ \tightlist
609
+ \item
610
+ \url{https://www.docker.com/products/docker-desktop/}
611
+ \end{itemize}
612
+ \item
613
+ Open Docker Desktop and enable WSL integration:
614
+
615
+ \begin{itemize}
616
+ \tightlist
617
+ \item
618
+ Settings \textgreater{} Resources \textgreater{} WSL Integration
619
+ \item
620
+ Enable integration for your target distro
621
+ \item
622
+ Apply \& Restart Docker Desktop
623
+ \end{itemize}
624
+ \item
625
+ In WSL, run Galaaz bootstrap:
626
+ \end{enumerate}
386
627
 
387
628
  \begin{quote}
388
- gstudio
629
+ ruby bin/galaaz-bootstrap --apply ruby bin/galaaz-bootstrap --check
389
630
  \end{quote}
390
631
 
632
+ Expected result: - docker CLI available - docker compose available -
633
+ docker daemon reachable (\texttt{docker\ info} works)
634
+
635
+ If bootstrap reports daemon is unreachable, check Docker Desktop is
636
+ running and WSL integration is enabled for the distro where Galaaz is
637
+ installed.
638
+
639
+ \section{Usage}\label{usage}
640
+
641
+ \begin{itemize}
642
+ \item
643
+ Interactive shell: use `gstudio' on the command line
644
+
645
+ \begin{quote}
646
+ gstudio
647
+ \end{quote}
648
+ \end{itemize}
649
+
391
650
  \begin{Shaded}
392
651
  \begin{Highlighting}[]
393
- \NormalTok{ vec = R.c(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{)}
394
- \NormalTok{ puts vec}
652
+ \NormalTok{ vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{)}
653
+ \FunctionTok{puts}\NormalTok{ vec}
395
654
  \end{Highlighting}
396
655
  \end{Shaded}
397
656
 
@@ -400,68 +659,182 @@ gstudio
400
659
  \end{verbatim}
401
660
 
402
661
  \begin{itemize}
403
- \tightlist
404
662
  \item
405
663
  Run all specs
406
- \end{itemize}
407
664
 
408
- \begin{quote}
409
- galaaz specs:all
410
- \end{quote}
411
-
412
- \begin{itemize}
413
- \tightlist
665
+ \begin{quote}
666
+ galaaz specs:all
667
+ \end{quote}
414
668
  \item
415
669
  Run graphics slideshow (80+ graphics)
670
+
671
+ \begin{quote}
672
+ galaaz sthda:all
673
+ \end{quote}
674
+ \item
675
+ Run labs from Introduction to Statistical Learning with R
676
+
677
+ \begin{quote}
678
+ galaaz islr:all
679
+ \end{quote}
680
+ \item
681
+ See all available examples
682
+
683
+ \begin{quote}
684
+ galaaz -T
685
+ \end{quote}
686
+
687
+ Shows a list with all available executable tasks. To execute a task,
688
+ substitute the `rake' word in the list with `galaaz'. For instance,
689
+ the following line shows up after `galaaz -T'
690
+
691
+ rake master\_list:scatter\_plot \# scatter\_plot from:\ldots.
692
+
693
+ execute
694
+
695
+ \begin{quote}
696
+ galaaz master\_list:scatter\_plot
697
+ \end{quote}
416
698
  \end{itemize}
417
699
 
418
- \begin{quote}
419
- galaaz sthda:all
420
- \end{quote}
700
+ \section{JRuby, multithreading, and the R
701
+ bridge}\label{jruby-multithreading-and-the-r-bridge}
421
702
 
422
- \begin{itemize}
703
+ Galaaz 2.0 runs Ruby on \textbf{JRuby}, so your application can use
704
+ \textbf{real parallel threads} for I/O-bound work (HTTP clients,
705
+ database connections, message consumers, and so on). R itself is still
706
+ executed in a \textbf{single GNU R process} behind the Galaaz bridge.
707
+
708
+ When several Ruby threads call into R at the same time, the bridge
709
+ \textbf{serializes} those calls: each request is matched to a reply
710
+ using an internal per-call \textbf{queue}, so you do not need to add
711
+ your own mutex around every \texttt{R.foo} from application threads.
712
+ (You should still use normal Ruby synchronization when \textbf{Ruby}
713
+ data structures are shared between threads---for example, when appending
714
+ rows from each thread into a shared array before sending them to R.)
715
+
716
+ A practical pattern is:
717
+
718
+ \begin{enumerate}
719
+ \def\labelenumi{\arabic{enumi}.}
423
720
  \tightlist
424
721
  \item
425
- Run labs from Introduction to Statistical Learning with R
426
- \end{itemize}
722
+ Use threads (or a connection pool) to read from \textbf{multiple
723
+ databases or shards} in parallel.
724
+ \item
725
+ Merge the rows in Ruby under a \texttt{Mutex} if you collect into one
726
+ structure.
727
+ \item
728
+ Hand the merged table to R \textbf{once} (for example with
729
+ \texttt{R::Arrow.from\_ruby\_batches} and dplyr, or by building a data
730
+ frame) so heavy statistics run in R with fewer bridge round-trips.
731
+ \end{enumerate}
427
732
 
428
- \begin{quote}
429
- galaaz islr:all
430
- \end{quote}
733
+ A runnable sketch lives in
734
+ \texttt{examples/multithread\_shards\_to\_r/shards\_to\_r.rb} (simulated
735
+ shard queries; swap in your DB driver). For concurrency tests on the
736
+ bridge itself, see \texttt{specs/bridge\_concurrent\_spec.rb} and
737
+ \texttt{specs/arrow\_from\_ruby\_batches\_spec.rb}.
738
+
739
+ \subsection{Long-running R calls and a completion
740
+ block}\label{long-running-r-calls-and-a-completion-block}
741
+
742
+ For R work that can take a long time, the bridge can avoid a Ruby-side
743
+ \textbf{wait timeout} by scheduling the call and resuming in a
744
+ \textbf{block} when the \texttt{RET} arrives.
431
745
 
432
746
  \begin{itemize}
433
747
  \tightlist
434
748
  \item
435
- See all available examples
749
+ \textbf{\texttt{R.eval\_r\_async(code,\ timeout:\ nil)\ \{\ \textbar{}result\textbar{}\ ...\ \}}}
750
+ --- string eval; on success, \texttt{result.value} is the same
751
+ formatted string as \textbf{\texttt{R.eval\_r}} (use
752
+ \texttt{timeout:\ nil} for no Ruby-side limit).
753
+ \item
754
+ \textbf{\texttt{R::Async.\textless{}rname\textgreater{}(...)\ \{\ \textbar{}result\textbar{}\ ...\ \}}}
755
+ --- same dispatch as
756
+ \textbf{\texttt{R.\textless{}rname\textgreater{}(...)}}, but async; on
757
+ success, \texttt{result.value} is an \textbf{\texttt{R::Object}} (or
758
+ unboxed Ruby value / Symbol), like synchronous
759
+ \textbf{\texttt{R.\textless{}rname\textgreater{}}}. Optional keyword
760
+ \textbf{\texttt{timeout:}} applies a Ruby-side wait limit (completion
761
+ receives \textbf{\texttt{NewBridge::SessionClient::TimeoutError}} if R
762
+ is too slow).
436
763
  \end{itemize}
437
764
 
438
- \begin{quote}
439
- galaaz -T
440
- \end{quote}
441
-
442
- Shows a list with all available executalbe tasks. To execute a task,
443
- substitute the `rake' word in the list with `galaaz'. For instance, the
444
- following line shows up after `galaaz -T'
765
+ \textbf{Important:}
766
+ \textbf{\texttt{R.foo(...)\ \{\ \textbar{}x\textbar{}\ \}}} is already
767
+ used for dplyr-style scopes (\texttt{R::Support.new\_scope}), so async R
768
+ calls must use \textbf{\texttt{R::Async}} or
769
+ \textbf{\texttt{R.eval\_r\_async}}, not a bare \textbf{\texttt{R.foo}
770
+ with a block.}
771
+
772
+ \texttt{NewBridge::EvalResult} exposes \textbf{\texttt{\#ok?}},
773
+ \textbf{\texttt{\#value}}, and \textbf{\texttt{\#error}}. The completion
774
+ block runs on a \textbf{background thread} (not the bridge reader
775
+ thread).
776
+
777
+ The example below is \textbf{plain Ruby} (no Rails). The R snippet
778
+ sleeps (standing in for heavy work) and then returns an integer so the
779
+ success branch shows a \textbf{non-nil} value. (\texttt{Sys.sleep} alone
780
+ returns \textbf{NULL} in R; on success \textbf{\texttt{result.value}} is
781
+ then \textbf{\texttt{nil}} in Ruby---that is expected, not a bridge
782
+ error.)
445
783
 
446
- rake master\_list:scatter\_plot \# scatter\_plot from:\ldots{}.
784
+ \begin{Shaded}
785
+ \begin{Highlighting}[]
786
+ \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}thread\textquotesingle{}}
787
+
788
+ \NormalTok{completion }\OperatorTok{=} \DataTypeTok{Queue}\AttributeTok{.new}
789
+
790
+ \ConstantTok{R}\AttributeTok{.eval\_r\_async}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}(\{ Sys.sleep(0.3); 42L \})\textquotesingle{}}\NormalTok{, }\WarningTok{timeout:} \DecValTok{nil}\NormalTok{) }\ControlFlowTok{do} \OperatorTok{|}\NormalTok{result}\OperatorTok{|}
791
+ \ControlFlowTok{if}\NormalTok{ result}\AttributeTok{.ok?}
792
+ \FunctionTok{puts} \StringTok{"[completion] R finished; eval\_r{-}style value: }\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.value.inspect}\SpecialCharTok{\}}\StringTok{"}
793
+ \ControlFlowTok{else}
794
+ \FunctionTok{puts} \StringTok{"[completion] R/bridge error: }\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.error.class}\SpecialCharTok{\}}\StringTok{: }\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.error.message}\SpecialCharTok{\}}\StringTok{"}
795
+ \ControlFlowTok{end}
796
+ \NormalTok{ completion}\AttributeTok{.push}\NormalTok{(}\WarningTok{:done}\NormalTok{)}
797
+ \ControlFlowTok{end}
798
+
799
+ \DecValTok{3}\AttributeTok{.times} \ControlFlowTok{do} \OperatorTok{|}\NormalTok{i}\OperatorTok{|}
800
+ \FunctionTok{puts} \StringTok{"[main] other Ruby work step }\SpecialCharTok{\#\{}\NormalTok{i }\OperatorTok{+} \DecValTok{1}\SpecialCharTok{\}}\StringTok{"}
801
+ \FunctionTok{sleep} \FloatTok{0.05}
802
+ \ControlFlowTok{end}
803
+
804
+ \NormalTok{completion}\AttributeTok{.pop}
805
+ \FunctionTok{puts} \StringTok{"[main] R completion has run; exiting."}
806
+ \end{Highlighting}
807
+ \end{Shaded}
447
808
 
448
- execute
809
+ \begin{verbatim}
810
+ ## [main] other Ruby work step 1
811
+ ## [main] other Ruby work step 2
812
+ ## [main] other Ruby work step 3
813
+ ## [completion] R finished; eval_r-style value: "[1] 42"
814
+ ## [main] R completion has run; exiting.
815
+ \end{verbatim}
449
816
 
450
- \begin{quote}
451
- galaaz master\_list:scatter\_plot
452
- \end{quote}
817
+ In a \textbf{web application}, the HTTP response usually ends before R
818
+ finishes, so you would not \texttt{Queue\#pop} in the controller; you
819
+ would persist an identifier, let the completion block write the outcome
820
+ to storage, and notify the client (poll, WebSocket, Turbo Stream, etc.).
821
+ The plain Ruby pattern above is only to show \textbf{when} the result
822
+ exists (inside the block, or after data written there is observed
823
+ elsewhere). Runnable specs live in
824
+ \textbf{\texttt{new\_bridge\_specs/eval\_r\_async\_spec.rb}}.
453
825
 
454
826
  \section{Accessing R from Ruby}\label{accessing-r-from-ruby}
455
827
 
456
- One of the nice aspects of Galaaz on GraalVM, is that variables and
457
- functions defined in R, can be easily accessed from Ruby. For instance,
458
- to access the `mtcars' data frame from R in Ruby, we use the `:mtcar'
459
- symbol preceded by the `\textasciitilde{}' operator, thus
460
- `\textasciitilde{}:r\_vec' retrieves the value of the `mtcars' variable.
828
+ One of the nice aspects of Galaaz is that variables and functions
829
+ defined in R can be easily accessed from Ruby. For instance, to access
830
+ the \texttt{mtcars} data frame from R in Ruby, we use the symbol
831
+ \texttt{:mtcars} preceded by the \texttt{\textasciitilde{}} operator:
832
+ \texttt{\textasciitilde{}:mtcars} retrieves the value of the
833
+ \texttt{mtcars} object in R.
461
834
 
462
835
  \begin{Shaded}
463
836
  \begin{Highlighting}[]
464
- \NormalTok{puts ~}\StringTok{:mtcars}
837
+ \FunctionTok{puts} \OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}
465
838
  \end{Highlighting}
466
839
  \end{Shaded}
467
840
 
@@ -501,13 +874,13 @@ symbol preceded by the `\textasciitilde{}' operator, thus
501
874
  ## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
502
875
  \end{verbatim}
503
876
 
504
- To access an R function from Ruby, the R function needs to be preceeded
505
- by `R.' scoping. Bellow we see and example of creating a R::Vector by
506
- calling the `c' R function
877
+ To access an R function from Ruby, the R function needs to be preceded
878
+ by \texttt{R.} scoping. Below we see an example of creating a R::Vector
879
+ by calling the `c' R function
507
880
 
508
881
  \begin{Shaded}
509
882
  \begin{Highlighting}[]
510
- \NormalTok{puts vec = R.c(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{, }\FloatTok{4.0}\NormalTok{)}
883
+ \FunctionTok{puts}\NormalTok{ vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{, }\FloatTok{4.0}\NormalTok{)}
511
884
  \end{Highlighting}
512
885
  \end{Shaded}
513
886
 
@@ -519,7 +892,7 @@ Note that `vec' is an object of type R::Vector:
519
892
 
520
893
  \begin{Shaded}
521
894
  \begin{Highlighting}[]
522
- \NormalTok{puts vec.class}
895
+ \FunctionTok{puts}\NormalTok{ vec}\AttributeTok{.class}
523
896
  \end{Highlighting}
524
897
  \end{Shaded}
525
898
 
@@ -534,12 +907,12 @@ R::Object:
534
907
 
535
908
  \begin{Shaded}
536
909
  \begin{Highlighting}[]
537
- \NormalTok{puts vec.rclass}
910
+ \FunctionTok{puts}\NormalTok{ vec}\AttributeTok{.rclass}
538
911
  \end{Highlighting}
539
912
  \end{Shaded}
540
913
 
541
914
  \begin{verbatim}
542
- ## [1] "numeric"
915
+ ## numeric
543
916
  \end{verbatim}
544
917
 
545
918
  When working with R::Object(s), it is possible to use the `.' operator
@@ -552,7 +925,7 @@ size one vector):
552
925
 
553
926
  \begin{Shaded}
554
927
  \begin{Highlighting}[]
555
- \NormalTok{puts R.c(vec, }\DecValTok{10}\NormalTok{, }\DecValTok{20}\NormalTok{, }\DecValTok{30}\NormalTok{)}
928
+ \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(vec, }\DecValTok{10}\NormalTok{, }\DecValTok{20}\NormalTok{, }\DecValTok{30}\NormalTok{)}
556
929
  \end{Highlighting}
557
930
  \end{Shaded}
558
931
 
@@ -564,7 +937,7 @@ The call above to the `c' function can also be done using `.' notation:
564
937
 
565
938
  \begin{Shaded}
566
939
  \begin{Highlighting}[]
567
- \NormalTok{puts vec.c(}\DecValTok{10}\NormalTok{, }\DecValTok{20}\NormalTok{, }\DecValTok{30}\NormalTok{)}
940
+ \FunctionTok{puts}\NormalTok{ vec}\AttributeTok{.c}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{20}\NormalTok{, }\DecValTok{30}\NormalTok{)}
568
941
  \end{Highlighting}
569
942
  \end{Shaded}
570
943
 
@@ -572,12 +945,12 @@ The call above to the `c' function can also be done using `.' notation:
572
945
  ## [1] 1 2 3 4 10 20 30
573
946
  \end{verbatim}
574
947
 
575
- We will talk about vector indexing in a latter section. But notice here
948
+ We will talk about vector indexing in a later section. But notice here
576
949
  that indexing an R::Vector will return another R::Vector:
577
950
 
578
951
  \begin{Shaded}
579
952
  \begin{Highlighting}[]
580
- \NormalTok{puts vec[}\DecValTok{1}\NormalTok{]}
953
+ \FunctionTok{puts}\NormalTok{ vec}\KeywordTok{[}\DecValTok{1}\KeywordTok{]}
581
954
  \end{Highlighting}
582
955
  \end{Shaded}
583
956
 
@@ -587,12 +960,12 @@ that indexing an R::Vector will return another R::Vector:
587
960
 
588
961
  Sometimes we want to index an R::Object and get back a Ruby object that
589
962
  is not wrapped in an R::Object, but the native Ruby object. For this, we
590
- can index the R object with the `\textgreater{}\textgreater{}' operator:
963
+ can index the R object with the `\textgreater\textgreater{}' operator:
591
964
 
592
965
  \begin{Shaded}
593
966
  \begin{Highlighting}[]
594
- \NormalTok{puts vec >> }\DecValTok{0}
595
- \NormalTok{puts vec >> }\DecValTok{2}
967
+ \FunctionTok{puts}\NormalTok{ vec }\OperatorTok{\textgreater{}\textgreater{}} \DecValTok{0}
968
+ \FunctionTok{puts}\NormalTok{ vec }\OperatorTok{\textgreater{}\textgreater{}} \DecValTok{2}
596
969
  \end{Highlighting}
597
970
  \end{Shaded}
598
971
 
@@ -607,7 +980,7 @@ here is an example of creating a `list' with named elements:
607
980
 
608
981
  \begin{Shaded}
609
982
  \begin{Highlighting}[]
610
- \NormalTok{puts R.list(}\StringTok{first_name: "Rodrigo"}\NormalTok{, }\StringTok{last_name: "Botafogo"}\NormalTok{)}
983
+ \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.list}\NormalTok{(}\WarningTok{first\_name:} \StringTok{"Rodrigo"}\NormalTok{, }\WarningTok{last\_name:} \StringTok{"Botafogo"}\NormalTok{)}
611
984
  \end{Highlighting}
612
985
  \end{Shaded}
613
986
 
@@ -627,26 +1000,23 @@ element of our previously created vector:
627
1000
 
628
1001
  \begin{Shaded}
629
1002
  \begin{Highlighting}[]
630
- \NormalTok{puts vec.map \{ |x| x + }\DecValTok{2}\NormalTok{ \}}
1003
+ \FunctionTok{puts}\NormalTok{ vec}\AttributeTok{.map} \OperatorTok{\{} \OperatorTok{|}\NormalTok{x}\OperatorTok{|}\NormalTok{ x }\OperatorTok{+} \DecValTok{2} \OperatorTok{\}}
631
1004
  \end{Highlighting}
632
1005
  \end{Shaded}
633
1006
 
634
1007
  \begin{verbatim}
635
- ## [1] 3
636
- ## [1] 4
637
- ## [1] 5
638
- ## [1] 6
1008
+ ## [1] 3 4 5 6
639
1009
  \end{verbatim}
640
1010
 
641
1011
  \section{gKnitting a Document}\label{gknitting-a-document}
642
1012
 
643
- This manual has been formatted usign gKnit. gKnit uses Knitr and R
644
- markdown to knit a document in Ruby or R and output it in any of the
645
- available formats for R markdown. gKnit runs atop of GraalVM, and
646
- Galaaz. In gKnit, Ruby variables are persisted between chunks, making it
647
- an ideal solution for literate programming. Also, since it is based on
648
- Galaaz, Ruby chunks can have access to R variables and Polyglot
649
- Programming with Ruby and R is quite natural.
1013
+ This manual has been formatted using gKnit. gKnit uses knitr and R
1014
+ Markdown to knit a document in Ruby or R and output it in any of the
1015
+ available formats for R Markdown. gKnit runs with \textbf{JRuby},
1016
+ \textbf{GNU R}, and Galaaz. In gKnit, Ruby variables are persisted
1017
+ between chunks, making it an ideal solution for literate programming.
1018
+ Also, since it is based on Galaaz, Ruby chunks can have access to R
1019
+ variables and combining Ruby with R in one document is natural.
650
1020
 
651
1021
  The idea of ``literate programming'' was first introduced by Donald
652
1022
  Knuth in the 1980's (Knuth 1984). The main intention of this approach
@@ -664,8 +1034,8 @@ in a single document or set of documents that when distributed to peers
664
1034
  could be rerun generating the same output and reports.
665
1035
 
666
1036
  The R community has put a great deal of effort in reproducible research.
667
- In 2002, Sweave was introduced and it allowed mixing R code with Latex
668
- generating high quality PDF documents. A Sweave document could include
1037
+ In 2002, Sweave was introduced and it allowed mixing R code with LaTeX,
1038
+ generating high-quality PDF documents. A Sweave document could include
669
1039
  code, the results of executing the code, graphics and text such that it
670
1040
  contained the whole narrative to reproduce the research. In 2012, Knitr,
671
1041
  developed by Yihui Xie from RStudio was released to replace Sweave and
@@ -674,8 +1044,8 @@ packages that were necessary for Sweave.
674
1044
 
675
1045
  With Knitr, \textbf{R markdown} was also developed, an extension to the
676
1046
  Markdown format. With \textbf{R markdown} and Knitr it is possible to
677
- generate reports in a multitude of formats such as HTML, markdown,
678
- Latex, PDF, dvi, etc. \textbf{R markdown} also allows the use of
1047
+ generate reports in a multitude of formats such as HTML, Markdown,
1048
+ LaTeX, PDF, DVI, etc. \textbf{R markdown} also allows the use of
679
1049
  multiple programming languages such as R, Ruby, Python, etc. in the same
680
1050
  document.
681
1051
 
@@ -701,8 +1071,8 @@ binary format:
701
1071
 
702
1072
  \begin{Shaded}
703
1073
  \begin{Highlighting}[]
704
- \NormalTok{lst = R.list(}\StringTok{a: }\DecValTok{1}\NormalTok{, }\StringTok{b: }\DecValTok{2}\NormalTok{, }\StringTok{c: }\DecValTok{3}\NormalTok{)}
705
- \NormalTok{lst.saveRDS(}\StringTok{"lst.rds"}\NormalTok{)}
1074
+ \NormalTok{lst }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.list}\NormalTok{(}\WarningTok{a:} \DecValTok{1}\NormalTok{, }\WarningTok{b:} \DecValTok{2}\NormalTok{, }\WarningTok{c:} \DecValTok{3}\NormalTok{)}
1075
+ \NormalTok{lst}\AttributeTok{.saveRDS}\NormalTok{(}\StringTok{"lst.rds"}\NormalTok{)}
706
1076
  \end{Highlighting}
707
1077
  \end{Shaded}
708
1078
 
@@ -711,8 +1081,8 @@ back it's value
711
1081
 
712
1082
  \begin{Shaded}
713
1083
  \begin{Highlighting}[]
714
- \NormalTok{lst = R.readRDS(}\StringTok{"lst.rds"}\NormalTok{)}
715
- \NormalTok{puts lst}
1084
+ \NormalTok{lst }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.readRDS}\NormalTok{(}\StringTok{"lst.rds"}\NormalTok{)}
1085
+ \FunctionTok{puts}\NormalTok{ lst}
716
1086
  \end{Highlighting}
717
1087
  \end{Shaded}
718
1088
 
@@ -732,18 +1102,18 @@ and reuse between chunks. Clearly, such an approach becomes quickly
732
1102
  unmanageable. Probably, because of this problem, it is very rare to see
733
1103
  any \textbf{R markdown} document in the Ruby community.
734
1104
 
735
- When variables can be used accross chunks, then no overhead is needed:
1105
+ When variables can be used across chunks, then no overhead is needed:
736
1106
 
737
1107
  \begin{Shaded}
738
1108
  \begin{Highlighting}[]
739
- \NormalTok{lst = R.list(}\StringTok{a: }\DecValTok{1}\NormalTok{, }\StringTok{b: }\DecValTok{2}\NormalTok{, }\StringTok{c: }\DecValTok{3}\NormalTok{)}
740
- \CommentTok{# any other code can be added here}
1109
+ \NormalTok{lst }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.list}\NormalTok{(}\WarningTok{a:} \DecValTok{1}\NormalTok{, }\WarningTok{b:} \DecValTok{2}\NormalTok{, }\WarningTok{c:} \DecValTok{3}\NormalTok{)}
1110
+ \CommentTok{\# any other code can be added here}
741
1111
  \end{Highlighting}
742
1112
  \end{Shaded}
743
1113
 
744
1114
  \begin{Shaded}
745
1115
  \begin{Highlighting}[]
746
- \NormalTok{puts lst}
1116
+ \FunctionTok{puts}\NormalTok{ lst}
747
1117
  \end{Highlighting}
748
1118
  \end{Shaded}
749
1119
 
@@ -759,13 +1129,14 @@ When variables can be used accross chunks, then no overhead is needed:
759
1129
  \end{verbatim}
760
1130
 
761
1131
  In the Python community, the same effort to have code and text in an
762
- integrated environment started around the first decade of 2000. In 2006
763
- iPython 0.7.2 was released. In 2014, Fernando Pérez, spun off project
764
- Jupyter from iPython creating a web-based interactive computation
765
- environment. Jupyter can now be used with many languages, including Ruby
766
- with the iruby gem (\url{https://github.com/SciRuby/iruby}). In order to
767
- have multiple languages in a Jupyter notebook the SoS kernel was
768
- developed (\url{https://vatlab.github.io/sos-docs/}).
1132
+ integrated environment started around the first decade of the 2000s. In
1133
+ 2006 IPython 0.7.2 was released. In 2014, Fernando Pérez spun off the
1134
+ Jupyter project from IPython, creating a web-based interactive
1135
+ computation environment. Jupyter can now be used with many languages,
1136
+ including Ruby with the iruby gem
1137
+ (\url{https://github.com/SciRuby/iruby}). In order to have multiple
1138
+ languages in a Jupyter notebook the SoS kernel was developed
1139
+ (\url{https://vatlab.github.io/sos-docs/}).
769
1140
 
770
1141
  \subsection{\texorpdfstring{gKnit and \textbf{R
771
1142
  markdown}}{gKnit and R markdown}}\label{gknit-and-r-markdown}
@@ -778,8 +1149,10 @@ in a single document, text and code.
778
1149
 
779
1150
  In gKnit, Ruby variables are persisted between chunks, making it an
780
1151
  ideal solution for literate programming in this language. Also, since it
781
- is based on Galaaz, Ruby chunks can have access to R variables and
782
- Polyglot Programming with Ruby and R is quite natural.
1152
+ is based on Galaaz, Ruby chunks can access R variables
1153
+ (\texttt{\textasciitilde{}:name}, \texttt{R.*}) through the
1154
+ \textbf{Galaaz bridge} while knitr drives \textbf{GNU R}---no GraalVM
1155
+ polyglot runtime is required.
783
1156
 
784
1157
  This is not a blog post on \textbf{R markdown}, and the interested user
785
1158
  is directed to the following links for detailed information on its
@@ -800,7 +1173,7 @@ markdown}, so the user can start gKnitting Ruby and R documents quickly.
800
1173
 
801
1174
  An \textbf{R markdown} document should start with a Yaml header and be
802
1175
  stored in a file with `.Rmd' extension. This document has the following
803
- header for gKitting an HTML document.
1176
+ header for gKnitting an HTML document.
804
1177
 
805
1178
  \begin{verbatim}
806
1179
  ---
@@ -808,7 +1181,7 @@ title: "How to do reproducible research in Ruby with gKnit"
808
1181
  author:
809
1182
  - "Rodrigo Botafogo"
810
1183
  - "Daniel Mossé - University of Pittsburgh"
811
- tags: [Tech, Data Science, Ruby, R, GraalVM]
1184
+ tags: [Tech, Data Science, Ruby, R, JRuby, Galaaz]
812
1185
  date: "20/02/2019"
813
1186
  output:
814
1187
  html_document:
@@ -825,6 +1198,73 @@ For more information on the options in the Yaml header,
825
1198
  \href{https://bookdown.org/yihui/rmarkdown/html-document.html}{check
826
1199
  here}.
827
1200
 
1201
+ \subsection{Choosing the output format when calling
1202
+ gknit}\label{choosing-the-output-format-when-calling-gknit}
1203
+
1204
+ Yes: you can select the render target on the \textbf{command line}.
1205
+ \textbf{\texttt{bin/gknit}} (or \textbf{\texttt{gknit}} on your
1206
+ \texttt{PATH}) forwards options to \textbf{\texttt{rmarkdown::render}}
1207
+ via \textbf{\texttt{R::Rmarkdown.render}}.
1208
+
1209
+ \begin{itemize}
1210
+ \tightlist
1211
+ \item
1212
+ \textbf{\texttt{-\/-output\_format\ FORMAT}} --- name of the format,
1213
+ as in the YAML \texttt{output:} block. Examples:
1214
+
1215
+ \begin{itemize}
1216
+ \tightlist
1217
+ \item
1218
+ \textbf{\texttt{html\_document}} --- HTML (often the default you
1219
+ list first under \texttt{output:}).
1220
+ \item
1221
+ \textbf{\texttt{pdf\_document}} --- PDF (you need a working LaTeX
1222
+ setup, e.g.~TinyTeX; see \textbf{\texttt{bin/install-tinytex}}).
1223
+ \item
1224
+ \textbf{\texttt{md\_document}}, \textbf{\texttt{github\_document}},
1225
+ or any other format defined in your YAML.
1226
+ \item
1227
+ \textbf{\texttt{all}} --- render \textbf{every} format declared
1228
+ under \texttt{output:} in the document (same idea as in R Markdown).
1229
+ \end{itemize}
1230
+ \end{itemize}
1231
+
1232
+ If you \textbf{omit} \textbf{\texttt{-\/-output\_format}}, gknit passes
1233
+ \textbf{\texttt{NULL}} for the format argument. In that case
1234
+ \textbf{rmarkdown} uses the \textbf{first} format listed under
1235
+ \textbf{\texttt{output:}} in the YAML (and if none is specified there,
1236
+ behavior follows the usual rmarkdown defaults, typically HTML).
1237
+
1238
+ Other useful flags:
1239
+
1240
+ \begin{itemize}
1241
+ \tightlist
1242
+ \item
1243
+ \textbf{\texttt{-\/-output\_file\ NAME}} --- output file name
1244
+ (optional path; see also \textbf{\texttt{-\/-output\_dir}}).
1245
+ \item
1246
+ \textbf{\texttt{-\/-output\_dir\ DIR}} --- directory for the rendered
1247
+ file (created if missing).
1248
+ \item
1249
+ \textbf{\texttt{-\/-bridge\_timeout\_sec}} /
1250
+ \textbf{\texttt{-\/-callback\_timeout\_ms}} --- longer R or install
1251
+ steps (see elsewhere in this manual).
1252
+ \end{itemize}
1253
+
1254
+ Examples (run from the directory where paths make sense, or use absolute
1255
+ paths):
1256
+
1257
+ \begin{Shaded}
1258
+ \begin{Highlighting}[]
1259
+ \NormalTok{bin/gknit blogs/manual/manual.Rmd}
1260
+ \NormalTok{bin/gknit {-}{-}output\_format html\_document blogs/manual/manual.Rmd}
1261
+ \NormalTok{bin/gknit {-}{-}output\_format pdf\_document blogs/manual/manual.Rmd}
1262
+ \NormalTok{bin/gknit {-}{-}output\_format all blogs/manual/manual.Rmd}
1263
+ \end{Highlighting}
1264
+ \end{Shaded}
1265
+
1266
+ Use \textbf{\texttt{gknit\ -h}} for the full option list.
1267
+
828
1268
  \subsection{\texorpdfstring{\textbf{R Markdown}
829
1269
  formatting}{R Markdown formatting}}\label{r-markdown-formatting}
830
1270
 
@@ -870,8 +1310,8 @@ Running and executing Ruby and R code is actually what really interests
870
1310
  us is this blog.\\
871
1311
  Inserting a code chunk is done by adding code in a block delimited by
872
1312
  three back ticks followed by an open curly brace (`\{') followed with
873
- the engine name (r, ruby, rb, include, \ldots{}), an any optional
874
- chunk\_label and options, as shown bellow:
1313
+ the engine name (r, ruby, rb, include, \ldots), an any optional
1314
+ chunk\_label and options, as shown below:
875
1315
 
876
1316
  \begin{verbatim}
877
1317
  ```{engine_name [chunk_label], [chunk_options]}
@@ -894,8 +1334,8 @@ the result will be:
894
1334
 
895
1335
  \begin{Shaded}
896
1336
  \begin{Highlighting}[]
897
- \NormalTok{vec <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}
898
- \KeywordTok{print}\NormalTok{(vec)}
1337
+ \NormalTok{vec }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}
1338
+ \FunctionTok{print}\NormalTok{(vec)}
899
1339
  \end{Highlighting}
900
1340
  \end{Shaded}
901
1341
 
@@ -945,10 +1385,10 @@ longer.
945
1385
 
946
1386
  \begin{Shaded}
947
1387
  \begin{Highlighting}[]
948
- \NormalTok{r_vec <-}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{)}
1388
+ \NormalTok{r\_vec }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{)}
949
1389
 
950
- \NormalTok{reduce_sum <-}\StringTok{ }\ControlFlowTok{function}\NormalTok{(...) \{}
951
- \KeywordTok{Reduce}\NormalTok{(sum, }\KeywordTok{as.list}\NormalTok{(...))}
1390
+ \NormalTok{reduce\_sum }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(...) \{}
1391
+ \FunctionTok{Reduce}\NormalTok{(sum, }\FunctionTok{as.list}\NormalTok{(...))}
952
1392
  \NormalTok{\}}
953
1393
  \end{Highlighting}
954
1394
  \end{Shaded}
@@ -958,7 +1398,7 @@ function as follows:
958
1398
 
959
1399
  \begin{Shaded}
960
1400
  \begin{Highlighting}[]
961
- \KeywordTok{print}\NormalTok{(r_vec)}
1401
+ \FunctionTok{print}\NormalTok{(r\_vec)}
962
1402
  \end{Highlighting}
963
1403
  \end{Shaded}
964
1404
 
@@ -968,7 +1408,7 @@ function as follows:
968
1408
 
969
1409
  \begin{Shaded}
970
1410
  \begin{Highlighting}[]
971
- \KeywordTok{print}\NormalTok{(}\KeywordTok{reduce_sum}\NormalTok{(r_vec))}
1411
+ \FunctionTok{print}\NormalTok{(}\FunctionTok{reduce\_sum}\NormalTok{(r\_vec))}
972
1412
  \end{Highlighting}
973
1413
  \end{Shaded}
974
1414
 
@@ -989,7 +1429,7 @@ grammar of graphics is to build a graphics by adding layers to the plot.
989
1429
  More information can be found in
990
1430
  \url{https://towardsdatascience.com/a-comprehensive-guide-to-the-grammar-of-graphics-for-effective-visualization-of-multi-dimensional-1f92b4ed4149}.
991
1431
 
992
- In the plot bellow the `mpg' dataset from base R is used. ``The data
1432
+ In the plot below the `mpg' dataset from base R is used. ``The data
993
1433
  concerns city-cycle fuel consumption in miles per gallon, to be
994
1434
  predicted in terms of 3 multivalued discrete and 5 continuous
995
1435
  attributes.'' (Quinlan, 1993)
@@ -1008,38 +1448,28 @@ linear regression line (method = ``lm'') for every manufacturer.
1008
1448
 
1009
1449
  \begin{Shaded}
1010
1450
  \begin{Highlighting}[]
1011
- \CommentTok{# load package and data}
1012
- \KeywordTok{library}\NormalTok{(ggplot2)}
1013
- \end{Highlighting}
1014
- \end{Shaded}
1451
+ \CommentTok{\# load package and data}
1452
+ \FunctionTok{library}\NormalTok{(ggplot2)}
1453
+ \FunctionTok{data}\NormalTok{(mpg, }\AttributeTok{package=}\StringTok{"ggplot2"}\NormalTok{)}
1015
1454
 
1016
- \begin{verbatim}
1017
- ## Message:
1018
- ## Registered S3 methods overwritten by 'ggplot2':
1019
- ## method from
1020
- ## [.quosures rlang
1021
- ## c.quosures rlang
1022
- ## print.quosures rlang
1023
- \end{verbatim}
1455
+ \NormalTok{mpg\_select }\OtherTok{\textless{}{-}}\NormalTok{ mpg[mpg}\SpecialCharTok{$}\NormalTok{manufacturer }\SpecialCharTok{\%in\%} \FunctionTok{c}\NormalTok{(}\StringTok{"audi"}\NormalTok{, }\StringTok{"ford"}\NormalTok{, }\StringTok{"honda"}\NormalTok{, }\StringTok{"hyundai"}\NormalTok{), ]}
1024
1456
 
1025
- \begin{Shaded}
1026
- \begin{Highlighting}[]
1027
- \KeywordTok{data}\NormalTok{(mpg, }\DataTypeTok{package=}\StringTok{"ggplot2"}\NormalTok{)}
1457
+ \CommentTok{\# Scatterplot}
1458
+ \FunctionTok{theme\_set}\NormalTok{(}\FunctionTok{theme\_bw}\NormalTok{()) }\CommentTok{\# pre{-}set the bw theme.}
1459
+ \NormalTok{g }\OtherTok{\textless{}{-}} \FunctionTok{ggplot}\NormalTok{(mpg\_select, }\FunctionTok{aes}\NormalTok{(displ, cty)) }\SpecialCharTok{+}
1460
+ \FunctionTok{labs}\NormalTok{(}\AttributeTok{subtitle=}\StringTok{"mpg: Displacement vs City Mileage"}\NormalTok{,}
1461
+ \AttributeTok{title=}\StringTok{"Bubble chart"}\NormalTok{)}
1028
1462
 
1029
- \NormalTok{mpg_select <-}\StringTok{ }\NormalTok{mpg[mpg}\OperatorTok{$}\NormalTok{manufacturer }\OperatorTok{%in%}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"audi"}\NormalTok{, }\StringTok{"ford"}\NormalTok{, }\StringTok{"honda"}\NormalTok{, }\StringTok{"hyundai"}\NormalTok{), ]}
1030
-
1031
- \CommentTok{# Scatterplot}
1032
- \KeywordTok{theme_set}\NormalTok{(}\KeywordTok{theme_bw}\NormalTok{()) }\CommentTok{# pre-set the bw theme.}
1033
- \NormalTok{g <-}\StringTok{ }\KeywordTok{ggplot}\NormalTok{(mpg_select, }\KeywordTok{aes}\NormalTok{(displ, cty)) }\OperatorTok{+}\StringTok{ }
1034
- \StringTok{ }\KeywordTok{labs}\NormalTok{(}\DataTypeTok{subtitle=}\StringTok{"mpg: Displacement vs City Mileage"}\NormalTok{,}
1035
- \DataTypeTok{title=}\StringTok{"Bubble chart"}\NormalTok{)}
1036
-
1037
- \NormalTok{g }\OperatorTok{+}\StringTok{ }\KeywordTok{geom_jitter}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{col=}\NormalTok{manufacturer, }\DataTypeTok{size=}\NormalTok{hwy)) }\OperatorTok{+}\StringTok{ }
1038
- \StringTok{ }\KeywordTok{geom_smooth}\NormalTok{(}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{col=}\NormalTok{manufacturer), }\DataTypeTok{method=}\StringTok{"lm"}\NormalTok{, }\DataTypeTok{se=}\NormalTok{F)}
1463
+ \NormalTok{g }\SpecialCharTok{+} \FunctionTok{geom\_jitter}\NormalTok{(}\FunctionTok{aes}\NormalTok{(}\AttributeTok{col=}\NormalTok{manufacturer, }\AttributeTok{size=}\NormalTok{hwy)) }\SpecialCharTok{+}
1464
+ \FunctionTok{geom\_smooth}\NormalTok{(}\FunctionTok{aes}\NormalTok{(}\AttributeTok{col=}\NormalTok{manufacturer), }\AttributeTok{method=}\StringTok{"lm"}\NormalTok{, }\AttributeTok{se=}\NormalTok{F)}
1039
1465
  \end{Highlighting}
1040
1466
  \end{Shaded}
1041
1467
 
1042
- \includegraphics{manual_files/figure-latex/bubble-1.png}
1468
+ \begin{verbatim}
1469
+ ## `geom_smooth()` using formula = 'y ~ x'
1470
+ \end{verbatim}
1471
+
1472
+ \pandocbounded{\includegraphics[keepaspectratio]{manual_files/figure-latex/bubble-1.png}}
1043
1473
 
1044
1474
  \subsection{Ruby chunks}\label{ruby-chunks}
1045
1475
 
@@ -1072,12 +1502,12 @@ text without any code.
1072
1502
 
1073
1503
  \begin{Shaded}
1074
1504
  \begin{Highlighting}[]
1075
- \NormalTok{a = [}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{]}
1076
- \NormalTok{b = }\StringTok{"US$ 250.000"}
1077
- \NormalTok{c = }\StringTok{"The 'outputs' function"}
1505
+ \NormalTok{a }\OperatorTok{=} \KeywordTok{[}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\KeywordTok{]}
1506
+ \NormalTok{b }\OperatorTok{=} \StringTok{"US$ 250.000"}
1507
+ \NormalTok{c }\OperatorTok{=} \StringTok{"The \textquotesingle{}outputs\textquotesingle{} function"}
1078
1508
 
1079
- \NormalTok{vec = R.c(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}
1080
- \NormalTok{vec2 = R.c(}\DecValTok{10}\NormalTok{, }\DecValTok{20}\NormalTok{, }\DecValTok{30}\NormalTok{)}
1509
+ \NormalTok{vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}
1510
+ \NormalTok{vec2 }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{20}\NormalTok{, }\DecValTok{30}\NormalTok{)}
1081
1511
  \end{Highlighting}
1082
1512
  \end{Shaded}
1083
1513
 
@@ -1085,8 +1515,8 @@ In the next block, variables `a', `vec' and `vec2' are used and printed.
1085
1515
 
1086
1516
  \begin{Shaded}
1087
1517
  \begin{Highlighting}[]
1088
- \NormalTok{puts a}
1089
- \NormalTok{puts vec * vec2}
1518
+ \FunctionTok{puts}\NormalTok{ a}
1519
+ \FunctionTok{puts}\NormalTok{ vec }\OperatorTok{*}\NormalTok{ vec2}
1090
1520
  \end{Highlighting}
1091
1521
  \end{Shaded}
1092
1522
 
@@ -1122,8 +1552,7 @@ Note that it is important not to add any new line before of after the
1122
1552
  code block if we want everything to be in only one line, resulting in
1123
1553
  the following sentence with inline Ruby code.
1124
1554
 
1125
- \subsubsection{\texorpdfstring{The `outputs'
1126
- function}{The outputs function}}\label{the-outputs-function}
1555
+ \subsubsection{The `outputs' function}\label{the-outputs-function}
1127
1556
 
1128
1557
  He have previously used the standard `puts' method in Ruby chunks in
1129
1558
  order produce output. The result of a `puts', as seen in all previous
@@ -1139,7 +1568,7 @@ the first line of a file we are going to read. Method `outputs' adds its
1139
1568
  output as if typed in the \textbf{R markdown} document.
1140
1569
 
1141
1570
  Take now a look at variable `c' (it was defined in a previous block
1142
- above) as `c = ``The 'outputs' function''. ``The 'outputs' function'' is
1571
+ above) as `c = ``The `outputs' function''. ``The `outputs' function'' is
1143
1572
  actually the name of this section and it was created using the 'outputs'
1144
1573
  function inside a Ruby chunk.
1145
1574
 
@@ -1183,113 +1612,85 @@ document:
1183
1612
  </table>
1184
1613
  \end{verbatim}
1185
1614
 
1186
- \begin{verbatim}
1187
- <th>Firstname</th>
1188
- <th>Lastname</th>
1189
- <th>Age</th>
1190
- \end{verbatim}
1615
+ Firstname
1191
1616
 
1192
- \begin{verbatim}
1193
- <td>Jill</td>
1194
- <td>Smith</td>
1195
- <td>50</td>
1196
- \end{verbatim}
1617
+ Lastname
1197
1618
 
1198
- \begin{verbatim}
1199
- <td>Eve</td>
1200
- <td>Jackson</td>
1201
- <td>94</td>
1202
- \end{verbatim}
1619
+ Age
1620
+
1621
+ Jill
1622
+
1623
+ Smith
1624
+
1625
+ 50
1626
+
1627
+ Eve
1628
+
1629
+ Jackson
1630
+
1631
+ 94
1203
1632
 
1204
1633
  But manually creating HTML output is not always easy or desirable,
1205
1634
  specially if we intend the document to be rendered in other formats, for
1206
- example, as Latex. Also, The above table looks ugly. The `kableExtra'
1635
+ example, as LaTeX. Also, The above table looks ugly. The `kableExtra'
1207
1636
  library is a great library for creating beautiful tables. Take a look at
1208
1637
  \url{https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html}
1209
1638
 
1210
1639
  In the next chunk, we output the `mtcars' dataframe from R in a nicely
1211
1640
  formatted table. Note that we retrieve the mtcars dataframe by using
1212
- `\textasciitilde{}:mtcars'.
1641
+ `\textasciitilde:mtcars'.
1213
1642
 
1214
1643
  \begin{Shaded}
1215
1644
  \begin{Highlighting}[]
1216
- \NormalTok{R.install_and_loads(}\StringTok{'kableExtra'}\NormalTok{)}
1217
- \NormalTok{outputs (~}\StringTok{:mtcars}\NormalTok{).kable.kable_styling}
1645
+ \ConstantTok{R}\AttributeTok{.install\_and\_loads}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}kableExtra\textquotesingle{}}\NormalTok{)}
1646
+ \NormalTok{outputs (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.kable.kable\_styling}
1218
1647
  \end{Highlighting}
1219
1648
  \end{Shaded}
1220
1649
 
1221
- \begin{table}[H]
1222
- \centering
1223
- \begin{tabular}{l|r|r|r|r|r|r|r|r|r|r|r}
1224
- \hline
1225
- & mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb\\
1226
- \hline
1650
+ \begin{longtable}[t]{lrrrrrrrrrrr}
1651
+ \toprule
1652
+ & mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb\\
1653
+ \midrule
1227
1654
  Mazda RX4 & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 & 4\\
1228
- \hline
1229
1655
  Mazda RX4 Wag & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4 & 4\\
1230
- \hline
1231
1656
  Datsun 710 & 22.8 & 4 & 108.0 & 93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 & 1\\
1232
- \hline
1233
1657
  Hornet 4 Drive & 21.4 & 6 & 258.0 & 110 & 3.08 & 3.215 & 19.44 & 1 & 0 & 3 & 1\\
1234
- \hline
1235
1658
  Hornet Sportabout & 18.7 & 8 & 360.0 & 175 & 3.15 & 3.440 & 17.02 & 0 & 0 & 3 & 2\\
1236
- \hline
1659
+ \addlinespace
1237
1660
  Valiant & 18.1 & 6 & 225.0 & 105 & 2.76 & 3.460 & 20.22 & 1 & 0 & 3 & 1\\
1238
- \hline
1239
1661
  Duster 360 & 14.3 & 8 & 360.0 & 245 & 3.21 & 3.570 & 15.84 & 0 & 0 & 3 & 4\\
1240
- \hline
1241
1662
  Merc 240D & 24.4 & 4 & 146.7 & 62 & 3.69 & 3.190 & 20.00 & 1 & 0 & 4 & 2\\
1242
- \hline
1243
1663
  Merc 230 & 22.8 & 4 & 140.8 & 95 & 3.92 & 3.150 & 22.90 & 1 & 0 & 4 & 2\\
1244
- \hline
1245
1664
  Merc 280 & 19.2 & 6 & 167.6 & 123 & 3.92 & 3.440 & 18.30 & 1 & 0 & 4 & 4\\
1246
- \hline
1665
+ \addlinespace
1247
1666
  Merc 280C & 17.8 & 6 & 167.6 & 123 & 3.92 & 3.440 & 18.90 & 1 & 0 & 4 & 4\\
1248
- \hline
1249
1667
  Merc 450SE & 16.4 & 8 & 275.8 & 180 & 3.07 & 4.070 & 17.40 & 0 & 0 & 3 & 3\\
1250
- \hline
1251
1668
  Merc 450SL & 17.3 & 8 & 275.8 & 180 & 3.07 & 3.730 & 17.60 & 0 & 0 & 3 & 3\\
1252
- \hline
1253
1669
  Merc 450SLC & 15.2 & 8 & 275.8 & 180 & 3.07 & 3.780 & 18.00 & 0 & 0 & 3 & 3\\
1254
- \hline
1255
1670
  Cadillac Fleetwood & 10.4 & 8 & 472.0 & 205 & 2.93 & 5.250 & 17.98 & 0 & 0 & 3 & 4\\
1256
- \hline
1671
+ \addlinespace
1257
1672
  Lincoln Continental & 10.4 & 8 & 460.0 & 215 & 3.00 & 5.424 & 17.82 & 0 & 0 & 3 & 4\\
1258
- \hline
1259
1673
  Chrysler Imperial & 14.7 & 8 & 440.0 & 230 & 3.23 & 5.345 & 17.42 & 0 & 0 & 3 & 4\\
1260
- \hline
1261
1674
  Fiat 128 & 32.4 & 4 & 78.7 & 66 & 4.08 & 2.200 & 19.47 & 1 & 1 & 4 & 1\\
1262
- \hline
1263
1675
  Honda Civic & 30.4 & 4 & 75.7 & 52 & 4.93 & 1.615 & 18.52 & 1 & 1 & 4 & 2\\
1264
- \hline
1265
1676
  Toyota Corolla & 33.9 & 4 & 71.1 & 65 & 4.22 & 1.835 & 19.90 & 1 & 1 & 4 & 1\\
1266
- \hline
1677
+ \addlinespace
1267
1678
  Toyota Corona & 21.5 & 4 & 120.1 & 97 & 3.70 & 2.465 & 20.01 & 1 & 0 & 3 & 1\\
1268
- \hline
1269
1679
  Dodge Challenger & 15.5 & 8 & 318.0 & 150 & 2.76 & 3.520 & 16.87 & 0 & 0 & 3 & 2\\
1270
- \hline
1271
1680
  AMC Javelin & 15.2 & 8 & 304.0 & 150 & 3.15 & 3.435 & 17.30 & 0 & 0 & 3 & 2\\
1272
- \hline
1273
1681
  Camaro Z28 & 13.3 & 8 & 350.0 & 245 & 3.73 & 3.840 & 15.41 & 0 & 0 & 3 & 4\\
1274
- \hline
1275
1682
  Pontiac Firebird & 19.2 & 8 & 400.0 & 175 & 3.08 & 3.845 & 17.05 & 0 & 0 & 3 & 2\\
1276
- \hline
1683
+ \addlinespace
1277
1684
  Fiat X1-9 & 27.3 & 4 & 79.0 & 66 & 4.08 & 1.935 & 18.90 & 1 & 1 & 4 & 1\\
1278
- \hline
1279
1685
  Porsche 914-2 & 26.0 & 4 & 120.3 & 91 & 4.43 & 2.140 & 16.70 & 0 & 1 & 5 & 2\\
1280
- \hline
1281
1686
  Lotus Europa & 30.4 & 4 & 95.1 & 113 & 3.77 & 1.513 & 16.90 & 1 & 1 & 5 & 2\\
1282
- \hline
1283
1687
  Ford Pantera L & 15.8 & 8 & 351.0 & 264 & 4.22 & 3.170 & 14.50 & 0 & 1 & 5 & 4\\
1284
- \hline
1285
1688
  Ferrari Dino & 19.7 & 6 & 145.0 & 175 & 3.62 & 2.770 & 15.50 & 0 & 1 & 5 & 6\\
1286
- \hline
1689
+ \addlinespace
1287
1690
  Maserati Bora & 15.0 & 8 & 301.0 & 335 & 3.54 & 3.570 & 14.60 & 0 & 1 & 5 & 8\\
1288
- \hline
1289
1691
  Volvo 142E & 21.4 & 4 & 121.0 & 109 & 4.11 & 2.780 & 18.60 & 1 & 1 & 4 & 2\\
1290
- \hline
1291
- \end{tabular}
1292
- \end{table}
1692
+ \bottomrule
1693
+ \end{longtable}
1293
1694
 
1294
1695
  \subsection{Including Ruby files in a
1295
1696
  chunk}\label{including-ruby-files-in-a-chunk}
@@ -1319,8 +1720,8 @@ Ruby's \$LOAD\_PATH is searched to find the file and it is 'require'd.
1319
1720
  ```
1320
1721
  \end{verbatim}
1321
1722
 
1322
- Bellow we include file `model.rb', which is in the same directory of
1323
- this blog.\\
1723
+ Below we include file `model.rb', which is in the same directory of this
1724
+ blog.\\
1324
1725
  This code uses R `caret' package to split a dataset in a train and test
1325
1726
  sets. The `caret' package is a very important a useful package for doing
1326
1727
  Data Analysis, it has hundreds of functions for all steps of the Data
@@ -1339,73 +1740,73 @@ installed and can take a while.
1339
1740
  ```
1340
1741
  \end{verbatim}
1341
1742
 
1342
- \begin{verbatim}
1343
- require 'galaaz'
1743
+ \begin{Shaded}
1744
+ \begin{Highlighting}[]
1745
+ \NormalTok{require \textquotesingle{}galaaz\textquotesingle{}}
1344
1746
 
1345
- # Loads the R 'caret' package. If not present, installs it
1346
- R.install_and_loads 'caret'
1747
+ \NormalTok{\# Loads the R \textquotesingle{}caret\textquotesingle{} package. If not present, installs it }
1748
+ \NormalTok{R.install\_and\_loads \textquotesingle{}caret\textquotesingle{}}
1347
1749
 
1348
- class Model
1750
+ \NormalTok{class Model}
1349
1751
 
1350
- attr_reader :data
1351
- attr_reader :test
1352
- attr_reader :train
1752
+ \NormalTok{ attr\_reader :data}
1753
+ \NormalTok{ attr\_reader :test}
1754
+ \NormalTok{ attr\_reader :train}
1353
1755
 
1354
- #==========================================================
1355
- #
1356
- #==========================================================
1756
+ \NormalTok{ \#==========================================================}
1757
+ \NormalTok{ \#}
1758
+ \NormalTok{ \#==========================================================}
1357
1759
 
1358
- def initialize(data, percent_train:, seed: 123)
1760
+ \NormalTok{ def initialize(data, percent\_train:, seed: 123)}
1359
1761
 
1360
- R.set__seed(seed)
1361
- @data = data
1362
- @percent_train = percent_train
1363
- @seed = seed
1762
+ \NormalTok{ R.set\_\_seed(seed)}
1763
+ \NormalTok{ @data = data}
1764
+ \NormalTok{ @percent\_train = percent\_train}
1765
+ \NormalTok{ @seed = seed}
1364
1766
 
1365
- end
1767
+ \NormalTok{ end}
1366
1768
 
1367
- #==========================================================
1368
- #
1369
- #==========================================================
1769
+ \NormalTok{ \#==========================================================}
1770
+ \NormalTok{ \#}
1771
+ \NormalTok{ \#==========================================================}
1370
1772
 
1371
- def partition(field)
1773
+ \NormalTok{ def partition(field)}
1372
1774
 
1373
- train_index =
1374
- R.createDataPartition(@data.send(field), p: @percet_train,
1375
- list: false, times: 1)
1376
- @train = @data[train_index, :all]
1377
- @test = @data[-train_index, :all]
1775
+ \NormalTok{ train\_index =}
1776
+ \NormalTok{ R.createDataPartition(@data.send(field), p: @percent\_train,}
1777
+ \NormalTok{ list: false, times: 1)}
1778
+ \NormalTok{ @train = @data[train\_index, :all]}
1779
+ \NormalTok{ @test = @data[{-}train\_index, :all]}
1378
1780
 
1379
- end
1781
+ \NormalTok{ end}
1380
1782
 
1381
- end
1382
- \end{verbatim}
1783
+ \NormalTok{end}
1784
+ \end{Highlighting}
1785
+ \end{Shaded}
1383
1786
 
1384
1787
  \begin{Shaded}
1385
1788
  \begin{Highlighting}[]
1386
- \NormalTok{mtcars = ~}\StringTok{:mtcars}
1387
- \NormalTok{model = }\DataTypeTok{Model}\NormalTok{.new(mtcars, }\StringTok{percent_train: }\FloatTok{0.8}\NormalTok{)}
1388
- \NormalTok{model.partition(}\StringTok{:mpg}\NormalTok{)}
1389
- \NormalTok{puts model.train.head}
1390
- \NormalTok{puts model.test.head}
1789
+ \NormalTok{mtcars }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}
1790
+ \NormalTok{model }\OperatorTok{=} \DataTypeTok{Model}\AttributeTok{.new}\NormalTok{(mtcars, }\WarningTok{percent\_train:} \FloatTok{0.8}\NormalTok{)}
1791
+ \NormalTok{model}\AttributeTok{.partition}\NormalTok{(}\WarningTok{:mpg}\NormalTok{)}
1792
+ \FunctionTok{puts}\NormalTok{ model}\AttributeTok{.train.head}
1793
+ \FunctionTok{puts}\NormalTok{ model}\AttributeTok{.test.head}
1391
1794
  \end{Highlighting}
1392
1795
  \end{Shaded}
1393
1796
 
1394
1797
  \begin{verbatim}
1395
- ## mpg cyl disp hp drat wt qsec vs am gear carb
1396
- ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
1397
- ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
1398
- ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
1399
- ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
1400
- ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
1401
- ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
1402
1798
  ## mpg cyl disp hp drat wt qsec vs am gear carb
1799
+ ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
1403
1800
  ## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
1404
1801
  ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
1405
1802
  ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
1406
- ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
1803
+ ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
1407
1804
  ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
1408
- ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
1805
+ ## mpg cyl disp hp drat wt qsec vs am gear carb
1806
+ ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
1807
+ ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
1808
+ ## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
1809
+ ## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
1409
1810
  \end{verbatim}
1410
1811
 
1411
1812
  \subsection{Documenting Gems}\label{documenting-gems}
@@ -1413,105 +1814,110 @@ end
1413
1814
  gKnit also allows developers to document and load files that are not in
1414
1815
  the same directory of the `.Rmd' file.
1415
1816
 
1416
- Here is an example of loading the `find.rb' file from TruffleRuby. In
1417
- this example, relative is set to FALSE, so Ruby will look for the file
1418
- in its \$LOAD\_PATH, and the user does not need to no it's directory.
1817
+ Here is an example of loading Ruby's standard library file
1818
+ \texttt{find.rb}. In this example, relative is set to FALSE, so Ruby
1819
+ will look for the file in its \texttt{\$LOAD\_PATH}, and the user does
1820
+ not need to know its directory on disk.
1419
1821
 
1420
1822
  \begin{verbatim}
1421
1823
  ```{include find, relative = FALSE}
1422
1824
  ```
1423
1825
  \end{verbatim}
1424
1826
 
1425
- \begin{verbatim}
1426
- # frozen_string_literal: true
1427
- #
1428
- # find.rb: the Find module for processing all files under a given directory.
1429
- #
1430
-
1431
- #
1432
- # The +Find+ module supports the top-down traversal of a set of file paths.
1433
- #
1434
- # For example, to total the size of all files under your home directory,
1435
- # ignoring anything in a "dot" directory (e.g. $HOME/.ssh):
1436
- #
1437
- # require 'find'
1438
- #
1439
- # total_size = 0
1440
- #
1441
- # Find.find(ENV["HOME"]) do |path|
1442
- # if FileTest.directory?(path)
1443
- # if File.basename(path)[0] == ?.
1444
- # Find.prune # Don't look any further into this directory.
1445
- # else
1446
- # next
1447
- # end
1448
- # else
1449
- # total_size += FileTest.size(path)
1450
- # end
1451
- # end
1452
- #
1453
- module Find
1454
-
1455
- #
1456
- # Calls the associated block with the name of every file and directory listed
1457
- # as arguments, then recursively on their subdirectories, and so on.
1458
- #
1459
- # Returns an enumerator if no block is given.
1460
- #
1461
- # See the +Find+ module documentation for an example.
1462
- #
1463
- def find(*paths, ignore_error: true) # :yield: path
1464
- block_given? or return enum_for(__method__, *paths, ignore_error: ignore_error)
1465
-
1466
- fs_encoding = Encoding.find("filesystem")
1467
-
1468
- paths.collect!{|d| raise Errno::ENOENT, d unless File.exist?(d); d.dup}.each do |path|
1469
- path = path.to_path if path.respond_to? :to_path
1470
- enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
1471
- ps = [path]
1472
- while file = ps.shift
1473
- catch(:prune) do
1474
- yield file.dup.taint
1475
- begin
1476
- s = File.lstat(file)
1477
- rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
1478
- raise unless ignore_error
1479
- next
1480
- end
1481
- if s.directory? then
1482
- begin
1483
- fs = Dir.children(file, encoding: enc)
1484
- rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
1485
- raise unless ignore_error
1486
- next
1487
- end
1488
- fs.sort!
1489
- fs.reverse_each {|f|
1490
- f = File.join(file, f)
1491
- ps.unshift f.untaint
1492
- }
1493
- end
1494
- end
1495
- end
1496
- end
1497
- nil
1498
- end
1499
-
1500
- #
1501
- # Skips the current file or directory, restarting the loop with the next
1502
- # entry. If the current file is a directory, that directory will not be
1503
- # recursively entered. Meaningful only within the block associated with
1504
- # Find::find.
1505
- #
1506
- # See the +Find+ module documentation for an example.
1507
- #
1508
- def prune
1509
- throw :prune
1510
- end
1511
-
1512
- module_function :find, :prune
1513
- end
1514
- \end{verbatim}
1827
+ \begin{Shaded}
1828
+ \begin{Highlighting}[]
1829
+ \NormalTok{\# frozen\_string\_literal: true}
1830
+ \NormalTok{\#}
1831
+ \NormalTok{\# find.rb: the Find module for processing all files under a given directory.}
1832
+ \NormalTok{\#}
1833
+
1834
+ \NormalTok{\#}
1835
+ \NormalTok{\# The +Find+ module supports the top{-}down traversal of a set of file paths.}
1836
+ \NormalTok{\#}
1837
+ \NormalTok{\# For example, to total the size of all files under your home directory,}
1838
+ \NormalTok{\# ignoring anything in a "dot" directory (e.g. $HOME/.ssh):}
1839
+ \NormalTok{\#}
1840
+ \NormalTok{\# require \textquotesingle{}find\textquotesingle{}}
1841
+ \NormalTok{\#}
1842
+ \NormalTok{\# total\_size = 0}
1843
+ \NormalTok{\#}
1844
+ \NormalTok{\# Find.find(ENV["HOME"]) do |path|}
1845
+ \NormalTok{\# if FileTest.directory?(path)}
1846
+ \NormalTok{\# if File.basename(path).start\_with?(\textquotesingle{}.\textquotesingle{})}
1847
+ \NormalTok{\# Find.prune \# Don\textquotesingle{}t look any further into this directory.}
1848
+ \NormalTok{\# else}
1849
+ \NormalTok{\# next}
1850
+ \NormalTok{\# end}
1851
+ \NormalTok{\# else}
1852
+ \NormalTok{\# total\_size += FileTest.size(path)}
1853
+ \NormalTok{\# end}
1854
+ \NormalTok{\# end}
1855
+ \NormalTok{\#}
1856
+ \NormalTok{module Find}
1857
+
1858
+ \NormalTok{ VERSION = "0.2.0"}
1859
+
1860
+ \NormalTok{ \#}
1861
+ \NormalTok{ \# Calls the associated block with the name of every file and directory listed}
1862
+ \NormalTok{ \# as arguments, then recursively on their subdirectories, and so on.}
1863
+ \NormalTok{ \#}
1864
+ \NormalTok{ \# Returns an enumerator if no block is given.}
1865
+ \NormalTok{ \#}
1866
+ \NormalTok{ \# See the +Find+ module documentation for an example.}
1867
+ \NormalTok{ \#}
1868
+ \NormalTok{ def find(*paths, ignore\_error: true) \# :yield: path}
1869
+ \NormalTok{ block\_given? or return enum\_for(\_\_method\_\_, *paths, ignore\_error: ignore\_error)}
1870
+
1871
+ \NormalTok{ fs\_encoding = Encoding.find("filesystem")}
1872
+
1873
+ \NormalTok{ paths.collect!\{|d| raise Errno::ENOENT, d unless File.exist?(d); d.dup\}.each do |path|}
1874
+ \NormalTok{ path = path.to\_path if path.respond\_to? :to\_path}
1875
+ \NormalTok{ enc = path.encoding == Encoding::US\_ASCII ? fs\_encoding : path.encoding}
1876
+ \NormalTok{ ps = [path]}
1877
+ \NormalTok{ while file = ps.shift}
1878
+ \NormalTok{ catch(:prune) do}
1879
+ \NormalTok{ yield file.dup}
1880
+ \NormalTok{ begin}
1881
+ \NormalTok{ s = File.lstat(file)}
1882
+ \NormalTok{ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EINVAL}
1883
+ \NormalTok{ raise unless ignore\_error}
1884
+ \NormalTok{ next}
1885
+ \NormalTok{ end}
1886
+ \NormalTok{ if s.directory? then}
1887
+ \NormalTok{ begin}
1888
+ \NormalTok{ fs = Dir.children(file, encoding: enc)}
1889
+ \NormalTok{ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EINVAL}
1890
+ \NormalTok{ raise unless ignore\_error}
1891
+ \NormalTok{ next}
1892
+ \NormalTok{ end}
1893
+ \NormalTok{ fs.sort!}
1894
+ \NormalTok{ fs.reverse\_each \{|f|}
1895
+ \NormalTok{ f = File.join(file, f)}
1896
+ \NormalTok{ ps.unshift f}
1897
+ \NormalTok{ \}}
1898
+ \NormalTok{ end}
1899
+ \NormalTok{ end}
1900
+ \NormalTok{ end}
1901
+ \NormalTok{ end}
1902
+ \NormalTok{ nil}
1903
+ \NormalTok{ end}
1904
+
1905
+ \NormalTok{ \#}
1906
+ \NormalTok{ \# Skips the current file or directory, restarting the loop with the next}
1907
+ \NormalTok{ \# entry. If the current file is a directory, that directory will not be}
1908
+ \NormalTok{ \# recursively entered. Meaningful only within the block associated with}
1909
+ \NormalTok{ \# Find::find.}
1910
+ \NormalTok{ \#}
1911
+ \NormalTok{ \# See the +Find+ module documentation for an example.}
1912
+ \NormalTok{ \#}
1913
+ \NormalTok{ def prune}
1914
+ \NormalTok{ throw :prune}
1915
+ \NormalTok{ end}
1916
+
1917
+ \NormalTok{ module\_function :find, :prune}
1918
+ \NormalTok{end}
1919
+ \end{Highlighting}
1920
+ \end{Shaded}
1515
1921
 
1516
1922
  \subsection{Converting to PDF}\label{converting-to-pdf}
1517
1923
 
@@ -1528,9 +1934,9 @@ format instead of HTML:
1528
1934
 
1529
1935
  \begin{verbatim}
1530
1936
  ---
1531
- title: "gKnit - Ruby and R Knitting with Galaaz in GraalVM"
1937
+ title: "gKnit - Ruby and R Knitting with Galaaz"
1532
1938
  author: "Rodrigo Botafogo"
1533
- tags: [Galaaz, Ruby, R, TruffleRuby, FastR, GraalVM, knitr, gknit]
1939
+ tags: [Galaaz, Ruby, R, JRuby, knitr, gknit]
1534
1940
  date: "29 October 2018"
1535
1941
  output:
1536
1942
  pdf\_document:
@@ -1543,7 +1949,7 @@ output:
1543
1949
  \subsection{Template based documents
1544
1950
  generation}\label{template-based-documents-generation}
1545
1951
 
1546
- When a document is converted to PDF it follows a certain convertion
1952
+ When a document is converted to PDF it follows a certain conversion
1547
1953
  template. We've seen above the use of `galaaz.sty' as a basic template
1548
1954
  to generate a PDF document. Using the `gknit-draft' app that comes with
1549
1955
  Galaaz, the same .Rmd file can be compiled to different looking PDF
@@ -1631,91 +2037,63 @@ gknit-draft --filename my_r_article --template rjournal_article --package rticle
1631
2037
  \section{Accessing R variables}\label{accessing-r-variables}
1632
2038
 
1633
2039
  Galaaz allows Ruby to access variables created in R. For example, the
1634
- `mtcars' data set is available in R and can be accessed from Ruby by
1635
- using the `tilda' operator followed by the symbol for the variable, in
1636
- this case `:mtcar'. In the code bellow method `outputs' is used to
1637
- output the `mtcars' data set nicely formatted in HTML by use of the
1638
- `kable' and `kable\_styling' functions. Method `outputs' is only
1639
- available when used with `gknit'.
2040
+ \texttt{mtcars} data set is available in R and can be accessed from Ruby
2041
+ by using the tilde operator followed by the symbol for the variable, in
2042
+ this case \texttt{:mtcars}. In the code below, method \texttt{outputs}
2043
+ is used to output the \texttt{mtcars} data set nicely formatted in HTML
2044
+ by use of the \texttt{kable} and \texttt{kable\_styling} functions.
2045
+ Method \texttt{outputs} is only available when used with gKnit.
1640
2046
 
1641
2047
  \begin{Shaded}
1642
2048
  \begin{Highlighting}[]
1643
- \NormalTok{outputs (~}\StringTok{:mtcars}\NormalTok{).kable.kable_styling}
2049
+ \NormalTok{outputs (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.kable.kable\_styling}
1644
2050
  \end{Highlighting}
1645
2051
  \end{Shaded}
1646
2052
 
1647
- \begin{table}[H]
1648
- \centering
1649
- \begin{tabular}{l|r|r|r|r|r|r|r|r|r|r|r}
1650
- \hline
1651
- & mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb\\
1652
- \hline
2053
+ \begin{longtable}[t]{lrrrrrrrrrrr}
2054
+ \toprule
2055
+ & mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb\\
2056
+ \midrule
1653
2057
  Mazda RX4 & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 & 4\\
1654
- \hline
1655
2058
  Mazda RX4 Wag & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4 & 4\\
1656
- \hline
1657
2059
  Datsun 710 & 22.8 & 4 & 108.0 & 93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 & 1\\
1658
- \hline
1659
2060
  Hornet 4 Drive & 21.4 & 6 & 258.0 & 110 & 3.08 & 3.215 & 19.44 & 1 & 0 & 3 & 1\\
1660
- \hline
1661
2061
  Hornet Sportabout & 18.7 & 8 & 360.0 & 175 & 3.15 & 3.440 & 17.02 & 0 & 0 & 3 & 2\\
1662
- \hline
2062
+ \addlinespace
1663
2063
  Valiant & 18.1 & 6 & 225.0 & 105 & 2.76 & 3.460 & 20.22 & 1 & 0 & 3 & 1\\
1664
- \hline
1665
2064
  Duster 360 & 14.3 & 8 & 360.0 & 245 & 3.21 & 3.570 & 15.84 & 0 & 0 & 3 & 4\\
1666
- \hline
1667
2065
  Merc 240D & 24.4 & 4 & 146.7 & 62 & 3.69 & 3.190 & 20.00 & 1 & 0 & 4 & 2\\
1668
- \hline
1669
2066
  Merc 230 & 22.8 & 4 & 140.8 & 95 & 3.92 & 3.150 & 22.90 & 1 & 0 & 4 & 2\\
1670
- \hline
1671
2067
  Merc 280 & 19.2 & 6 & 167.6 & 123 & 3.92 & 3.440 & 18.30 & 1 & 0 & 4 & 4\\
1672
- \hline
2068
+ \addlinespace
1673
2069
  Merc 280C & 17.8 & 6 & 167.6 & 123 & 3.92 & 3.440 & 18.90 & 1 & 0 & 4 & 4\\
1674
- \hline
1675
2070
  Merc 450SE & 16.4 & 8 & 275.8 & 180 & 3.07 & 4.070 & 17.40 & 0 & 0 & 3 & 3\\
1676
- \hline
1677
2071
  Merc 450SL & 17.3 & 8 & 275.8 & 180 & 3.07 & 3.730 & 17.60 & 0 & 0 & 3 & 3\\
1678
- \hline
1679
2072
  Merc 450SLC & 15.2 & 8 & 275.8 & 180 & 3.07 & 3.780 & 18.00 & 0 & 0 & 3 & 3\\
1680
- \hline
1681
2073
  Cadillac Fleetwood & 10.4 & 8 & 472.0 & 205 & 2.93 & 5.250 & 17.98 & 0 & 0 & 3 & 4\\
1682
- \hline
2074
+ \addlinespace
1683
2075
  Lincoln Continental & 10.4 & 8 & 460.0 & 215 & 3.00 & 5.424 & 17.82 & 0 & 0 & 3 & 4\\
1684
- \hline
1685
2076
  Chrysler Imperial & 14.7 & 8 & 440.0 & 230 & 3.23 & 5.345 & 17.42 & 0 & 0 & 3 & 4\\
1686
- \hline
1687
2077
  Fiat 128 & 32.4 & 4 & 78.7 & 66 & 4.08 & 2.200 & 19.47 & 1 & 1 & 4 & 1\\
1688
- \hline
1689
2078
  Honda Civic & 30.4 & 4 & 75.7 & 52 & 4.93 & 1.615 & 18.52 & 1 & 1 & 4 & 2\\
1690
- \hline
1691
2079
  Toyota Corolla & 33.9 & 4 & 71.1 & 65 & 4.22 & 1.835 & 19.90 & 1 & 1 & 4 & 1\\
1692
- \hline
2080
+ \addlinespace
1693
2081
  Toyota Corona & 21.5 & 4 & 120.1 & 97 & 3.70 & 2.465 & 20.01 & 1 & 0 & 3 & 1\\
1694
- \hline
1695
2082
  Dodge Challenger & 15.5 & 8 & 318.0 & 150 & 2.76 & 3.520 & 16.87 & 0 & 0 & 3 & 2\\
1696
- \hline
1697
2083
  AMC Javelin & 15.2 & 8 & 304.0 & 150 & 3.15 & 3.435 & 17.30 & 0 & 0 & 3 & 2\\
1698
- \hline
1699
2084
  Camaro Z28 & 13.3 & 8 & 350.0 & 245 & 3.73 & 3.840 & 15.41 & 0 & 0 & 3 & 4\\
1700
- \hline
1701
2085
  Pontiac Firebird & 19.2 & 8 & 400.0 & 175 & 3.08 & 3.845 & 17.05 & 0 & 0 & 3 & 2\\
1702
- \hline
2086
+ \addlinespace
1703
2087
  Fiat X1-9 & 27.3 & 4 & 79.0 & 66 & 4.08 & 1.935 & 18.90 & 1 & 1 & 4 & 1\\
1704
- \hline
1705
2088
  Porsche 914-2 & 26.0 & 4 & 120.3 & 91 & 4.43 & 2.140 & 16.70 & 0 & 1 & 5 & 2\\
1706
- \hline
1707
2089
  Lotus Europa & 30.4 & 4 & 95.1 & 113 & 3.77 & 1.513 & 16.90 & 1 & 1 & 5 & 2\\
1708
- \hline
1709
2090
  Ford Pantera L & 15.8 & 8 & 351.0 & 264 & 4.22 & 3.170 & 14.50 & 0 & 1 & 5 & 4\\
1710
- \hline
1711
2091
  Ferrari Dino & 19.7 & 6 & 145.0 & 175 & 3.62 & 2.770 & 15.50 & 0 & 1 & 5 & 6\\
1712
- \hline
2092
+ \addlinespace
1713
2093
  Maserati Bora & 15.0 & 8 & 301.0 & 335 & 3.54 & 3.570 & 14.60 & 0 & 1 & 5 & 8\\
1714
- \hline
1715
2094
  Volvo 142E & 21.4 & 4 & 121.0 & 109 & 4.11 & 2.780 & 18.60 & 1 & 1 & 4 & 2\\
1716
- \hline
1717
- \end{tabular}
1718
- \end{table}
2095
+ \bottomrule
2096
+ \end{longtable}
1719
2097
 
1720
2098
  \section{Basic Data Types}\label{basic-data-types}
1721
2099
 
@@ -1727,19 +2105,22 @@ basic (`atomic') vector types: logical, integer, real, complex, string
1727
2105
  (or character) and raw. The modes and storage modes for the different
1728
2106
  vector types are listed in the following table.
1729
2107
 
2108
+ {\def\LTcaptype{none} % do not increment counter
1730
2109
  \begin{longtable}[]{@{}lcr@{}}
1731
- \toprule
1732
- typeof & mode & storage.mode\tabularnewline
1733
- \midrule
2110
+ \toprule\noalign{}
2111
+ typeof & mode & storage.mode \\
2112
+ \midrule\noalign{}
1734
2113
  \endhead
1735
- logical & logical & logical\tabularnewline
1736
- integer & numeric & integer\tabularnewline
1737
- double & numeric & double\tabularnewline
1738
- complex & complex & comples\tabularnewline
1739
- character & character & character\tabularnewline
1740
- raw & raw & raw\tabularnewline
1741
- \bottomrule
2114
+ \bottomrule\noalign{}
2115
+ \endlastfoot
2116
+ logical & logical & logical \\
2117
+ integer & numeric & integer \\
2118
+ double & numeric & double \\
2119
+ complex & complex & complex \\
2120
+ character & character & character \\
2121
+ raw & raw & raw \\
1742
2122
  \end{longtable}
2123
+ }
1743
2124
 
1744
2125
  Single numbers, such as 4.2, and strings, such as ``four point two'' are
1745
2126
  still vectors, of length 1; there are no more basic types. Vectors with
@@ -1752,8 +2133,8 @@ should be used:
1752
2133
 
1753
2134
  \begin{Shaded}
1754
2135
  \begin{Highlighting}[]
1755
- \NormalTok{vec = R.c(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}
1756
- \NormalTok{puts vec}
2136
+ \NormalTok{vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}
2137
+ \FunctionTok{puts}\NormalTok{ vec}
1757
2138
  \end{Highlighting}
1758
2139
  \end{Shaded}
1759
2140
 
@@ -1767,7 +2148,7 @@ printing it out. A data frame, for those not familiar with it, is
1767
2148
  basically a table. Here we create the data frame and add the column name
1768
2149
  by passing named parameters for each column, such as `typeof:', `mode:'
1769
2150
  and 'storage\_\_mode?`. You should also note here that the double
1770
- underscore is converted to a'.`. So, when printed 'storage\_\_mode' will
2151
+ underscore is converted to a'.'. So, when printed `storage\_\_mode' will
1771
2152
  actually print as `storage.mode'.
1772
2153
 
1773
2154
  Data frames will later be more carefully described. In R, the method
@@ -1776,8 +2157,8 @@ used to create a data frame is `data.frame', in Galaaz we use
1776
2157
 
1777
2158
  \begin{Shaded}
1778
2159
  \begin{Highlighting}[]
1779
- \NormalTok{df = R.data__frame(}\StringTok{typeof: }\NormalTok{vec.typeof, }\StringTok{mode: }\NormalTok{vec.mode, }\StringTok{storage__mode: }\NormalTok{vec.storage__mode)}
1780
- \NormalTok{puts df}
2160
+ \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}\WarningTok{typeof:}\NormalTok{ vec}\AttributeTok{.typeof}\NormalTok{, }\WarningTok{mode:}\NormalTok{ vec}\AttributeTok{.mode}\NormalTok{, }\WarningTok{storage\_\_mode:}\NormalTok{ vec}\AttributeTok{.storage\_\_mode}\NormalTok{)}
2161
+ \FunctionTok{puts}\NormalTok{ df}
1781
2162
  \end{Highlighting}
1782
2163
  \end{Shaded}
1783
2164
 
@@ -1794,8 +2175,8 @@ normal Ruby rules and the number 1 is an integer and 1.0 is a float.
1794
2175
 
1795
2176
  \begin{Shaded}
1796
2177
  \begin{Highlighting}[]
1797
- \NormalTok{vec = R.c(}\FloatTok{1.0}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}
1798
- \NormalTok{puts vec}
2178
+ \NormalTok{vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{1.0}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}
2179
+ \FunctionTok{puts}\NormalTok{ vec}
1799
2180
  \end{Highlighting}
1800
2181
  \end{Shaded}
1801
2182
 
@@ -1805,21 +2186,18 @@ normal Ruby rules and the number 1 is an integer and 1.0 is a float.
1805
2186
 
1806
2187
  \begin{Shaded}
1807
2188
  \begin{Highlighting}[]
1808
- \NormalTok{df = R.data__frame(}\StringTok{typeof: }\NormalTok{vec.typeof, }\StringTok{mode: }\NormalTok{vec.mode, }\StringTok{storage__mode: }\NormalTok{vec.storage__mode)}
1809
- \NormalTok{outputs df.kable.kable_styling}
2189
+ \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}\WarningTok{typeof:}\NormalTok{ vec}\AttributeTok{.typeof}\NormalTok{, }\WarningTok{mode:}\NormalTok{ vec}\AttributeTok{.mode}\NormalTok{, }\WarningTok{storage\_\_mode:}\NormalTok{ vec}\AttributeTok{.storage\_\_mode}\NormalTok{)}
2190
+ \NormalTok{outputs df}\AttributeTok{.kable.kable\_styling}
1810
2191
  \end{Highlighting}
1811
2192
  \end{Shaded}
1812
2193
 
1813
- \begin{table}[H]
1814
- \centering
1815
- \begin{tabular}{l|l|l}
1816
- \hline
2194
+ \begin{longtable}[t]{lll}
2195
+ \toprule
1817
2196
  typeof & mode & storage.mode\\
1818
- \hline
2197
+ \midrule
1819
2198
  double & numeric & double\\
1820
- \hline
1821
- \end{tabular}
1822
- \end{table}
2199
+ \bottomrule
2200
+ \end{longtable}
1823
2201
 
1824
2202
  In this next example we try to create a vector with a variable `hello'
1825
2203
  that has not yet being defined. This will raise an exception that is
@@ -1829,43 +2207,32 @@ error.
1829
2207
 
1830
2208
  \begin{Shaded}
1831
2209
  \begin{Highlighting}[]
1832
- \NormalTok{vec = R.c(}\DecValTok{1}\NormalTok{, hello, }\DecValTok{5}\NormalTok{)}
2210
+ \NormalTok{vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, hello, }\DecValTok{5}\NormalTok{)}
1833
2211
  \end{Highlighting}
1834
2212
  \end{Shaded}
1835
2213
 
1836
2214
  \begin{verbatim}
1837
- ## Message:
1838
- ## undefined local variable or method `hello' for #<RC:0x3d8 @out_list=nil>:RC
2215
+ ## undefined local variable or method 'hello' for an instance of RC
1839
2216
  \end{verbatim}
1840
2217
 
1841
2218
  \begin{verbatim}
1842
- ## Message:
1843
- ## /home/rbotafogo/desenv/galaaz/lib/util/exec_ruby.rb:103:in `get_binding'
1844
- ## /home/rbotafogo/desenv/galaaz/lib/util/exec_ruby.rb:102:in `eval'
1845
- ## /home/rbotafogo/desenv/galaaz/lib/util/exec_ruby.rb:102:in `exec_ruby'
1846
- ## /home/rbotafogo/desenv/galaaz/lib/gknit/knitr_engine.rb:650:in `block in initialize'
1847
- ## /home/rbotafogo/desenv/galaaz/lib/R_interface/ruby_callback.rb:77:in `call'
1848
- ## /home/rbotafogo/desenv/galaaz/lib/R_interface/ruby_callback.rb:77:in `callback'
1849
- ## (eval):3:in `function(...) {\n rb_method(...)'
1850
- ## unknown.r:1:in `in_dir'
1851
- ## unknown.r:1:in `block_exec'
1852
- ## /usr/local/lib/graalvm-ce-java11-20.0.0/languages/R/library/knitr/R/block.R:92:in `call_block'
1853
- ## /usr/local/lib/graalvm-ce-java11-20.0.0/languages/R/library/knitr/R/block.R:6:in `process_group.block'
1854
- ## /usr/local/lib/graalvm-ce-java11-20.0.0/languages/R/library/knitr/R/block.R:3:in `<no source>'
1855
- ## unknown.r:1:in `withCallingHandlers'
1856
- ## unknown.r:1:in `process_file'
1857
- ## unknown.r:1:in `<no source>'
1858
- ## unknown.r:1:in `<no source>'
1859
- ## <REPL>:4:in `<repl wrapper>'
1860
- ## <REPL>:1
2219
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:170:in 'exec_ruby'
2220
+ ## org/jruby/RubyKernel.java:1268:in 'eval'
2221
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:169:in 'exec_ruby'
2222
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:777:in 'block in initialize'
2223
+ ## org/jruby/RubyBasicObject.java:2695:in 'instance_eval'
2224
+ ## org/jruby/RubyBasicObject.java:2723:in 'instance_eval'
2225
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:748:in 'block in initialize'
2226
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/new_bridge_adapter.rb:358:in 'block in register_callback_proc_stub'
2227
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/new_bridge/session_client.rb:413:in 'block in handle_call'
1861
2228
  \end{verbatim}
1862
2229
 
1863
2230
  Here is a vector with logical values
1864
2231
 
1865
2232
  \begin{Shaded}
1866
2233
  \begin{Highlighting}[]
1867
- \NormalTok{vec = R.c(}\DecValTok{true}\NormalTok{, }\DecValTok{true}\NormalTok{, }\DecValTok{false}\NormalTok{, }\DecValTok{false}\NormalTok{, }\DecValTok{true}\NormalTok{)}
1868
- \NormalTok{puts vec}
2234
+ \NormalTok{vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{true}\NormalTok{, }\DecValTok{true}\NormalTok{, }\DecValTok{false}\NormalTok{, }\DecValTok{false}\NormalTok{, }\DecValTok{true}\NormalTok{)}
2235
+ \FunctionTok{puts}\NormalTok{ vec}
1869
2236
  \end{Highlighting}
1870
2237
  \end{Shaded}
1871
2238
 
@@ -1880,10 +2247,10 @@ vectors:
1880
2247
 
1881
2248
  \begin{Shaded}
1882
2249
  \begin{Highlighting}[]
1883
- \NormalTok{vec1 = R.c(}\FloatTok{10.0}\NormalTok{, }\FloatTok{20.0}\NormalTok{, }\FloatTok{30.0}\NormalTok{)}
1884
- \NormalTok{vec2 = R.c(}\FloatTok{4.0}\NormalTok{, }\FloatTok{5.0}\NormalTok{, }\FloatTok{6.0}\NormalTok{)}
1885
- \NormalTok{vec = R.c(vec1, vec2)}
1886
- \NormalTok{puts vec}
2250
+ \NormalTok{vec1 }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{10.0}\NormalTok{, }\FloatTok{20.0}\NormalTok{, }\FloatTok{30.0}\NormalTok{)}
2251
+ \NormalTok{vec2 }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{4.0}\NormalTok{, }\FloatTok{5.0}\NormalTok{, }\FloatTok{6.0}\NormalTok{)}
2252
+ \NormalTok{vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(vec1, vec2)}
2253
+ \FunctionTok{puts}\NormalTok{ vec}
1887
2254
  \end{Highlighting}
1888
2255
  \end{Shaded}
1889
2256
 
@@ -1892,18 +2259,18 @@ vectors:
1892
2259
  \end{verbatim}
1893
2260
 
1894
2261
  In galaaz, methods can be chainned (somewhat like the pipe operator in R
1895
- \%\textgreater{}\%, but more generic). In this next example, method `c'
1896
- is chainned after `vec1'. This also looks like `c' is a method of the
2262
+ \%\textgreater\%, but more generic). In this next example, method `c' is
2263
+ chainned after `vec1'. This also looks like `c' is a method of the
1897
2264
  vector, but in reallity, this is actually closer to the pipe operator.
1898
2265
  When Galaaz identifies that `c' is not a method of `vec' it actually
1899
2266
  tries to call `R.c' with `vec1' as the first argument concatenated with
1900
- all the other available arguments. The code bellow is automatically
2267
+ all the other available arguments. The code below is automatically
1901
2268
  converted to the code above.
1902
2269
 
1903
2270
  \begin{Shaded}
1904
2271
  \begin{Highlighting}[]
1905
- \NormalTok{vec = vec1.c(vec2)}
1906
- \NormalTok{puts vec}
2272
+ \NormalTok{vec }\OperatorTok{=}\NormalTok{ vec1}\AttributeTok{.c}\NormalTok{(vec2)}
2273
+ \FunctionTok{puts}\NormalTok{ vec}
1907
2274
  \end{Highlighting}
1908
2275
  \end{Shaded}
1909
2276
 
@@ -1917,7 +2284,7 @@ Arithmetic operations on vectors are performed element by element:
1917
2284
 
1918
2285
  \begin{Shaded}
1919
2286
  \begin{Highlighting}[]
1920
- \NormalTok{puts vec1 + vec2}
2287
+ \FunctionTok{puts}\NormalTok{ vec1 }\OperatorTok{+}\NormalTok{ vec2}
1921
2288
  \end{Highlighting}
1922
2289
  \end{Shaded}
1923
2290
 
@@ -1927,7 +2294,7 @@ Arithmetic operations on vectors are performed element by element:
1927
2294
 
1928
2295
  \begin{Shaded}
1929
2296
  \begin{Highlighting}[]
1930
- \NormalTok{puts vec1 * }\DecValTok{5}
2297
+ \FunctionTok{puts}\NormalTok{ vec1 }\OperatorTok{*} \DecValTok{5}
1931
2298
  \end{Highlighting}
1932
2299
  \end{Shaded}
1933
2300
 
@@ -1940,8 +2307,8 @@ shorter vector:
1940
2307
 
1941
2308
  \begin{Shaded}
1942
2309
  \begin{Highlighting}[]
1943
- \NormalTok{vec3 = R.c(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{, }\FloatTok{4.0}\NormalTok{, }\FloatTok{5.0}\NormalTok{, }\FloatTok{6.0}\NormalTok{, }\FloatTok{7.0}\NormalTok{, }\FloatTok{8.0}\NormalTok{, }\FloatTok{9.0}\NormalTok{)}
1944
- \NormalTok{puts vec4 = vec1 + vec3}
2310
+ \NormalTok{vec3 }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{, }\FloatTok{4.0}\NormalTok{, }\FloatTok{5.0}\NormalTok{, }\FloatTok{6.0}\NormalTok{, }\FloatTok{7.0}\NormalTok{, }\FloatTok{8.0}\NormalTok{, }\FloatTok{9.0}\NormalTok{)}
2311
+ \FunctionTok{puts}\NormalTok{ vec4 }\OperatorTok{=}\NormalTok{ vec1 }\OperatorTok{+}\NormalTok{ vec3}
1945
2312
  \end{Highlighting}
1946
2313
  \end{Shaded}
1947
2314
 
@@ -1955,7 +2322,7 @@ Vectors can be indexed by using the `{[}{]}' operator:
1955
2322
 
1956
2323
  \begin{Shaded}
1957
2324
  \begin{Highlighting}[]
1958
- \NormalTok{puts vec4[}\DecValTok{3}\NormalTok{]}
2325
+ \FunctionTok{puts}\NormalTok{ vec4}\KeywordTok{[}\DecValTok{3}\KeywordTok{]}
1959
2326
  \end{Highlighting}
1960
2327
  \end{Shaded}
1961
2328
 
@@ -1964,11 +2331,11 @@ Vectors can be indexed by using the `{[}{]}' operator:
1964
2331
  \end{verbatim}
1965
2332
 
1966
2333
  We can also index a vector with another vector. For example, in the code
1967
- bellow, we take elements 1, 3, 5, and 7 from vec3:
2334
+ below, we take elements 1, 3, 5, and 7 from vec3:
1968
2335
 
1969
2336
  \begin{Shaded}
1970
2337
  \begin{Highlighting}[]
1971
- \NormalTok{puts vec4[R.c(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{7}\NormalTok{)]}
2338
+ \FunctionTok{puts}\NormalTok{ vec4}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{7}\NormalTok{)}\KeywordTok{]}
1972
2339
  \end{Highlighting}
1973
2340
  \end{Shaded}
1974
2341
 
@@ -1980,7 +2347,7 @@ Repeating an index and having indices out of order is valid code:
1980
2347
 
1981
2348
  \begin{Shaded}
1982
2349
  \begin{Highlighting}[]
1983
- \NormalTok{puts vec4[R.c(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{1}\NormalTok{)]}
2350
+ \FunctionTok{puts}\NormalTok{ vec4}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{1}\NormalTok{)}\KeywordTok{]}
1984
2351
  \end{Highlighting}
1985
2352
  \end{Shaded}
1986
2353
 
@@ -1993,8 +2360,8 @@ vector. In these cases the indexed values are not returned:
1993
2360
 
1994
2361
  \begin{Shaded}
1995
2362
  \begin{Highlighting}[]
1996
- \NormalTok{puts vec4[-}\DecValTok{3}\NormalTok{]}
1997
- \NormalTok{puts vec4[-R.c(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{7}\NormalTok{)]}
2363
+ \FunctionTok{puts}\NormalTok{ vec4}\KeywordTok{[}\OperatorTok{{-}}\DecValTok{3}\KeywordTok{]}
2364
+ \FunctionTok{puts}\NormalTok{ vec4}\KeywordTok{[}\OperatorTok{{-}}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{7}\NormalTok{)}\KeywordTok{]}
1998
2365
  \end{Highlighting}
1999
2366
  \end{Shaded}
2000
2367
 
@@ -2007,7 +2374,7 @@ If an index is out of range, a missing value (NA) will be reported.
2007
2374
 
2008
2375
  \begin{Shaded}
2009
2376
  \begin{Highlighting}[]
2010
- \NormalTok{puts vec4[}\DecValTok{30}\NormalTok{]}
2377
+ \FunctionTok{puts}\NormalTok{ vec4}\KeywordTok{[}\DecValTok{30}\KeywordTok{]}
2011
2378
  \end{Highlighting}
2012
2379
  \end{Shaded}
2013
2380
 
@@ -2019,7 +2386,7 @@ It is also possible to index a vector by range:
2019
2386
 
2020
2387
  \begin{Shaded}
2021
2388
  \begin{Highlighting}[]
2022
- \NormalTok{puts vec4[(}\DecValTok{2}\NormalTok{..}\DecValTok{5}\NormalTok{)]}
2389
+ \FunctionTok{puts}\NormalTok{ vec4}\KeywordTok{[}\NormalTok{(}\DecValTok{2}\OperatorTok{..}\DecValTok{5}\NormalTok{)}\KeywordTok{]}
2023
2390
  \end{Highlighting}
2024
2391
  \end{Shaded}
2025
2392
 
@@ -2032,9 +2399,9 @@ vector:
2032
2399
 
2033
2400
  \begin{Shaded}
2034
2401
  \begin{Highlighting}[]
2035
- \NormalTok{full_name = R.c(}\StringTok{"Rodrigo"}\NormalTok{, }\StringTok{"A"}\NormalTok{, }\StringTok{"Botafogo"}\NormalTok{)}
2036
- \NormalTok{full_name.names = R.c(}\StringTok{"First"}\NormalTok{, }\StringTok{"Middle"}\NormalTok{, }\StringTok{"Last"}\NormalTok{)}
2037
- \NormalTok{puts full_name}
2402
+ \NormalTok{full\_name }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"Rodrigo"}\NormalTok{, }\StringTok{"A"}\NormalTok{, }\StringTok{"Botafogo"}\NormalTok{)}
2403
+ \NormalTok{full\_name}\AttributeTok{.names} \OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"First"}\NormalTok{, }\StringTok{"Middle"}\NormalTok{, }\StringTok{"Last"}\NormalTok{)}
2404
+ \FunctionTok{puts}\NormalTok{ full\_name}
2038
2405
  \end{Highlighting}
2039
2406
  \end{Shaded}
2040
2407
 
@@ -2048,8 +2415,8 @@ paramenters:
2048
2415
 
2049
2416
  \begin{Shaded}
2050
2417
  \begin{Highlighting}[]
2051
- \NormalTok{full_name = R.c(}\DataTypeTok{First}\NormalTok{: }\StringTok{"Rodrigo"}\NormalTok{, }\DataTypeTok{Middle}\NormalTok{: }\StringTok{"A"}\NormalTok{, }\DataTypeTok{Last}\NormalTok{: }\StringTok{"Botafogo"}\NormalTok{)}
2052
- \NormalTok{puts full_name}
2418
+ \NormalTok{full\_name }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\WarningTok{First:} \StringTok{"Rodrigo"}\NormalTok{, }\WarningTok{Middle:} \StringTok{"A"}\NormalTok{, }\WarningTok{Last:} \StringTok{"Botafogo"}\NormalTok{)}
2419
+ \FunctionTok{puts}\NormalTok{ full\_name}
2053
2420
  \end{Highlighting}
2054
2421
  \end{Shaded}
2055
2422
 
@@ -2066,13 +2433,13 @@ noticed that when indexing a vector, a new vector is returned, even if
2066
2433
  this vector has one single element. In order to use R::Vector with other
2067
2434
  ruby classes it might be necessary to extract the actual Ruby native
2068
2435
  type from the vector. In order to do this extraction the
2069
- `\textgreater{}\textgreater{}' operator is used.
2436
+ `\textgreater\textgreater{}' operator is used.
2070
2437
 
2071
2438
  \begin{Shaded}
2072
2439
  \begin{Highlighting}[]
2073
- \NormalTok{puts vec4}
2074
- \NormalTok{puts vec4 >> }\DecValTok{0}
2075
- \NormalTok{puts vec4 >> }\DecValTok{4}
2440
+ \FunctionTok{puts}\NormalTok{ vec4}
2441
+ \FunctionTok{puts}\NormalTok{ vec4 }\OperatorTok{\textgreater{}\textgreater{}} \DecValTok{0}
2442
+ \FunctionTok{puts}\NormalTok{ vec4 }\OperatorTok{\textgreater{}\textgreater{}} \DecValTok{4}
2076
2443
  \end{Highlighting}
2077
2444
  \end{Shaded}
2078
2445
 
@@ -2082,8 +2449,8 @@ type from the vector. In order to do this extraction the
2082
2449
  ## 25.0
2083
2450
  \end{verbatim}
2084
2451
 
2085
- Note that indexing with `\textgreater{}\textgreater{}' starts at 0 and
2086
- not at 1, also, we cannot do negative indexing.
2452
+ Note that indexing with `\textgreater\textgreater{}' starts at 0 and not
2453
+ at 1, also, we cannot do negative indexing.
2087
2454
 
2088
2455
  \subsection{Matrix}\label{matrix}
2089
2456
 
@@ -2092,11 +2459,11 @@ table. A matrix can be created by the `matrix' function:
2092
2459
 
2093
2460
  \begin{Shaded}
2094
2461
  \begin{Highlighting}[]
2095
- \NormalTok{mat = R.matrix(R.c(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{, }\FloatTok{4.0}\NormalTok{, }\FloatTok{5.0}\NormalTok{, }\FloatTok{6.0}\NormalTok{, }\FloatTok{7.0}\NormalTok{, }\FloatTok{8.0}\NormalTok{, }\FloatTok{9.0}\NormalTok{),}
2096
- \StringTok{nrow: }\DecValTok{3}\NormalTok{,}
2097
- \StringTok{ncol: }\DecValTok{3}\NormalTok{)}
2462
+ \NormalTok{mat }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.matrix}\NormalTok{(}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{, }\FloatTok{4.0}\NormalTok{, }\FloatTok{5.0}\NormalTok{, }\FloatTok{6.0}\NormalTok{, }\FloatTok{7.0}\NormalTok{, }\FloatTok{8.0}\NormalTok{, }\FloatTok{9.0}\NormalTok{),}
2463
+ \WarningTok{nrow:} \DecValTok{3}\NormalTok{,}
2464
+ \WarningTok{ncol:} \DecValTok{3}\NormalTok{)}
2098
2465
 
2099
- \NormalTok{puts mat}
2466
+ \FunctionTok{puts}\NormalTok{ mat}
2100
2467
  \end{Highlighting}
2101
2468
  \end{Shaded}
2102
2469
 
@@ -2113,12 +2480,12 @@ organize the matrix memory by row first passing an extra argument to the
2113
2480
 
2114
2481
  \begin{Shaded}
2115
2482
  \begin{Highlighting}[]
2116
- \NormalTok{mat_row = R.matrix(R.c(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{, }\FloatTok{4.0}\NormalTok{, }\FloatTok{5.0}\NormalTok{, }\FloatTok{6.0}\NormalTok{, }\FloatTok{7.0}\NormalTok{, }\FloatTok{8.0}\NormalTok{, }\FloatTok{9.0}\NormalTok{),}
2117
- \StringTok{nrow: }\DecValTok{3}\NormalTok{,}
2118
- \StringTok{ncol: }\DecValTok{3}\NormalTok{,}
2119
- \StringTok{byrow: }\DecValTok{true}\NormalTok{)}
2483
+ \NormalTok{mat\_row }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.matrix}\NormalTok{(}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{, }\FloatTok{4.0}\NormalTok{, }\FloatTok{5.0}\NormalTok{, }\FloatTok{6.0}\NormalTok{, }\FloatTok{7.0}\NormalTok{, }\FloatTok{8.0}\NormalTok{, }\FloatTok{9.0}\NormalTok{),}
2484
+ \WarningTok{nrow:} \DecValTok{3}\NormalTok{,}
2485
+ \WarningTok{ncol:} \DecValTok{3}\NormalTok{,}
2486
+ \WarningTok{byrow:} \DecValTok{true}\NormalTok{)}
2120
2487
 
2121
- \NormalTok{puts mat_row}
2488
+ \FunctionTok{puts}\NormalTok{ mat\_row}
2122
2489
  \end{Highlighting}
2123
2490
  \end{Shaded}
2124
2491
 
@@ -2135,8 +2502,8 @@ A matrix can be indexed by {[}row, column{]}:
2135
2502
 
2136
2503
  \begin{Shaded}
2137
2504
  \begin{Highlighting}[]
2138
- \NormalTok{puts mat_row[}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{]}
2139
- \NormalTok{puts mat_row[}\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{]}
2505
+ \FunctionTok{puts}\NormalTok{ mat\_row}\KeywordTok{[}\DecValTok{1}\NormalTok{, }\DecValTok{1}\KeywordTok{]}
2506
+ \FunctionTok{puts}\NormalTok{ mat\_row}\KeywordTok{[}\DecValTok{2}\NormalTok{, }\DecValTok{3}\KeywordTok{]}
2140
2507
  \end{Highlighting}
2141
2508
  \end{Shaded}
2142
2509
 
@@ -2149,8 +2516,8 @@ It is possible to index an entire row or column with the `:all' keyword
2149
2516
 
2150
2517
  \begin{Shaded}
2151
2518
  \begin{Highlighting}[]
2152
- \NormalTok{puts mat_row[}\DecValTok{1}\NormalTok{, }\StringTok{:all}\NormalTok{]}
2153
- \NormalTok{puts mat_row[}\StringTok{:all}\NormalTok{, }\DecValTok{2}\NormalTok{]}
2519
+ \FunctionTok{puts}\NormalTok{ mat\_row}\KeywordTok{[}\DecValTok{1}\NormalTok{, }\WarningTok{:all}\KeywordTok{]}
2520
+ \FunctionTok{puts}\NormalTok{ mat\_row}\KeywordTok{[}\WarningTok{:all}\NormalTok{, }\DecValTok{2}\KeywordTok{]}
2154
2521
  \end{Highlighting}
2155
2522
  \end{Shaded}
2156
2523
 
@@ -2165,7 +2532,7 @@ matrix.
2165
2532
 
2166
2533
  \begin{Shaded}
2167
2534
  \begin{Highlighting}[]
2168
- \NormalTok{puts mat_row[R.c(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{), R.c(}\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)]}
2535
+ \FunctionTok{puts}\NormalTok{ mat\_row}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{), }\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{)}\KeywordTok{]}
2169
2536
  \end{Highlighting}
2170
2537
  \end{Shaded}
2171
2538
 
@@ -2179,7 +2546,7 @@ Matrices can be combined with functions `rbind':
2179
2546
 
2180
2547
  \begin{Shaded}
2181
2548
  \begin{Highlighting}[]
2182
- \NormalTok{puts mat_row.rbind(mat)}
2549
+ \FunctionTok{puts}\NormalTok{ mat\_row}\AttributeTok{.rbind}\NormalTok{(mat)}
2183
2550
  \end{Highlighting}
2184
2551
  \end{Shaded}
2185
2552
 
@@ -2197,7 +2564,7 @@ and `cbind':
2197
2564
 
2198
2565
  \begin{Shaded}
2199
2566
  \begin{Highlighting}[]
2200
- \NormalTok{puts mat_row.cbind(mat)}
2567
+ \FunctionTok{puts}\NormalTok{ mat\_row}\AttributeTok{.cbind}\NormalTok{(mat)}
2201
2568
  \end{Highlighting}
2202
2569
  \end{Shaded}
2203
2570
 
@@ -2215,11 +2582,11 @@ while vector and matrix can only hold one type of element.
2215
2582
 
2216
2583
  \begin{Shaded}
2217
2584
  \begin{Highlighting}[]
2218
- \NormalTok{nums = R.c(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{)}
2219
- \NormalTok{strs = R.c(}\StringTok{"a"}\NormalTok{, }\StringTok{"b"}\NormalTok{, }\StringTok{"c"}\NormalTok{, }\StringTok{"d"}\NormalTok{)}
2220
- \NormalTok{bool = R.c(}\DecValTok{true}\NormalTok{, }\DecValTok{true}\NormalTok{, }\DecValTok{false}\NormalTok{)}
2221
- \NormalTok{lst = R.list(}\StringTok{nums: }\NormalTok{nums, }\StringTok{strs: }\NormalTok{strs, }\StringTok{bool: }\NormalTok{bool)}
2222
- \NormalTok{puts lst}
2585
+ \NormalTok{nums }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{1.0}\NormalTok{, }\FloatTok{2.0}\NormalTok{, }\FloatTok{3.0}\NormalTok{)}
2586
+ \NormalTok{strs }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"a"}\NormalTok{, }\StringTok{"b"}\NormalTok{, }\StringTok{"c"}\NormalTok{, }\StringTok{"d"}\NormalTok{)}
2587
+ \NormalTok{bool }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{true}\NormalTok{, }\DecValTok{true}\NormalTok{, }\DecValTok{false}\NormalTok{)}
2588
+ \NormalTok{lst }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.list}\NormalTok{(}\WarningTok{nums:}\NormalTok{ nums, }\WarningTok{strs:}\NormalTok{ strs, }\WarningTok{bool:}\NormalTok{ bool)}
2589
+ \FunctionTok{puts}\NormalTok{ lst}
2223
2590
  \end{Highlighting}
2224
2591
  \end{Shaded}
2225
2592
 
@@ -2245,7 +2612,7 @@ return one of the sublists.
2245
2612
 
2246
2613
  \begin{Shaded}
2247
2614
  \begin{Highlighting}[]
2248
- \NormalTok{puts lst[}\DecValTok{1}\NormalTok{]}
2615
+ \FunctionTok{puts}\NormalTok{ lst}\KeywordTok{[}\DecValTok{1}\KeywordTok{]}
2249
2616
  \end{Highlighting}
2250
2617
  \end{Shaded}
2251
2618
 
@@ -2260,7 +2627,7 @@ of the list in the given position and not a slice of the original list
2260
2627
 
2261
2628
  \begin{Shaded}
2262
2629
  \begin{Highlighting}[]
2263
- \NormalTok{puts lst[[}\DecValTok{1}\NormalTok{]]}
2630
+ \FunctionTok{puts}\NormalTok{ lst}\KeywordTok{[[}\DecValTok{1}\KeywordTok{]]}
2264
2631
  \end{Highlighting}
2265
2632
  \end{Shaded}
2266
2633
 
@@ -2273,7 +2640,7 @@ name:
2273
2640
 
2274
2641
  \begin{Shaded}
2275
2642
  \begin{Highlighting}[]
2276
- \NormalTok{puts lst[[}\StringTok{'bool'}\NormalTok{]][[}\DecValTok{1}\NormalTok{]] >> }\DecValTok{0}
2643
+ \FunctionTok{puts}\NormalTok{ lst}\KeywordTok{[[}\VerbatimStringTok{\textquotesingle{}bool\textquotesingle{}}\KeywordTok{]][[}\DecValTok{1}\KeywordTok{]]} \OperatorTok{\textgreater{}\textgreater{}} \DecValTok{0}
2277
2644
  \end{Highlighting}
2278
2645
  \end{Shaded}
2279
2646
 
@@ -2292,16 +2659,16 @@ native Ruby type.
2292
2659
  A data frame is a table like structure in which each column has the same
2293
2660
  number of rows. Data frames are the basic structure for storing data for
2294
2661
  data analysis. We have already seen a data frame previously when we
2295
- accessed variable `\textasciitilde{}:mtcars'. In order to create a data
2662
+ accessed variable `\textasciitilde:mtcars'. In order to create a data
2296
2663
  frame, function 'data\_\_frame' is used:
2297
2664
 
2298
2665
  \begin{Shaded}
2299
2666
  \begin{Highlighting}[]
2300
- \NormalTok{df = R.data__frame(}
2301
- \StringTok{year: }\NormalTok{R.c(}\DecValTok{2010}\NormalTok{, }\DecValTok{2011}\NormalTok{, }\DecValTok{2012}\NormalTok{),}
2302
- \StringTok{income: }\NormalTok{R.c(}\FloatTok{1000.0}\NormalTok{, }\FloatTok{1500.0}\NormalTok{, }\FloatTok{2000.0}\NormalTok{))}
2667
+ \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}
2668
+ \WarningTok{year:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{2010}\NormalTok{, }\DecValTok{2011}\NormalTok{, }\DecValTok{2012}\NormalTok{),}
2669
+ \WarningTok{income:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{1000.0}\NormalTok{, }\FloatTok{1500.0}\NormalTok{, }\FloatTok{2000.0}\NormalTok{))}
2303
2670
 
2304
- \NormalTok{puts df}
2671
+ \FunctionTok{puts}\NormalTok{ df}
2305
2672
  \end{Highlighting}
2306
2673
  \end{Shaded}
2307
2674
 
@@ -2320,9 +2687,9 @@ the row or column
2320
2687
 
2321
2688
  \begin{Shaded}
2322
2689
  \begin{Highlighting}[]
2323
- \NormalTok{puts (~}\StringTok{:mtcars}\NormalTok{).head}
2324
- \NormalTok{puts (~}\StringTok{:mtcars}\NormalTok{)[}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{]}
2325
- \NormalTok{puts (~}\StringTok{:mtcars}\NormalTok{)[}\StringTok{'Datsun 710'}\NormalTok{, }\StringTok{'mpg'}\NormalTok{]}
2690
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.head}
2691
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\DecValTok{1}\NormalTok{, }\DecValTok{2}\KeywordTok{]}
2692
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\VerbatimStringTok{\textquotesingle{}Datsun 710\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\KeywordTok{]}
2326
2693
  \end{Highlighting}
2327
2694
  \end{Shaded}
2328
2695
 
@@ -2343,14 +2710,14 @@ the double square bracket operator:
2343
2710
 
2344
2711
  \begin{Shaded}
2345
2712
  \begin{Highlighting}[]
2346
- \NormalTok{puts (~}\StringTok{:mtcars}\NormalTok{)[[}\StringTok{'mpg'}\NormalTok{]]}
2713
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[[}\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\KeywordTok{]]}
2347
2714
  \end{Highlighting}
2348
2715
  \end{Shaded}
2349
2716
 
2350
2717
  \begin{verbatim}
2351
- ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2
2352
- ## [15] 10.4 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4
2353
- ## [29] 15.8 19.7 15.0 21.4
2718
+ ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
2719
+ ## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
2720
+ ## [31] 15.0 21.4
2354
2721
  \end{verbatim}
2355
2722
 
2356
2723
  A data frame column can also be accessed as if it were an instance
@@ -2358,14 +2725,14 @@ variable of the data frame:
2358
2725
 
2359
2726
  \begin{Shaded}
2360
2727
  \begin{Highlighting}[]
2361
- \NormalTok{puts (~}\StringTok{:mtcars}\NormalTok{).mpg}
2728
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.mpg}
2362
2729
  \end{Highlighting}
2363
2730
  \end{Shaded}
2364
2731
 
2365
2732
  \begin{verbatim}
2366
- ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2
2367
- ## [15] 10.4 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4
2368
- ## [29] 15.8 19.7 15.0 21.4
2733
+ ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
2734
+ ## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
2735
+ ## [31] 15.0 21.4
2369
2736
  \end{verbatim}
2370
2737
 
2371
2738
  Slicing a data frame can be done by indexing it with a vector (we use
@@ -2373,18 +2740,14 @@ Slicing a data frame can be done by indexing it with a vector (we use
2373
2740
 
2374
2741
  \begin{Shaded}
2375
2742
  \begin{Highlighting}[]
2376
- \NormalTok{puts (~}\StringTok{:mtcars}\NormalTok{)[R.c(}\StringTok{'mpg'}\NormalTok{, }\StringTok{'hp'}\NormalTok{)].head}
2743
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}hp\textquotesingle{}}\NormalTok{)}\KeywordTok{]}\AttributeTok{.head}
2377
2744
  \end{Highlighting}
2378
2745
  \end{Shaded}
2379
2746
 
2380
2747
  \begin{verbatim}
2381
- ## mpg hp
2382
- ## Mazda RX4 21.0 110
2383
- ## Mazda RX4 Wag 21.0 110
2384
- ## Datsun 710 22.8 93
2385
- ## Hornet 4 Drive 21.4 110
2386
- ## Hornet Sportabout 18.7 175
2387
- ## Valiant 18.1 105
2748
+ ## mpg cyl disp hp drat wt qsec vs am gear carb
2749
+ ## NA NA NA NA NA NA NA NA NA NA NA NA
2750
+ ## NA.1 NA NA NA NA NA NA NA NA NA NA NA
2388
2751
  \end{verbatim}
2389
2752
 
2390
2753
  A row slice can be obtained by indexing by row and using the `:all'
@@ -2392,7 +2755,7 @@ keyword for the column:
2392
2755
 
2393
2756
  \begin{Shaded}
2394
2757
  \begin{Highlighting}[]
2395
- \NormalTok{puts (~}\StringTok{:mtcars}\NormalTok{)[R.c(}\StringTok{'Datsun 710'}\NormalTok{, }\StringTok{'Camaro Z28'}\NormalTok{), }\StringTok{:all}\NormalTok{]}
2758
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}Datsun 710\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}Camaro Z28\textquotesingle{}}\NormalTok{), }\WarningTok{:all}\KeywordTok{]}
2396
2759
  \end{Highlighting}
2397
2760
  \end{Shaded}
2398
2761
 
@@ -2405,21 +2768,21 @@ keyword for the column:
2405
2768
  Finally, a data frame can also be indexed with a logical vector. In this
2406
2769
  next example, the `am' column of :mtcars is compared with 0 (with method
2407
2770
  `eq'). When `am' is equal to 0 the car is automatic. So, by doing
2408
- `(\textasciitilde{}:mtcars).am.eq 0' a logical vector is created with
2771
+ `(\textasciitilde:mtcars).am.eq 0' a logical vector is created with
2409
2772
  `true' whenever `am' is 0 and `false' otherwise.
2410
2773
 
2411
2774
  \begin{Shaded}
2412
2775
  \begin{Highlighting}[]
2413
- \CommentTok{# obtain a vector with 'true' for cars with automatic transmission}
2414
- \NormalTok{automatic = (~}\StringTok{:mtcars}\NormalTok{).am.eq }\DecValTok{0}
2415
- \NormalTok{puts automatic}
2776
+ \CommentTok{\# obtain a vector with \textquotesingle{}true\textquotesingle{} for cars with automatic transmission}
2777
+ \NormalTok{automatic }\OperatorTok{=}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.am.eq} \DecValTok{0}
2778
+ \FunctionTok{puts}\NormalTok{ automatic}
2416
2779
  \end{Highlighting}
2417
2780
  \end{Shaded}
2418
2781
 
2419
2782
  \begin{verbatim}
2420
- ## [1] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
2421
- ## [12] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE
2422
- ## [23] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
2783
+ ## [1] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
2784
+ ## [13] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE
2785
+ ## [25] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
2423
2786
  \end{verbatim}
2424
2787
 
2425
2788
  Using this logical vector, the data frame is indexed, returning a new
@@ -2427,8 +2790,8 @@ data frame in which all cars have automatic transmission.
2427
2790
 
2428
2791
  \begin{Shaded}
2429
2792
  \begin{Highlighting}[]
2430
- \CommentTok{# slice the data frame by using this vector}
2431
- \NormalTok{puts (~}\StringTok{:mtcars}\NormalTok{)[automatic, }\StringTok{:all}\NormalTok{]}
2793
+ \CommentTok{\# slice the data frame by using this vector}
2794
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\NormalTok{automatic, }\WarningTok{:all}\KeywordTok{]}
2432
2795
  \end{Highlighting}
2433
2796
  \end{Shaded}
2434
2797
 
@@ -2465,12 +2828,12 @@ a look at some of those expressions.
2465
2828
  \subsection{Expressions from
2466
2829
  operators}\label{expressions-from-operators}
2467
2830
 
2468
- The code bellow creates an expression summing two symbols
2831
+ The code below creates an expression summing two symbols
2469
2832
 
2470
2833
  \begin{Shaded}
2471
2834
  \begin{Highlighting}[]
2472
- \NormalTok{exp1 = }\StringTok{:a}\NormalTok{ + }\StringTok{:b}
2473
- \NormalTok{puts exp1}
2835
+ \NormalTok{exp1 }\OperatorTok{=} \WarningTok{:a} \OperatorTok{+} \WarningTok{:b}
2836
+ \FunctionTok{puts}\NormalTok{ exp1}
2474
2837
  \end{Highlighting}
2475
2838
  \end{Shaded}
2476
2839
 
@@ -2482,21 +2845,21 @@ We can build any complex mathematical expression
2482
2845
 
2483
2846
  \begin{Shaded}
2484
2847
  \begin{Highlighting}[]
2485
- \NormalTok{exp2 = (}\StringTok{:a}\NormalTok{ + }\StringTok{:b}\NormalTok{) * }\FloatTok{2.0}\NormalTok{ + }\StringTok{:c}\NormalTok{ ** }\DecValTok{2}\NormalTok{ / }\StringTok{:z}
2486
- \NormalTok{puts exp2}
2848
+ \NormalTok{exp2 }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{) }\OperatorTok{*} \FloatTok{2.0} \OperatorTok{+} \WarningTok{:c} \OperatorTok{**} \DecValTok{2} \OperatorTok{/} \WarningTok{:z}
2849
+ \FunctionTok{puts}\NormalTok{ exp2}
2487
2850
  \end{Highlighting}
2488
2851
  \end{Shaded}
2489
2852
 
2490
2853
  \begin{verbatim}
2491
- ## (a + b) * 2 + c^2L/z
2854
+ ## a + b * 2.0 + c ^ 2L / z
2492
2855
  \end{verbatim}
2493
2856
 
2494
2857
  It is also possible to use inequality operators in building expressions
2495
2858
 
2496
2859
  \begin{Shaded}
2497
2860
  \begin{Highlighting}[]
2498
- \NormalTok{exp3 = (}\StringTok{:a}\NormalTok{ + }\StringTok{:b}\NormalTok{) >= }\StringTok{:z}
2499
- \NormalTok{puts exp3}
2861
+ \NormalTok{exp3 }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{) }\OperatorTok{\textgreater{}=} \WarningTok{:z}
2862
+ \FunctionTok{puts}\NormalTok{ exp3}
2500
2863
  \end{Highlighting}
2501
2864
  \end{Shaded}
2502
2865
 
@@ -2505,14 +2868,14 @@ It is also possible to use inequality operators in building expressions
2505
2868
  \end{verbatim}
2506
2869
 
2507
2870
  Galaaz provides both symbolic representations for operators, such as
2508
- (\textgreater{}, \textless{}, !=) as functional notation for those
2509
- operators such as (.gt, .ge, etc.). So the same expression written above
2510
- can also be written as
2871
+ (\textgreater, \textless, !=) as functional notation for those operators
2872
+ such as (.gt, .ge, etc.). So the same expression written above can also
2873
+ be written as
2511
2874
 
2512
2875
  \begin{Shaded}
2513
2876
  \begin{Highlighting}[]
2514
- \NormalTok{exp4 = (}\StringTok{:a}\NormalTok{ + }\StringTok{:b}\NormalTok{).ge }\StringTok{:z}
2515
- \NormalTok{puts exp4}
2877
+ \NormalTok{exp4 }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{)}\AttributeTok{.ge} \OperatorTok{:}\NormalTok{z}
2878
+ \FunctionTok{puts}\NormalTok{ exp4}
2516
2879
  \end{Highlighting}
2517
2880
  \end{Shaded}
2518
2881
 
@@ -2527,8 +2890,8 @@ the method `.eq' and for `=' we need the function `.assign'
2527
2890
 
2528
2891
  \begin{Shaded}
2529
2892
  \begin{Highlighting}[]
2530
- \NormalTok{exp5 = (}\StringTok{:a}\NormalTok{ + }\StringTok{:b}\NormalTok{).eq }\StringTok{:z}
2531
- \NormalTok{puts exp5}
2893
+ \NormalTok{exp5 }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{)}\AttributeTok{.eq} \OperatorTok{:}\NormalTok{z}
2894
+ \FunctionTok{puts}\NormalTok{ exp5}
2532
2895
  \end{Highlighting}
2533
2896
  \end{Shaded}
2534
2897
 
@@ -2538,8 +2901,8 @@ the method `.eq' and for `=' we need the function `.assign'
2538
2901
 
2539
2902
  \begin{Shaded}
2540
2903
  \begin{Highlighting}[]
2541
- \NormalTok{exp6 = }\StringTok{:y}\NormalTok{.assign }\StringTok{:a}\NormalTok{ + }\StringTok{:b}
2542
- \NormalTok{puts exp6}
2904
+ \NormalTok{exp6 }\OperatorTok{=} \WarningTok{:y}\AttributeTok{.assign} \OperatorTok{:}\NormalTok{a }\OperatorTok{+} \WarningTok{:b}
2905
+ \FunctionTok{puts}\NormalTok{ exp6}
2543
2906
  \end{Highlighting}
2544
2907
  \end{Shaded}
2545
2908
 
@@ -2553,8 +2916,8 @@ expressions such as
2553
2916
 
2554
2917
  \begin{Shaded}
2555
2918
  \begin{Highlighting}[]
2556
- \NormalTok{exp_wrong = (}\StringTok{:a}\NormalTok{ + }\StringTok{:b}\NormalTok{) == }\StringTok{:z}
2557
- \NormalTok{puts exp_wrong}
2919
+ \NormalTok{exp\_wrong }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{) }\OperatorTok{==} \WarningTok{:z}
2920
+ \FunctionTok{puts}\NormalTok{ exp\_wrong}
2558
2921
  \end{Highlighting}
2559
2922
  \end{Shaded}
2560
2923
 
@@ -2580,8 +2943,8 @@ such as `E.sin(x)'
2580
2943
 
2581
2944
  \begin{Shaded}
2582
2945
  \begin{Highlighting}[]
2583
- \NormalTok{exp7 = }\StringTok{:y}\NormalTok{.assign E.sin(}\StringTok{:x}\NormalTok{)}
2584
- \NormalTok{puts exp7}
2946
+ \NormalTok{exp7 }\OperatorTok{=} \WarningTok{:y}\AttributeTok{.assign} \ConstantTok{E}\AttributeTok{.sin}\NormalTok{(}\WarningTok{:x}\NormalTok{)}
2947
+ \FunctionTok{puts}\NormalTok{ exp7}
2585
2948
  \end{Highlighting}
2586
2949
  \end{Shaded}
2587
2950
 
@@ -2593,8 +2956,8 @@ Expressions can also be written using `.' notation:
2593
2956
 
2594
2957
  \begin{Shaded}
2595
2958
  \begin{Highlighting}[]
2596
- \NormalTok{exp8 = }\StringTok{:y}\NormalTok{.assign }\StringTok{:x}\NormalTok{.sin}
2597
- \NormalTok{puts exp8}
2959
+ \NormalTok{exp8 }\OperatorTok{=} \WarningTok{:y}\AttributeTok{.assign} \OperatorTok{:}\NormalTok{x}\AttributeTok{.sin}
2960
+ \FunctionTok{puts}\NormalTok{ exp8}
2598
2961
  \end{Highlighting}
2599
2962
  \end{Shaded}
2600
2963
 
@@ -2607,8 +2970,8 @@ the `.':
2607
2970
 
2608
2971
  \begin{Shaded}
2609
2972
  \begin{Highlighting}[]
2610
- \NormalTok{exp9 = }\StringTok{:x}\NormalTok{.c(}\StringTok{:y}\NormalTok{)}
2611
- \NormalTok{puts exp9}
2973
+ \NormalTok{exp9 }\OperatorTok{=} \WarningTok{:x}\AttributeTok{.c}\NormalTok{(}\WarningTok{:y}\NormalTok{)}
2974
+ \FunctionTok{puts}\NormalTok{ exp9}
2612
2975
  \end{Highlighting}
2613
2976
  \end{Shaded}
2614
2977
 
@@ -2623,37 +2986,37 @@ A binding can be provided with a list:
2623
2986
 
2624
2987
  \begin{Shaded}
2625
2988
  \begin{Highlighting}[]
2626
- \NormalTok{exp = (}\StringTok{:a}\NormalTok{ + }\StringTok{:b}\NormalTok{) * }\FloatTok{2.0}\NormalTok{ + }\StringTok{:c}\NormalTok{ ** }\DecValTok{2}\NormalTok{ / }\StringTok{:z}
2627
- \NormalTok{puts exp.eval(R.list(}\StringTok{a: }\DecValTok{10}\NormalTok{, }\StringTok{b: }\DecValTok{20}\NormalTok{, }\StringTok{c: }\DecValTok{30}\NormalTok{, }\StringTok{z: }\DecValTok{40}\NormalTok{))}
2989
+ \NormalTok{exp }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{) }\OperatorTok{*} \FloatTok{2.0} \OperatorTok{+} \WarningTok{:c} \OperatorTok{**} \DecValTok{2} \OperatorTok{/} \WarningTok{:z}
2990
+ \FunctionTok{puts}\NormalTok{ exp}\AttributeTok{.eval}\NormalTok{(}\ConstantTok{R}\AttributeTok{.list}\NormalTok{(}\WarningTok{a:} \DecValTok{10}\NormalTok{, }\WarningTok{b:} \DecValTok{20}\NormalTok{, }\WarningTok{c:} \DecValTok{30}\NormalTok{, }\WarningTok{z:} \DecValTok{40}\NormalTok{))}
2628
2991
  \end{Highlighting}
2629
2992
  \end{Shaded}
2630
2993
 
2631
2994
  \begin{verbatim}
2632
- ## [1] 82.5
2995
+ ## [1] 72.5
2633
2996
  \end{verbatim}
2634
2997
 
2635
2998
  \ldots{} with a data frame:
2636
2999
 
2637
3000
  \begin{Shaded}
2638
3001
  \begin{Highlighting}[]
2639
- \NormalTok{df = R.data__frame(}
2640
- \StringTok{a: }\NormalTok{R.c(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{),}
2641
- \StringTok{b: }\NormalTok{R.c(}\DecValTok{10}\NormalTok{, }\DecValTok{20}\NormalTok{, }\DecValTok{30}\NormalTok{),}
2642
- \StringTok{c: }\NormalTok{R.c(}\DecValTok{100}\NormalTok{, }\DecValTok{200}\NormalTok{, }\DecValTok{300}\NormalTok{),}
2643
- \StringTok{z: }\NormalTok{R.c(}\DecValTok{1000}\NormalTok{, }\DecValTok{2000}\NormalTok{, }\DecValTok{3000}\NormalTok{))}
3002
+ \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}
3003
+ \WarningTok{a:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{),}
3004
+ \WarningTok{b:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{20}\NormalTok{, }\DecValTok{30}\NormalTok{),}
3005
+ \WarningTok{c:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{200}\NormalTok{, }\DecValTok{300}\NormalTok{),}
3006
+ \WarningTok{z:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1000}\NormalTok{, }\DecValTok{2000}\NormalTok{, }\DecValTok{3000}\NormalTok{))}
2644
3007
 
2645
- \NormalTok{puts exp.eval(df)}
3008
+ \FunctionTok{puts}\NormalTok{ exp}\AttributeTok{.eval}\NormalTok{(df)}
2646
3009
  \end{Highlighting}
2647
3010
  \end{Shaded}
2648
3011
 
2649
3012
  \begin{verbatim}
2650
- ## [1] 32 64 96
3013
+ ## [1] 31 62 93
2651
3014
  \end{verbatim}
2652
3015
 
2653
3016
  \section{Manipulating Data}\label{manipulating-data}
2654
3017
 
2655
3018
  One of the major benefits of Galaaz is to bring strong data manipulation
2656
- to Ruby. The following examples were extracted from Hardley's ``R for
3019
+ to Ruby. The following examples were extracted from Hadley's ``R for
2657
3020
  Data Science'' (\url{https://r4ds.had.co.nz/}). This is a highly
2658
3021
  recommended book for those not already familiar with the `tidyverse'
2659
3022
  style of programming in R. In the sections to follow, we will limit
@@ -2666,39 +3029,38 @@ and if not, installs it. This data frame contains all 336,776 flights
2666
3029
  that departed from New York City in 2013. The data comes from the US
2667
3030
  Bureau of Transportation Statistics.
2668
3031
 
2669
- Dplyr uses `tibbles' in place of data frames; unfortunately, tibbles do
2670
- not print yet properly in Galaaz due to a bug in fastR. In order to
2671
- print a tibble we need to convert it to a data frame using the
2672
- 'as\_\_data\_\_frame' method.
3032
+ Dplyr often uses \textbf{tibbles} in place of classic data frames. In
3033
+ Galaaz, printing may differ from the R console; if you need a classic
3034
+ tabular printout, convert with \textbf{\texttt{as\_\_data\_\_frame}} (or
3035
+ use \texttt{head} / \texttt{str} in R via \texttt{R} calls).
2673
3036
 
2674
3037
  \begin{Shaded}
2675
3038
  \begin{Highlighting}[]
2676
- \NormalTok{R.install_and_loads(}\StringTok{'nycflights13'}\NormalTok{)}
2677
- \NormalTok{R.library(}\StringTok{'dplyr'}\NormalTok{)}
3039
+ \ConstantTok{R}\AttributeTok{.install\_and\_loads}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}nycflights13\textquotesingle{}}\NormalTok{)}
3040
+ \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}dplyr\textquotesingle{}}\NormalTok{)}
2678
3041
  \end{Highlighting}
2679
3042
  \end{Shaded}
2680
3043
 
2681
3044
  \begin{Shaded}
2682
3045
  \begin{Highlighting}[]
2683
- \NormalTok{flights = ~}\StringTok{:flights}
2684
- \NormalTok{puts flights.head}
3046
+ \NormalTok{flights }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:flights}
3047
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.head}
2685
3048
  \end{Highlighting}
2686
3049
  \end{Shaded}
2687
3050
 
2688
3051
  \begin{verbatim}
2689
3052
  ## # A tibble: 6 x 19
2690
- ## year month day dep_time sched_dep_time dep_delay arr_time
2691
- ## <int> <int> <int> <int> <int> <dbl> <int>
2692
- ## 1 2013 1 1 517 515 2 830
2693
- ## 2 2013 1 1 533 529 4 850
2694
- ## 3 2013 1 1 542 540 2 923
2695
- ## 4 2013 1 1 544 545 -1 1004
2696
- ## 5 2013 1 1 554 600 -6 812
2697
- ## 6 2013 1 1 554 558 -4 740
2698
- ## # ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
2699
- ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,
2700
- ## # air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,
2701
- ## # time_hour <dttm>
3053
+ ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3054
+ ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3055
+ ## 1 2013 1 1 517 515 2 830 819
3056
+ ## 2 2013 1 1 533 529 4 850 830
3057
+ ## 3 2013 1 1 542 540 2 923 850
3058
+ ## 4 2013 1 1 544 545 -1 1004 1022
3059
+ ## 5 2013 1 1 554 600 -6 812 837
3060
+ ## 6 2013 1 1 554 558 -4 740 728
3061
+ ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3062
+ ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3063
+ ## # hour <dbl>, minute <dbl>, time_hour <dttm>
2702
3064
  \end{verbatim}
2703
3065
 
2704
3066
  \subsection{Filtering rows with
@@ -2709,24 +3071,23 @@ function two expressions: the first :month.eq 1
2709
3071
 
2710
3072
  \begin{Shaded}
2711
3073
  \begin{Highlighting}[]
2712
- \NormalTok{puts flights.filter((}\StringTok{:month}\NormalTok{.eq }\DecValTok{1}\NormalTok{), (}\StringTok{:day}\NormalTok{.eq }\DecValTok{1}\NormalTok{)).head}
3074
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{((}\WarningTok{:month}\AttributeTok{.eq} \DecValTok{1}\NormalTok{), (}\WarningTok{:day}\AttributeTok{.eq} \DecValTok{1}\NormalTok{))}\AttributeTok{.head}
2713
3075
  \end{Highlighting}
2714
3076
  \end{Shaded}
2715
3077
 
2716
3078
  \begin{verbatim}
2717
3079
  ## # A tibble: 6 x 19
2718
- ## year month day dep_time sched_dep_time dep_delay arr_time
2719
- ## <int> <int> <int> <int> <int> <dbl> <int>
2720
- ## 1 2013 1 1 517 515 2 830
2721
- ## 2 2013 1 1 533 529 4 850
2722
- ## 3 2013 1 1 542 540 2 923
2723
- ## 4 2013 1 1 544 545 -1 1004
2724
- ## 5 2013 1 1 554 600 -6 812
2725
- ## 6 2013 1 1 554 558 -4 740
2726
- ## # ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
2727
- ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,
2728
- ## # air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,
2729
- ## # time_hour <dttm>
3080
+ ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3081
+ ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3082
+ ## 1 2013 1 1 517 515 2 830 819
3083
+ ## 2 2013 1 1 533 529 4 850 830
3084
+ ## 3 2013 1 1 542 540 2 923 850
3085
+ ## 4 2013 1 1 544 545 -1 1004 1022
3086
+ ## 5 2013 1 1 554 600 -6 812 837
3087
+ ## 6 2013 1 1 554 558 -4 740 728
3088
+ ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3089
+ ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3090
+ ## # hour <dbl>, minute <dbl>, time_hour <dttm>
2730
3091
  \end{verbatim}
2731
3092
 
2732
3093
  \subsection{Logical Operators}\label{logical-operators}
@@ -2735,52 +3096,50 @@ All flights that departed in November of December
2735
3096
 
2736
3097
  \begin{Shaded}
2737
3098
  \begin{Highlighting}[]
2738
- \NormalTok{puts flights.filter((}\StringTok{:month}\NormalTok{.eq }\DecValTok{11}\NormalTok{) | (}\StringTok{:month}\NormalTok{.eq }\DecValTok{12}\NormalTok{)).head}
3099
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{((}\WarningTok{:month}\AttributeTok{.eq} \DecValTok{11}\NormalTok{) }\OperatorTok{|}\NormalTok{ (}\WarningTok{:month}\AttributeTok{.eq} \DecValTok{12}\NormalTok{))}\AttributeTok{.head}
2739
3100
  \end{Highlighting}
2740
3101
  \end{Shaded}
2741
3102
 
2742
3103
  \begin{verbatim}
2743
3104
  ## # A tibble: 6 x 19
2744
- ## year month day dep_time sched_dep_time dep_delay arr_time
2745
- ## <int> <int> <int> <int> <int> <dbl> <int>
2746
- ## 1 2013 11 1 5 2359 6 352
2747
- ## 2 2013 11 1 35 2250 105 123
2748
- ## 3 2013 11 1 455 500 -5 641
2749
- ## 4 2013 11 1 539 545 -6 856
2750
- ## 5 2013 11 1 542 545 -3 831
2751
- ## 6 2013 11 1 549 600 -11 912
2752
- ## # ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
2753
- ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,
2754
- ## # air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,
2755
- ## # time_hour <dttm>
3105
+ ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3106
+ ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3107
+ ## 1 2013 11 1 5 2359 6 352 345
3108
+ ## 2 2013 11 1 35 2250 105 123 2356
3109
+ ## 3 2013 11 1 455 500 -5 641 651
3110
+ ## 4 2013 11 1 539 545 -6 856 827
3111
+ ## 5 2013 11 1 542 545 -3 831 855
3112
+ ## 6 2013 11 1 549 600 -11 912 923
3113
+ ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3114
+ ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3115
+ ## # hour <dbl>, minute <dbl>, time_hour <dttm>
2756
3116
  \end{verbatim}
2757
3117
 
2758
3118
  The same as above, but using the `in' operator. In R, it is possible to
2759
3119
  define many operators by doing \%\%. The \%in\% operator checks if a
2760
3120
  value is in a vector. In order to use those operators from Galaaz the
2761
- '.\_`method is used, where the first argument is the operator's symbol,
2762
- in this case':in' and the second argument is the vector:
3121
+ `.\_' method is used, where the first argument is the operator's symbol,
3122
+ in this case `:in' and the second argument is the vector:
2763
3123
 
2764
3124
  \begin{Shaded}
2765
3125
  \begin{Highlighting}[]
2766
- \NormalTok{puts flights.filter(}\StringTok{:month}\NormalTok{._ }\StringTok{:in}\NormalTok{, R.c(}\DecValTok{11}\NormalTok{, }\DecValTok{12}\NormalTok{)).head}
3126
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{(}\WarningTok{:month}\AttributeTok{.\_} \OperatorTok{:}\ControlFlowTok{in}\NormalTok{, }\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{11}\NormalTok{, }\DecValTok{12}\NormalTok{))}\AttributeTok{.head}
2767
3127
  \end{Highlighting}
2768
3128
  \end{Shaded}
2769
3129
 
2770
3130
  \begin{verbatim}
2771
3131
  ## # A tibble: 6 x 19
2772
- ## year month day dep_time sched_dep_time dep_delay arr_time
2773
- ## <int> <int> <int> <int> <int> <dbl> <int>
2774
- ## 1 2013 11 1 5 2359 6 352
2775
- ## 2 2013 11 1 35 2250 105 123
2776
- ## 3 2013 11 1 455 500 -5 641
2777
- ## 4 2013 11 1 539 545 -6 856
2778
- ## 5 2013 11 1 542 545 -3 831
2779
- ## 6 2013 11 1 549 600 -11 912
2780
- ## # ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
2781
- ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,
2782
- ## # air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,
2783
- ## # time_hour <dttm>
3132
+ ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3133
+ ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3134
+ ## 1 2013 11 1 5 2359 6 352 345
3135
+ ## 2 2013 11 1 35 2250 105 123 2356
3136
+ ## 3 2013 11 1 455 500 -5 641 651
3137
+ ## 4 2013 11 1 539 545 -6 856 827
3138
+ ## 5 2013 11 1 542 545 -3 831 855
3139
+ ## 6 2013 11 1 549 600 -11 912 923
3140
+ ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3141
+ ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3142
+ ## # hour <dbl>, minute <dbl>, time_hour <dttm>
2784
3143
  \end{verbatim}
2785
3144
 
2786
3145
  \subsection{Filtering with NA (Not
@@ -2794,8 +3153,8 @@ from data frame.
2794
3153
 
2795
3154
  \begin{Shaded}
2796
3155
  \begin{Highlighting}[]
2797
- \NormalTok{df = R.tibble(}\StringTok{x: }\NormalTok{R.c(}\DecValTok{1}\NormalTok{, R::}\DataTypeTok{NA}\NormalTok{, }\DecValTok{3}\NormalTok{))}
2798
- \NormalTok{puts df}
3156
+ \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.tibble}\NormalTok{(}\WarningTok{x:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\ConstantTok{R}\OperatorTok{::}\ConstantTok{NA}\NormalTok{, }\DecValTok{3}\NormalTok{))}
3157
+ \FunctionTok{puts}\NormalTok{ df}
2799
3158
  \end{Highlighting}
2800
3159
  \end{Shaded}
2801
3160
 
@@ -2804,7 +3163,7 @@ from data frame.
2804
3163
  ## x
2805
3164
  ## <int>
2806
3165
  ## 1 1
2807
- ## 2
3166
+ ## 2 NA
2808
3167
  ## 3 3
2809
3168
  \end{verbatim}
2810
3169
 
@@ -2813,7 +3172,7 @@ condition, where the row with R:NA does not.
2813
3172
 
2814
3173
  \begin{Shaded}
2815
3174
  \begin{Highlighting}[]
2816
- \NormalTok{puts df.filter(}\StringTok{:x}\NormalTok{ > }\DecValTok{1}\NormalTok{)}
3175
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\WarningTok{:x} \OperatorTok{\textgreater{}} \DecValTok{1}\NormalTok{)}
2817
3176
  \end{Highlighting}
2818
3177
  \end{Shaded}
2819
3178
 
@@ -2828,7 +3187,7 @@ To match an NA use method 'is\_\_na'
2828
3187
 
2829
3188
  \begin{Shaded}
2830
3189
  \begin{Highlighting}[]
2831
- \NormalTok{puts df.filter((}\StringTok{:x}\NormalTok{.is__na) | (}\StringTok{:x}\NormalTok{ > }\DecValTok{1}\NormalTok{))}
3190
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{((}\WarningTok{:x}\AttributeTok{.is\_\_na}\NormalTok{) }\OperatorTok{|}\NormalTok{ (}\WarningTok{:x} \OperatorTok{\textgreater{}} \DecValTok{1}\NormalTok{))}
2832
3191
  \end{Highlighting}
2833
3192
  \end{Shaded}
2834
3193
 
@@ -2836,7 +3195,7 @@ To match an NA use method 'is\_\_na'
2836
3195
  ## # A tibble: 2 x 1
2837
3196
  ## x
2838
3197
  ## <int>
2839
- ## 1
3198
+ ## 1 NA
2840
3199
  ## 2 3
2841
3200
  \end{verbatim}
2842
3201
 
@@ -2846,48 +3205,46 @@ Arrange reorders the rows of a data frame by the given arguments.
2846
3205
 
2847
3206
  \begin{Shaded}
2848
3207
  \begin{Highlighting}[]
2849
- \NormalTok{puts flights.arrange(}\StringTok{:year}\NormalTok{, }\StringTok{:month}\NormalTok{, }\StringTok{:day}\NormalTok{).head}
3208
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.arrange}\NormalTok{(}\WarningTok{:year}\NormalTok{, }\WarningTok{:month}\NormalTok{, }\WarningTok{:day}\NormalTok{)}\AttributeTok{.head}
2850
3209
  \end{Highlighting}
2851
3210
  \end{Shaded}
2852
3211
 
2853
3212
  \begin{verbatim}
2854
3213
  ## # A tibble: 6 x 19
2855
- ## year month day dep_time sched_dep_time dep_delay arr_time
2856
- ## <int> <int> <int> <int> <int> <dbl> <int>
2857
- ## 1 2013 1 1 517 515 2 830
2858
- ## 2 2013 1 1 533 529 4 850
2859
- ## 3 2013 1 1 542 540 2 923
2860
- ## 4 2013 1 1 544 545 -1 1004
2861
- ## 5 2013 1 1 554 600 -6 812
2862
- ## 6 2013 1 1 554 558 -4 740
2863
- ## # ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
2864
- ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,
2865
- ## # air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,
2866
- ## # time_hour <dttm>
3214
+ ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3215
+ ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3216
+ ## 1 2013 1 1 517 515 2 830 819
3217
+ ## 2 2013 1 1 533 529 4 850 830
3218
+ ## 3 2013 1 1 542 540 2 923 850
3219
+ ## 4 2013 1 1 544 545 -1 1004 1022
3220
+ ## 5 2013 1 1 554 600 -6 812 837
3221
+ ## 6 2013 1 1 554 558 -4 740 728
3222
+ ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3223
+ ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3224
+ ## # hour <dbl>, minute <dbl>, time_hour <dttm>
2867
3225
  \end{verbatim}
2868
3226
 
2869
3227
  To arrange in descending order, use function `desc'
2870
3228
 
2871
3229
  \begin{Shaded}
2872
3230
  \begin{Highlighting}[]
2873
- \NormalTok{puts flights.arrange(}\StringTok{:dep_delay}\NormalTok{.desc).head}
3231
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.arrange}\NormalTok{(}\WarningTok{:dep\_delay}\AttributeTok{.desc}\NormalTok{)}\AttributeTok{.head}
2874
3232
  \end{Highlighting}
2875
3233
  \end{Shaded}
2876
3234
 
2877
3235
  \begin{verbatim}
2878
3236
  ## # A tibble: 6 x 19
2879
- ## year month day dep_time sched_dep_time dep_delay arr_time
2880
- ## <int> <int> <int> <int> <int> <dbl> <int>
2881
- ## 1 2013 1 9 641 900 1301 1242
2882
- ## 2 2013 6 15 1432 1935 1137 1607
2883
- ## 3 2013 1 10 1121 1635 1126 1239
2884
- ## 4 2013 9 20 1139 1845 1014 1457
2885
- ## 5 2013 7 22 845 1600 1005 1044
2886
- ## 6 2013 4 10 1100 1900 960 1342
2887
- ## # ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
2888
- ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,
2889
- ## # air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,
2890
- ## # time_hour <dttm>
3237
+ ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3238
+ ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3239
+ ## 1 2013 1 9 641 900 1301 1242 1530
3240
+ ## 2 2013 6 15 1432 1935 1137 1607 2120
3241
+ ## 3 2013 1 10 1121 1635 1126 1239 1810
3242
+ ## 4 2013 9 20 1139 1845 1014 1457 2210
3243
+ ## 5 2013 7 22 845 1600 1005 1044 1815
3244
+ ## 6 2013 4 10 1100 1900 960 1342 2211
3245
+ ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3246
+ ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3247
+ ## # hour <dbl>, minute <dbl>, time_hour <dttm>
2891
3248
  \end{verbatim}
2892
3249
 
2893
3250
  \subsection{Selecting columns}\label{selecting-columns}
@@ -2896,7 +3253,7 @@ To select specific columns from a dataset we use function `select':
2896
3253
 
2897
3254
  \begin{Shaded}
2898
3255
  \begin{Highlighting}[]
2899
- \NormalTok{puts flights.select(}\StringTok{:year}\NormalTok{, }\StringTok{:month}\NormalTok{, }\StringTok{:day}\NormalTok{).head}
3256
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.select}\NormalTok{(}\WarningTok{:year}\NormalTok{, }\WarningTok{:month}\NormalTok{, }\WarningTok{:day}\NormalTok{)}\AttributeTok{.head}
2900
3257
  \end{Highlighting}
2901
3258
  \end{Shaded}
2902
3259
 
@@ -2916,7 +3273,7 @@ It is also possible to select column in a given range
2916
3273
 
2917
3274
  \begin{Shaded}
2918
3275
  \begin{Highlighting}[]
2919
- \NormalTok{puts flights.select(}\StringTok{:year}\NormalTok{.up_to }\StringTok{:day}\NormalTok{).head}
3276
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.select}\NormalTok{(}\WarningTok{:year}\AttributeTok{.up\_to} \OperatorTok{:}\NormalTok{day)}\AttributeTok{.head}
2920
3277
  \end{Highlighting}
2921
3278
  \end{Shaded}
2922
3279
 
@@ -2936,7 +3293,7 @@ Select all columns that start with a given name sequence
2936
3293
 
2937
3294
  \begin{Shaded}
2938
3295
  \begin{Highlighting}[]
2939
- \NormalTok{puts flights.select(E.starts_with(}\StringTok{'arr'}\NormalTok{)).head}
3296
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.select}\NormalTok{(}\ConstantTok{E}\AttributeTok{.starts\_with}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}arr\textquotesingle{}}\NormalTok{))}\AttributeTok{.head}
2940
3297
  \end{Highlighting}
2941
3298
  \end{Shaded}
2942
3299
 
@@ -2960,7 +3317,7 @@ Other functions that can be used:
2960
3317
  \item
2961
3318
  contains(``ijk''): matches names that contain ``ijk''.
2962
3319
  \item
2963
- matches(``(.)\textbackslash{}1''): selects variables that match a
3320
+ matches(``(.)\textbackslash1''): selects variables that match a
2964
3321
  regular expression. This one matches any variables that contain
2965
3322
  repeated characters.
2966
3323
  \item
@@ -2972,38 +3329,37 @@ column order is `Everything':
2972
3329
 
2973
3330
  \begin{Shaded}
2974
3331
  \begin{Highlighting}[]
2975
- \NormalTok{puts flights.select(}\StringTok{:year}\NormalTok{, }\StringTok{:month}\NormalTok{, }\StringTok{:day}\NormalTok{, E.everything).head}
3332
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.select}\NormalTok{(}\WarningTok{:year}\NormalTok{, }\WarningTok{:month}\NormalTok{, }\WarningTok{:day}\NormalTok{, }\ConstantTok{E}\AttributeTok{.everything}\NormalTok{)}\AttributeTok{.head}
2976
3333
  \end{Highlighting}
2977
3334
  \end{Shaded}
2978
3335
 
2979
3336
  \begin{verbatim}
2980
3337
  ## # A tibble: 6 x 19
2981
- ## year month day dep_time sched_dep_time dep_delay arr_time
2982
- ## <int> <int> <int> <int> <int> <dbl> <int>
2983
- ## 1 2013 1 1 517 515 2 830
2984
- ## 2 2013 1 1 533 529 4 850
2985
- ## 3 2013 1 1 542 540 2 923
2986
- ## 4 2013 1 1 544 545 -1 1004
2987
- ## 5 2013 1 1 554 600 -6 812
2988
- ## 6 2013 1 1 554 558 -4 740
2989
- ## # ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
2990
- ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,
2991
- ## # air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,
2992
- ## # time_hour <dttm>
2993
- \end{verbatim}
2994
-
2995
- \subsection{\texorpdfstring{Add variables to a dataframe with
2996
- `mutate'}{Add variables to a dataframe with mutate}}\label{add-variables-to-a-dataframe-with-mutate}
3338
+ ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3339
+ ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3340
+ ## 1 2013 1 1 517 515 2 830 819
3341
+ ## 2 2013 1 1 533 529 4 850 830
3342
+ ## 3 2013 1 1 542 540 2 923 850
3343
+ ## 4 2013 1 1 544 545 -1 1004 1022
3344
+ ## 5 2013 1 1 554 600 -6 812 837
3345
+ ## 6 2013 1 1 554 558 -4 740 728
3346
+ ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3347
+ ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3348
+ ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3349
+ \end{verbatim}
3350
+
3351
+ \subsection{Add variables to a dataframe with
3352
+ `mutate'}\label{add-variables-to-a-dataframe-with-mutate}
2997
3353
 
2998
3354
  \begin{Shaded}
2999
3355
  \begin{Highlighting}[]
3000
- \NormalTok{flights_sm = flights.}
3001
- \NormalTok{ select((}\StringTok{:year}\NormalTok{.up_to }\StringTok{:day}\NormalTok{),}
3002
- \NormalTok{ E.ends_with(}\StringTok{'delay'}\NormalTok{),}
3003
- \StringTok{:distance}\NormalTok{,}
3004
- \StringTok{:air_time}\NormalTok{)}
3356
+ \NormalTok{flights\_sm }\OperatorTok{=}\NormalTok{ flights}\AttributeTok{.}
3357
+ \AttributeTok{select}\NormalTok{((}\WarningTok{:year}\AttributeTok{.up\_to} \OperatorTok{:}\NormalTok{day),}
3358
+ \ConstantTok{E}\AttributeTok{.ends\_with}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}delay\textquotesingle{}}\NormalTok{),}
3359
+ \WarningTok{:distance}\NormalTok{,}
3360
+ \WarningTok{:air\_time}\NormalTok{)}
3005
3361
 
3006
- \NormalTok{puts flights_sm.head}
3362
+ \FunctionTok{puts}\NormalTok{ flights\_sm}\AttributeTok{.head}
3007
3363
  \end{Highlighting}
3008
3364
  \end{Shaded}
3009
3365
 
@@ -3021,10 +3377,10 @@ column order is `Everything':
3021
3377
 
3022
3378
  \begin{Shaded}
3023
3379
  \begin{Highlighting}[]
3024
- \NormalTok{flights_sm = flights_sm.}
3025
- \NormalTok{ mutate(}\StringTok{gain: :dep_delay}\NormalTok{ - }\StringTok{:arr_delay}\NormalTok{,}
3026
- \StringTok{speed: :distance}\NormalTok{ / }\StringTok{:air_time}\NormalTok{ * }\DecValTok{60}\NormalTok{)}
3027
- \NormalTok{puts flights_sm.head}
3380
+ \NormalTok{flights\_sm }\OperatorTok{=}\NormalTok{ flights\_sm}\AttributeTok{.}
3381
+ \AttributeTok{mutate}\NormalTok{(}\WarningTok{gain:} \WarningTok{:dep\_delay} \OperatorTok{{-}} \WarningTok{:arr\_delay}\NormalTok{,}
3382
+ \WarningTok{speed:} \WarningTok{:distance} \OperatorTok{/} \WarningTok{:air\_time} \OperatorTok{*} \DecValTok{60}\NormalTok{)}
3383
+ \FunctionTok{puts}\NormalTok{ flights\_sm}\AttributeTok{.head}
3028
3384
  \end{Highlighting}
3029
3385
  \end{Shaded}
3030
3386
 
@@ -3047,7 +3403,7 @@ Function `summarise' calculates summaries for the data frame. When no
3047
3403
 
3048
3404
  \begin{Shaded}
3049
3405
  \begin{Highlighting}[]
3050
- \NormalTok{puts flights.summarise(}\StringTok{delay: }\NormalTok{E.mean(}\StringTok{:dep_delay}\NormalTok{, }\StringTok{na__rm: }\DecValTok{true}\NormalTok{))}
3406
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.summarise}\NormalTok{(}\WarningTok{delay:} \ConstantTok{E}\AttributeTok{.mean}\NormalTok{(}\WarningTok{:dep\_delay}\NormalTok{, }\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{))}
3051
3407
  \end{Highlighting}
3052
3408
  \end{Shaded}
3053
3409
 
@@ -3063,8 +3419,8 @@ given group:
3063
3419
 
3064
3420
  \begin{Shaded}
3065
3421
  \begin{Highlighting}[]
3066
- \NormalTok{by_day = flights.group_by(}\StringTok{:year}\NormalTok{, }\StringTok{:month}\NormalTok{, }\StringTok{:day}\NormalTok{)}
3067
- \NormalTok{puts by_day.summarise(}\StringTok{delay: :dep_delay}\NormalTok{.mean(}\StringTok{na__rm: }\DecValTok{true}\NormalTok{)).head}
3422
+ \NormalTok{by\_day }\OperatorTok{=}\NormalTok{ flights}\AttributeTok{.group\_by}\NormalTok{(}\WarningTok{:year}\NormalTok{, }\WarningTok{:month}\NormalTok{, }\WarningTok{:day}\NormalTok{)}
3423
+ \FunctionTok{puts}\NormalTok{ by\_day}\AttributeTok{.summarise}\NormalTok{(}\WarningTok{delay:} \WarningTok{:dep\_delay}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{))}\AttributeTok{.head}
3068
3424
  \end{Highlighting}
3069
3425
  \end{Shaded}
3070
3426
 
@@ -3072,7 +3428,7 @@ given group:
3072
3428
  ## # A tibble: 6 x 4
3073
3429
  ## # Groups: year, month [1]
3074
3430
  ## year month day delay
3075
- ## * <int> <int> <int> <dbl>
3431
+ ## <int> <int> <int> <dbl>
3076
3432
  ## 1 2013 1 1 11.5
3077
3433
  ## 2 2013 1 2 13.9
3078
3434
  ## 3 2013 1 3 11.0
@@ -3086,15 +3442,15 @@ other:
3086
3442
 
3087
3443
  \begin{Shaded}
3088
3444
  \begin{Highlighting}[]
3089
- \NormalTok{delays = flights.}
3090
- \NormalTok{ group_by(}\StringTok{:dest}\NormalTok{).}
3091
- \NormalTok{ summarise(}
3092
- \StringTok{count: }\NormalTok{E.n,}
3093
- \StringTok{dist: :distance}\NormalTok{.mean(}\StringTok{na__rm: }\DecValTok{true}\NormalTok{),}
3094
- \StringTok{delay: :arr_delay}\NormalTok{.mean(}\StringTok{na__rm: }\DecValTok{true}\NormalTok{)).}
3095
- \NormalTok{ filter(}\StringTok{:count}\NormalTok{ > }\DecValTok{20}\NormalTok{, }\StringTok{:dest}\NormalTok{ != }\StringTok{"NHL"}\NormalTok{)}
3096
-
3097
- \NormalTok{puts delays.head}
3445
+ \NormalTok{delays }\OperatorTok{=}\NormalTok{ flights}\AttributeTok{.}
3446
+ \AttributeTok{group\_by}\NormalTok{(}\WarningTok{:dest}\NormalTok{)}\AttributeTok{.}
3447
+ \AttributeTok{summarise}\NormalTok{(}
3448
+ \WarningTok{count:} \ConstantTok{E}\AttributeTok{.n}\NormalTok{,}
3449
+ \WarningTok{dist:} \WarningTok{:distance}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{),}
3450
+ \WarningTok{delay:} \WarningTok{:arr\_delay}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{))}\AttributeTok{.}
3451
+ \AttributeTok{filter}\NormalTok{(}\WarningTok{:count} \OperatorTok{\textgreater{}} \DecValTok{20}\NormalTok{, }\WarningTok{:dest} \OperatorTok{!=} \StringTok{"NHL"}\NormalTok{)}
3452
+
3453
+ \FunctionTok{puts}\NormalTok{ delays}\AttributeTok{.head}
3098
3454
  \end{Highlighting}
3099
3455
  \end{Shaded}
3100
3456
 
@@ -3112,133 +3468,155 @@ other:
3112
3468
 
3113
3469
  \section{Using Data Table}\label{using-data-table}
3114
3470
 
3471
+ The next chunk reads the \textbf{flights14} sample (same file as the
3472
+ data.table vignette). Prefer \textbf{downloading in Ruby} and
3473
+ \textbf{\texttt{R.fread} on a local path}:
3474
+ \texttt{data.table::fread("https://…")} runs the HTTP transfer
3475
+ \textbf{inside R} while the Galaaz bridge waits on a \textbf{single}
3476
+ eval; if the remote server stalls, that looks like an intermittent
3477
+ ``hang'' and eventually hits the \textbf{per-eval} bridge timeout.
3478
+ Ruby's \textbf{\texttt{Net::HTTP}} \texttt{open\_timeout} /
3479
+ \texttt{read\_timeout} fail fast with a clear error instead. The chunk
3480
+ passes \textbf{\texttt{nrows:}} to \textbf{\texttt{fread}} so a single
3481
+ bridge eval does not have to materialize the full
3482
+ \textasciitilde1.2M-row table during a gknit run.
3483
+
3115
3484
  \begin{Shaded}
3116
3485
  \begin{Highlighting}[]
3117
- \NormalTok{R.library(}\StringTok{'data.table'}\NormalTok{)}
3118
- \NormalTok{R.install_and_loads(}\StringTok{'curl'}\NormalTok{)}
3119
-
3120
- \NormalTok{input = }\StringTok{"https://raw.githubusercontent.com/Rdatatable/data.table/master/vignettes/flights14.csv"}
3121
- \NormalTok{flights = R.fread(input)}
3122
- \NormalTok{puts flights}
3123
- \NormalTok{puts flights.dim}
3486
+ \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}net/http\textquotesingle{}}
3487
+ \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}uri\textquotesingle{}}
3488
+ \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}tmpdir\textquotesingle{}}
3489
+
3490
+ \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}data.table\textquotesingle{}}\NormalTok{)}
3491
+
3492
+ \NormalTok{url }\OperatorTok{=} \ConstantTok{URI}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}https://raw.githubusercontent.com/Rdatatable/data.table/master/vignettes/flights14.csv\textquotesingle{}}\NormalTok{)}
3493
+ \NormalTok{csv }\OperatorTok{=} \DataTypeTok{File}\AttributeTok{.join}\NormalTok{(}\DataTypeTok{Dir}\AttributeTok{.tmpdir}\NormalTok{, }\StringTok{"galaaz\_manual\_flights14\_}\SpecialCharTok{\#\{}\DataTypeTok{Process}\AttributeTok{.pid}\SpecialCharTok{\}}\StringTok{.csv"}\NormalTok{)}
3494
+ \ControlFlowTok{begin}
3495
+ \DataTypeTok{Net}\OperatorTok{::}\ConstantTok{HTTP}\AttributeTok{.start}\NormalTok{(url}\AttributeTok{.host}\NormalTok{, url}\AttributeTok{.port}\NormalTok{, }\WarningTok{use\_ssl:} \DecValTok{true}\NormalTok{, }\WarningTok{open\_timeout:} \DecValTok{25}\NormalTok{, }\WarningTok{read\_timeout:} \DecValTok{120}\NormalTok{) }\ControlFlowTok{do} \OperatorTok{|}\NormalTok{http}\OperatorTok{|}
3496
+ \NormalTok{ resp }\OperatorTok{=}\NormalTok{ http}\AttributeTok{.request\_get}\NormalTok{(url}\AttributeTok{.request\_uri}\NormalTok{)}
3497
+ \FunctionTok{raise} \StringTok{"HTTP }\SpecialCharTok{\#\{}\NormalTok{resp}\AttributeTok{.code}\SpecialCharTok{\}}\StringTok{"} \ControlFlowTok{unless}\NormalTok{ resp}\AttributeTok{.is\_a?}\NormalTok{(}\DataTypeTok{Net}\OperatorTok{::}\DataTypeTok{HTTPSuccess}\NormalTok{)}
3498
+
3499
+ \DataTypeTok{File}\AttributeTok{.binwrite}\NormalTok{(csv, resp}\AttributeTok{.body}\NormalTok{)}
3500
+ \ControlFlowTok{end}
3501
+
3502
+ \CommentTok{\# Cap rows so one bridge eval stays short on slow disks (full file is \textasciitilde{}1.2M rows).}
3503
+ \NormalTok{ flights }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.fread}\NormalTok{(csv, }\WarningTok{nrows:} \DecValTok{120\_000}\NormalTok{)}
3504
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.dim}
3505
+ \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.head}\NormalTok{(flights, }\DecValTok{12}\NormalTok{)}
3506
+ \ControlFlowTok{ensure}
3507
+ \DataTypeTok{File}\AttributeTok{.unlink}\NormalTok{(csv) }\ControlFlowTok{if}\NormalTok{ csv }\OperatorTok{\&\&} \DataTypeTok{File}\AttributeTok{.exist?}\NormalTok{(csv)}
3508
+ \ControlFlowTok{end}
3124
3509
  \end{Highlighting}
3125
3510
  \end{Shaded}
3126
3511
 
3127
3512
  \begin{verbatim}
3128
- ## year month day dep_delay arr_delay carrier origin dest air_time
3129
- ## 1: 2014 1 1 14 13 AA JFK LAX 359
3130
- ## 2: 2014 1 1 -3 13 AA JFK LAX 363
3131
- ## 3: 2014 1 1 2 9 AA JFK LAX 351
3132
- ## 4: 2014 1 1 -8 -26 AA LGA PBI 157
3133
- ## 5: 2014 1 1 2 1 AA JFK LAX 350
3134
- ## ---
3135
- ## 253312: 2014 10 31 1 -30 UA LGA IAH 201
3136
- ## 253313: 2014 10 31 -5 -14 UA EWR IAH 189
3137
- ## 253314: 2014 10 31 -8 16 MQ LGA RDU 83
3138
- ## 253315: 2014 10 31 -4 15 MQ LGA DTW 75
3139
- ## 253316: 2014 10 31 -5 1 MQ LGA SDF 110
3140
- ## distance hour
3141
- ## 1: 2475 9
3142
- ## 2: 2475 11
3143
- ## 3: 2475 19
3144
- ## 4: 1035 7
3145
- ## 5: 2475 13
3146
- ## ---
3147
- ## 253312: 1416 14
3148
- ## 253313: 1400 8
3149
- ## 253314: 431 11
3150
- ## 253315: 502 11
3151
- ## 253316: 659 8
3152
- ## [1] 253316 11
3513
+ ## [1] 120000 11
3514
+ ## year month day dep_delay arr_delay carrier origin dest air_time
3515
+ ## <int> <int> <int> <int> <int> <char> <char> <char> <int>
3516
+ ## 1: 2014 1 1 14 13 AA JFK LAX 359
3517
+ ## 2: 2014 1 1 -3 13 AA JFK LAX 363
3518
+ ## 3: 2014 1 1 2 9 AA JFK LAX 351
3519
+ ## 4: 2014 1 1 -8 -26 AA LGA PBI 157
3520
+ ## 5: 2014 1 1 2 1 AA JFK LAX 350
3521
+ ## 6: 2014 1 1 4 0 AA EWR LAX 339
3522
+ ## 7: 2014 1 1 -2 -18 AA JFK LAX 338
3523
+ ## 8: 2014 1 1 -3 -14 AA JFK LAX 356
3524
+ ## 9: 2014 1 1 -1 -17 AA JFK MIA 161
3525
+ ## 10: 2014 1 1 -2 -14 AA JFK SEA 349
3526
+ ## 11: 2014 1 1 -5 -17 AA EWR MIA 161
3527
+ ## 12: 2014 1 1 7 -5 AA JFK SFO 365
3528
+ ## distance hour
3529
+ ## <int> <int>
3530
+ ## 1: 2475 9
3531
+ ## 2: 2475 11
3532
+ ## 3: 2475 19
3533
+ ## 4: 1035 7
3534
+ ## 5: 2475 13
3535
+ ## 6: 2454 18
3536
+ ## 7: 2475 21
3537
+ ## 8: 2475 15
3538
+ ## 9: 1089 15
3539
+ ## 10: 2422 18
3540
+ ## 11: 1085 16
3541
+ ## 12: 2586 17
3153
3542
  \end{verbatim}
3154
3543
 
3155
3544
  \begin{Shaded}
3156
3545
  \begin{Highlighting}[]
3157
-
3158
- \NormalTok{data_table = R.data__table(}
3159
- \DataTypeTok{ID}\NormalTok{: R.c(}\StringTok{"b"}\NormalTok{,}\StringTok{"b"}\NormalTok{,}\StringTok{"b"}\NormalTok{,}\StringTok{"a"}\NormalTok{,}\StringTok{"a"}\NormalTok{,}\StringTok{"c"}\NormalTok{),}
3160
- \StringTok{a: }\NormalTok{(}\DecValTok{1}\NormalTok{..}\DecValTok{6}\NormalTok{),}
3161
- \StringTok{b: }\NormalTok{(}\DecValTok{7}\NormalTok{..}\DecValTok{12}\NormalTok{),}
3162
- \StringTok{c: }\NormalTok{(}\DecValTok{13}\NormalTok{..}\DecValTok{18}\NormalTok{)}
3546
+ \NormalTok{data\_table }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_table}\NormalTok{(}
3547
+ \WarningTok{ID:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\StringTok{"b"}\NormalTok{,}\StringTok{"b"}\NormalTok{,}\StringTok{"b"}\NormalTok{,}\StringTok{"a"}\NormalTok{,}\StringTok{"a"}\NormalTok{,}\StringTok{"c"}\NormalTok{),}
3548
+ \WarningTok{a:}\NormalTok{ (}\DecValTok{1}\OperatorTok{..}\DecValTok{6}\NormalTok{),}
3549
+ \WarningTok{b:}\NormalTok{ (}\DecValTok{7}\OperatorTok{..}\DecValTok{12}\NormalTok{),}
3550
+ \WarningTok{c:}\NormalTok{ (}\DecValTok{13}\OperatorTok{..}\DecValTok{18}\NormalTok{)}
3163
3551
  \NormalTok{)}
3164
3552
 
3165
- \NormalTok{puts data_table}
3166
- \NormalTok{puts data_table.}\DataTypeTok{ID}
3553
+ \FunctionTok{puts}\NormalTok{ data\_table}
3554
+ \FunctionTok{puts}\NormalTok{ data\_table}\AttributeTok{.}\ConstantTok{ID}
3167
3555
  \end{Highlighting}
3168
3556
  \end{Shaded}
3169
3557
 
3170
3558
  \begin{verbatim}
3171
- ## ID a b c
3172
- ## 1: b 1 7 13
3173
- ## 2: b 2 8 14
3174
- ## 3: b 3 9 15
3175
- ## 4: a 4 10 16
3176
- ## 5: a 5 11 17
3177
- ## 6: c 6 12 18
3559
+ ## ID a b c
3560
+ ## <char> <int> <int> <int>
3561
+ ## 1: b 1 7 13
3562
+ ## 2: b 2 8 14
3563
+ ## 3: b 3 9 15
3564
+ ## 4: a 4 10 16
3565
+ ## 5: a 5 11 17
3566
+ ## 6: c 6 12 18
3178
3567
  ## [1] "b" "b" "b" "a" "a" "c"
3179
3568
  \end{verbatim}
3180
3569
 
3181
3570
  \begin{Shaded}
3182
3571
  \begin{Highlighting}[]
3183
- \CommentTok{# subset rows in i}
3184
- \NormalTok{ans = flights[(}\StringTok{:origin}\NormalTok{.eq }\StringTok{"JFK"}\NormalTok{) & (}\StringTok{:month}\NormalTok{.eq }\DecValTok{6}\NormalTok{)]}
3185
- \NormalTok{puts ans.head}
3186
-
3187
- \CommentTok{# Get the first two rows from flights.}
3572
+ \CommentTok{\# subset rows in i}
3573
+ \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\NormalTok{(}\WarningTok{:origin}\AttributeTok{.eq} \StringTok{"JFK"}\NormalTok{) }\OperatorTok{\&}\NormalTok{ (}\WarningTok{:month}\AttributeTok{.eq} \DecValTok{6}\NormalTok{)}\KeywordTok{]}
3574
+ \FunctionTok{puts}\NormalTok{ ans}\AttributeTok{.head}
3188
3575
 
3189
- \NormalTok{ans = flights[(}\DecValTok{1}\NormalTok{..}\DecValTok{2}\NormalTok{)]}
3190
- \NormalTok{puts ans}
3576
+ \CommentTok{\# Get the first two rows from flights.}
3191
3577
 
3192
- \CommentTok{# Sort flights first by column origin in ascending order, and then by dest in descending order:}
3578
+ \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\NormalTok{(}\DecValTok{1}\OperatorTok{..}\DecValTok{2}\NormalTok{)}\KeywordTok{]}
3579
+ \FunctionTok{puts}\NormalTok{ ans}
3193
3580
 
3194
- \CommentTok{# ans = flights[E.order(:origin, -(:dest))]}
3195
- \CommentTok{# puts ans.head}
3581
+ \CommentTok{\# Sort by origin asc, then dest desc (example kept commented):}
3582
+ \CommentTok{\# ans = flights[E.order(:origin, {-}(:dest))]}
3583
+ \CommentTok{\# puts ans.head}
3196
3584
  \end{Highlighting}
3197
3585
  \end{Shaded}
3198
3586
 
3199
3587
  \begin{verbatim}
3200
- ## year month day dep_delay arr_delay carrier origin dest air_time
3201
- ## 1: 2014 6 1 -9 -5 AA JFK LAX 324
3202
- ## 2: 2014 6 1 -10 -13 AA JFK LAX 329
3203
- ## 3: 2014 6 1 18 -1 AA JFK LAX 326
3204
- ## 4: 2014 6 1 -6 -16 AA JFK LAX 320
3205
- ## 5: 2014 6 1 -4 -45 AA JFK LAX 326
3206
- ## 6: 2014 6 1 -6 -23 AA JFK LAX 329
3207
- ## distance hour
3208
- ## 1: 2475 8
3209
- ## 2: 2475 12
3210
- ## 3: 2475 7
3211
- ## 4: 2475 10
3212
- ## 5: 2475 18
3213
- ## 6: 2475 14
3214
- ## year month day dep_delay arr_delay carrier origin dest air_time
3215
- ## 1: 2014 1 1 14 13 AA JFK LAX 359
3216
- ## 2: 2014 1 1 -3 13 AA JFK LAX 363
3217
- ## distance hour
3218
- ## 1: 2475 9
3219
- ## 2: 2475 11
3588
+ ## Empty data.table (0 rows and 11 cols): year,month,day,dep_delay,arr_delay,carrier...
3589
+ ## year month day dep_delay arr_delay carrier origin dest air_time
3590
+ ## <int> <int> <int> <int> <int> <char> <char> <char> <int>
3591
+ ## 1: 2014 1 1 14 13 AA JFK LAX 359
3592
+ ## 2: 2014 1 1 -3 13 AA JFK LAX 363
3593
+ ## distance hour
3594
+ ## <int> <int>
3595
+ ## 1: 2475 9
3596
+ ## 2: 2475 11
3220
3597
  \end{verbatim}
3221
3598
 
3222
3599
  \begin{Shaded}
3223
3600
  \begin{Highlighting}[]
3224
- \CommentTok{# Select column(s) in j}
3225
- \CommentTok{# select arr_delay column, but return it as a vector.}
3601
+ \CommentTok{\# Select column(s) in j}
3602
+ \CommentTok{\# select arr\_delay column, but return it as a vector.}
3226
3603
 
3227
- \NormalTok{ans = flights[}\StringTok{:all}\NormalTok{, }\StringTok{:arr_delay}\NormalTok{]}
3228
- \NormalTok{puts ans.head}
3604
+ \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\WarningTok{:all}\NormalTok{, }\WarningTok{:arr\_delay}\KeywordTok{]}
3605
+ \FunctionTok{puts}\NormalTok{ ans}\AttributeTok{.head}
3229
3606
 
3230
- \CommentTok{# Select arr_delay column, but return as a data.table instead.}
3607
+ \CommentTok{\# arr\_delay as data.table (not plain vector).}
3231
3608
 
3232
- \NormalTok{ans = flights[}\StringTok{:all}\NormalTok{, }\StringTok{:arr_delay}\NormalTok{.list]}
3233
- \NormalTok{puts ans.head}
3609
+ \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\WarningTok{:all}\NormalTok{, }\WarningTok{:arr\_delay}\AttributeTok{.list}\KeywordTok{]}
3610
+ \FunctionTok{puts}\NormalTok{ ans}\AttributeTok{.head}
3234
3611
 
3235
- \NormalTok{ans = flights[}\StringTok{:all}\NormalTok{, E.list(}\StringTok{:arr_delay}\NormalTok{, }\StringTok{:dep_delay}\NormalTok{)]}
3612
+ \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\WarningTok{:all}\NormalTok{, }\ConstantTok{E}\AttributeTok{.list}\NormalTok{(}\WarningTok{:arr\_delay}\NormalTok{, }\WarningTok{:dep\_delay}\NormalTok{)}\KeywordTok{]}
3236
3613
  \end{Highlighting}
3237
3614
  \end{Shaded}
3238
3615
 
3239
3616
  \begin{verbatim}
3240
3617
  ## [1] 13 13 9 -26 1 0
3241
3618
  ## arr_delay
3619
+ ## <int>
3242
3620
  ## 1: 13
3243
3621
  ## 2: 13
3244
3622
  ## 3: 9
@@ -3247,44 +3625,361 @@ other:
3247
3625
  ## 6: 0
3248
3626
  \end{verbatim}
3249
3627
 
3628
+ \section{Apache Arrow}\label{apache-arrow}
3629
+
3630
+ \href{https://arrow.apache.org/}{Apache Arrow} is a \textbf{columnar}
3631
+ in-memory format used heavily in R and Python for analytics. In Galaaz,
3632
+ \textbf{Ruby does not hold an Arrow C++ table itself}; instead you build
3633
+ ordinary Ruby structures (arrays of row hashes), and
3634
+ \textbf{\texttt{R::Arrow.from\_ruby\_batches}} creates a real
3635
+ \textbf{Arrow \texttt{Table} inside GNU R}. From there you use R's
3636
+ \textbf{\texttt{arrow}} and \textbf{\texttt{dplyr}} packages as usual:
3637
+ \textbf{\texttt{group\_by}} on the Arrow table,
3638
+ \textbf{\texttt{summarise}} for aggregates, then
3639
+ \textbf{\texttt{collect()}} to materialize a tibble when you need
3640
+ in-memory R rows.
3641
+
3642
+ That pattern matches production use: \textbf{JRuby threads} (or
3643
+ sequential code) assemble many rows in Ruby; you pay \textbf{one}
3644
+ bridge-heavy handoff to R; \textbf{dplyr} runs vectorised work on the
3645
+ Arrow table in R.
3646
+
3647
+ \textbf{Prerequisites:} install R packages \textbf{\texttt{arrow}} and
3648
+ \textbf{\texttt{dplyr}}. Run scripts with
3649
+ \textbf{\texttt{bin/galaaz-jruby}} (or the same JVM flags as in
3650
+ \textbf{\texttt{docs/testing.md}}) so the Arrow JNI stack is available.
3651
+
3652
+ \subsection{\texorpdfstring{Other \texttt{R::Arrow}
3653
+ helpers}{Other R::Arrow helpers}}\label{other-rarrow-helpers}
3654
+
3655
+ The Ruby module \textbf{\texttt{R::Arrow}} (see
3656
+ \texttt{lib/R\_interface/r\_arrow.rb}) also includes:
3657
+
3658
+ \begin{itemize}
3659
+ \tightlist
3660
+ \item
3661
+ \textbf{\texttt{R::Arrow.table\_from(df)}} --- wrap an R
3662
+ \texttt{data.frame} / tibble as an Arrow table.
3663
+ \item
3664
+ \textbf{\texttt{R::Arrow.read\_feather} / \texttt{write\_feather}},
3665
+ \textbf{\texttt{read\_parquet}}, \textbf{\texttt{dataset(path)}} ---
3666
+ file and dataset IO on paths visible to R.
3667
+ \end{itemize}
3668
+
3669
+ \subsection{Example: many Ruby rows → Arrow in R → grouped
3670
+ statistics}\label{example-many-ruby-rows-arrow-in-r-grouped-statistics}
3671
+
3672
+ The repository test
3673
+ \textbf{\texttt{slow-specs/arrow\_large\_pipeline\_spec.rb}} builds
3674
+ \textbf{200k rows} in parallel (eight threads × 25,000 rows), pushes
3675
+ them through \textbf{\texttt{R::Arrow.from\_ruby\_batches}}, then checks
3676
+ that \textbf{dplyr} group summaries match a Ruby reference calculation.
3677
+ The same logic appears below at a \textbf{smaller scale} so this manual
3678
+ can knit quickly; increase \texttt{thread\_count} and
3679
+ \texttt{rows\_per\_thread} when experimenting locally.
3680
+
3681
+ \begin{Shaded}
3682
+ \begin{Highlighting}[]
3683
+ \CommentTok{\# Scaled{-}down version of slow{-}specs/arrow\_large\_pipeline\_spec.rb.}
3684
+ \ControlFlowTok{unless} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Support}\AttributeTok{.eval}\NormalTok{(}\StringTok{"requireNamespace(\textquotesingle{}arrow\textquotesingle{}, quietly=TRUE) \&\& requireNamespace(\textquotesingle{}dplyr\textquotesingle{}, quietly=TRUE)"}\NormalTok{) }\OperatorTok{==} \DecValTok{true}
3685
+ \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}(Skip: need arrow + dplyr in R; use bin/galaaz{-}jruby outside gKnit.)\textquotesingle{}}
3686
+ \ControlFlowTok{else}
3687
+ \NormalTok{ thread\_count }\OperatorTok{=} \DecValTok{4}
3688
+ \NormalTok{ rows\_per\_thread }\OperatorTok{=} \DecValTok{500}
3689
+ \NormalTok{ group\_count }\OperatorTok{=} \DecValTok{5}
3690
+
3691
+ \NormalTok{ batches }\OperatorTok{=} \KeywordTok{[]}
3692
+ \NormalTok{ mutex }\OperatorTok{=} \DataTypeTok{Mutex}\AttributeTok{.new}
3693
+ \NormalTok{ threads }\OperatorTok{=} \KeywordTok{[]}
3694
+
3695
+ \NormalTok{ thread\_count}\AttributeTok{.times} \ControlFlowTok{do} \OperatorTok{|}\NormalTok{tid}\OperatorTok{|}
3696
+ \NormalTok{ threads }\OperatorTok{\textless{}\textless{}} \DataTypeTok{Thread}\AttributeTok{.new} \ControlFlowTok{do}
3697
+ \NormalTok{ start }\OperatorTok{=}\NormalTok{ tid }\OperatorTok{*}\NormalTok{ rows\_per\_thread}
3698
+ \NormalTok{ local }\OperatorTok{=}\NormalTok{ (start}\OperatorTok{...}\NormalTok{(start }\OperatorTok{+}\NormalTok{ rows\_per\_thread))}\AttributeTok{.map} \ControlFlowTok{do} \OperatorTok{|}\NormalTok{i}\OperatorTok{|}
3699
+ \OperatorTok{\{}
3700
+ \WarningTok{id:}\NormalTok{ i,}
3701
+ \WarningTok{grp:} \StringTok{"g}\SpecialCharTok{\#\{}\NormalTok{i }\OperatorTok{\%}\NormalTok{ group\_count}\SpecialCharTok{\}}\StringTok{"}\NormalTok{,}
3702
+ \WarningTok{value:}\NormalTok{ (i }\OperatorTok{\%} \DecValTok{17}\NormalTok{) }\OperatorTok{+} \DecValTok{1}\NormalTok{,}
3703
+ \WarningTok{weight:}\NormalTok{ ((i }\OperatorTok{\%} \DecValTok{5}\NormalTok{) }\OperatorTok{+} \DecValTok{1}\NormalTok{) }\OperatorTok{*} \FloatTok{0.5}
3704
+ \OperatorTok{\}}
3705
+ \ControlFlowTok{end}
3706
+ \NormalTok{ mutex}\AttributeTok{.synchronize} \OperatorTok{\{}\NormalTok{ batches }\OperatorTok{\textless{}\textless{}}\NormalTok{ local }\OperatorTok{\}}
3707
+ \ControlFlowTok{end}
3708
+ \ControlFlowTok{end}
3709
+ \NormalTok{ threads}\AttributeTok{.each}\NormalTok{(}\OperatorTok{\&}\WarningTok{:join}\NormalTok{)}
3710
+
3711
+ \NormalTok{ tbl }\OperatorTok{=} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Arrow}\AttributeTok{.from\_ruby\_batches}\NormalTok{(batches)}
3712
+ \FunctionTok{puts} \StringTok{"R class after from\_ruby\_batches: }\SpecialCharTok{\#\{}\NormalTok{tbl}\AttributeTok{.rclass}\SpecialCharTok{\}}\StringTok{"}
3713
+
3714
+ \NormalTok{ grouped }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.dplyr\_\_\_group\_by}\NormalTok{(tbl, }\WarningTok{:grp}\NormalTok{)}
3715
+ \NormalTok{ summarised }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.dplyr\_\_\_summarise}\NormalTok{(}
3716
+ \NormalTok{ grouped,}
3717
+ \WarningTok{n:} \ConstantTok{E}\AttributeTok{.n}\NormalTok{(),}
3718
+ \WarningTok{total:} \ConstantTok{E}\AttributeTok{.sum}\NormalTok{(}\WarningTok{:value}\NormalTok{),}
3719
+ \WarningTok{wsum:} \ConstantTok{E}\AttributeTok{.sum}\NormalTok{(}\WarningTok{:value} \OperatorTok{*} \WarningTok{:weight}\NormalTok{)}
3720
+ \NormalTok{ )}
3721
+ \NormalTok{ out }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.dplyr\_\_\_collect}\NormalTok{(summarised)}
3722
+
3723
+ \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}Per{-}group summary (first rows):\textquotesingle{}}
3724
+ \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.as\_\_data\_\_frame}\NormalTok{(out)}\AttributeTok{.head}\NormalTok{(}\DecValTok{10}\NormalTok{)}
3725
+
3726
+ \NormalTok{ total\_n }\OperatorTok{=} \DecValTok{0}
3727
+ \NormalTok{ (}\DecValTok{1}\OperatorTok{..}\NormalTok{(out}\AttributeTok{.nrow} \OperatorTok{\textgreater{}\textgreater{}} \DecValTok{0}\NormalTok{))}\AttributeTok{.each} \OperatorTok{\{} \OperatorTok{|}\NormalTok{i}\OperatorTok{|}\NormalTok{ total\_n }\OperatorTok{+=}\NormalTok{ (out}\KeywordTok{[[}\CharTok{\textquotesingle{}n\textquotesingle{}}\KeywordTok{]][}\NormalTok{i}\KeywordTok{]} \OperatorTok{\textgreater{}\textgreater{}} \DecValTok{0}\NormalTok{) }\OperatorTok{\}}
3728
+ \FunctionTok{puts} \StringTok{"Sum of group counts n (should equal }\SpecialCharTok{\#\{}\NormalTok{thread\_count }\OperatorTok{*}\NormalTok{ rows\_per\_thread}\SpecialCharTok{\}}\StringTok{): }\SpecialCharTok{\#\{}\NormalTok{total\_n}\SpecialCharTok{\}}\StringTok{"}
3729
+ \ControlFlowTok{end}
3730
+ \end{Highlighting}
3731
+ \end{Shaded}
3732
+
3733
+ \begin{verbatim}
3734
+ ## R class after from_ruby_batches: Table
3735
+ ## Per-group summary (first rows):
3736
+ ## grp n total wsum
3737
+ ## 1 g0 400 3589 1794.5
3738
+ ## 2 g1 400 3598 3598.0
3739
+ ## 3 g2 400 3590 5385.0
3740
+ ## 4 g3 400 3599 7198.0
3741
+ ## 5 g4 400 3591 8977.5
3742
+ ## Sum of group counts n (should equal 2000): 2000
3743
+ \end{verbatim}
3744
+
3745
+ \textbf{What to notice:} (1) Ruby only sees \textbf{\texttt{Hash}} rows
3746
+ and Ruby \textbf{\texttt{Thread}} objects; (2) a single
3747
+ \textbf{\texttt{from\_ruby\_batches}} call creates the Arrow table in R;
3748
+ (3) \textbf{\texttt{dplyr\_\_\_group\_by}} /
3749
+ \textbf{\texttt{dplyr\_\_\_summarise}} /
3750
+ \textbf{\texttt{dplyr\_\_\_collect}} mirror
3751
+ \textbf{\texttt{dplyr::group\_by}} / \textbf{\texttt{dplyr::summarise}}
3752
+ / \textbf{\texttt{dplyr::collect}} on an Arrow-backed table. For a
3753
+ lighter test, see
3754
+ \textbf{\texttt{specs/arrow\_from\_ruby\_batches\_spec.rb}}; for the
3755
+ full-size benchmark, run
3756
+ \textbf{\texttt{bin/run\_slow\_rspec\ slow-specs/arrow\_large\_pipeline\_spec.rb}}.
3757
+
3758
+ \section{Bioconductor and DESeq2}\label{bioconductor-and-deseq2}
3759
+
3760
+ \textbf{Bioconductor} packages are ordinary R packages installed from
3761
+ the Bioconductor repositories. Galaaz does not treat them specially:
3762
+ once installed in \textbf{GNU R}, you load them with
3763
+ \textbf{\texttt{R.library}} like any CRAN package.
3764
+
3765
+ \subsection{Installing Bioconductor
3766
+ packages}\label{installing-bioconductor-packages}
3767
+
3768
+ From an R session (or
3769
+ \texttt{R\ -e\ \textquotesingle{}...\textquotesingle{}}), use
3770
+ \textbf{BiocManager} (see
3771
+ \href{https://bioconductor.org/install/}{bioconductor.org}):
3772
+
3773
+ \begin{Shaded}
3774
+ \begin{Highlighting}[]
3775
+ \ControlFlowTok{if}\NormalTok{ (}\SpecialCharTok{!}\FunctionTok{requireNamespace}\NormalTok{(}\StringTok{"BiocManager"}\NormalTok{, }\AttributeTok{quietly =} \ConstantTok{TRUE}\NormalTok{))}
3776
+ \FunctionTok{install.packages}\NormalTok{(}\StringTok{"BiocManager"}\NormalTok{)}
3777
+ \NormalTok{BiocManager}\SpecialCharTok{::}\FunctionTok{install}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"DESeq2"}\NormalTok{, }\StringTok{"airway"}\NormalTok{))}
3778
+ \end{Highlighting}
3779
+ \end{Shaded}
3780
+
3781
+ The \textbf{\texttt{airway}} package ships the example
3782
+ \textbf{\texttt{SummarizedExperiment}} used below. \textbf{DESeq2} pulls
3783
+ in several dependencies; the first install can take several minutes.
3784
+
3785
+ \subsection{Example: DESeq2 on the airway
3786
+ dataset}\label{example-deseq2-on-the-airway-dataset}
3787
+
3788
+ The script
3789
+ \textbf{\texttt{examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}}
3790
+ is the canonical version in the repository. Run it from the
3791
+ \textbf{Galaaz repository root} with JRuby, for example:
3792
+
3793
+ \begin{Shaded}
3794
+ \begin{Highlighting}[]
3795
+ \NormalTok{bin/galaaz{-}jruby examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}
3796
+ \end{Highlighting}
3797
+ \end{Shaded}
3798
+
3799
+ The workflow in Ruby mirrors a standard DESeq2 vignette:
3800
+
3801
+ \begin{enumerate}
3802
+ \def\labelenumi{\arabic{enumi}.}
3803
+ \tightlist
3804
+ \item
3805
+ \textbf{\texttt{R.library(\textquotesingle{}DESeq2\textquotesingle{})}}
3806
+ and
3807
+ \textbf{\texttt{R.library(\textquotesingle{}airway\textquotesingle{})}},
3808
+ then
3809
+ \textbf{\texttt{R.data(\textquotesingle{}airway\textquotesingle{})}}
3810
+ so the object exists in R's global environment.
3811
+ \item
3812
+ \textbf{\texttt{airway\ =\ \textasciitilde{}:airway}} pulls the
3813
+ experiment into a Galaaz wrapper so you can pass it to R functions as
3814
+ a Ruby value.
3815
+ \item
3816
+ \textbf{\texttt{R.DESeqDataSet(...,\ design:\ (:all.til\ :cell\ +\ :dex))}}
3817
+ builds the \textbf{\texttt{DESeqDataSet}}. The
3818
+ \textbf{\texttt{(:all.til\ :cell\ +\ :dex)}} form is Galaaz's way of
3819
+ passing the one-sided formula
3820
+ \textbf{\texttt{\textasciitilde{}\ cell\ +\ dex}} (adjust for the
3821
+ design you need).
3822
+ \item
3823
+ Prefilter rows with almost no counts:
3824
+ \textbf{\texttt{keep\ =\ R.rowSums(R.counts(dds))\ \textgreater{}=\ 10}}
3825
+ and \textbf{\texttt{dds\ =\ dds{[}keep,\ :all{]}}}.
3826
+ \item
3827
+ \textbf{\texttt{dds\ =\ R.DESeq(dds)}} fits the model;
3828
+ \textbf{\texttt{res\ =\ R.results(dds,\ contrast:\ R.c(\textquotesingle{}dex\textquotesingle{},\ \textquotesingle{}trt\textquotesingle{},\ \textquotesingle{}untrt\textquotesingle{}))}}
3829
+ extracts the treatment contrast (adjust \textbf{\texttt{contrast}} for
3830
+ your experiment).
3831
+ \item
3832
+ Summaries use normal Ruby string interpolation on
3833
+ \textbf{\texttt{R.nrow}}, \textbf{\texttt{R.ncol}},
3834
+ \textbf{\texttt{R.colnames}}, etc.
3835
+ \item
3836
+ \textbf{\texttt{R.pdf(...);\ R.plotMA(res,\ ...);\ R.dev\_\_off}}
3837
+ writes DESeq2's MA plot (path is relative to the process working
3838
+ directory---use the repo root when running the bundled script).
3839
+ \end{enumerate}
3840
+
3841
+ Related benchmarks and warm-run notes live under
3842
+ \textbf{\texttt{docs/deseq2\_airway\_benchmark.md}} and
3843
+ \textbf{\texttt{examples/bioconductor\_deseq2\_airway/bench\_*.rb}}.
3844
+
3845
+ Below is the full listing (same as the file in the repository). It is
3846
+ \textbf{not} executed while this manual is knitted, because
3847
+ \textbf{DESeq2} is heavy and may be absent on the build machine.
3848
+
3849
+ \begin{Shaded}
3850
+ \begin{Highlighting}[]
3851
+ \CommentTok{\# Canonical script: examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}
3852
+ \CommentTok{\# Run: bin/galaaz{-}jruby examples/.../deseq2\_airway\_galaaz.rb (repo root).}
3853
+
3854
+ \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}galaaz\textquotesingle{}}
3855
+
3856
+ \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}DESeq2\textquotesingle{}}\NormalTok{)}
3857
+ \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}airway\textquotesingle{}}\NormalTok{)}
3858
+ \ConstantTok{R}\AttributeTok{.data}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}airway\textquotesingle{}}\NormalTok{)}
3859
+
3860
+ \NormalTok{airway }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:airway}
3861
+
3862
+ \CommentTok{\# Build DESeq2 dataset with one{-}sided formula: \textasciitilde{} cell + dex.}
3863
+ \NormalTok{dds }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.}\DataTypeTok{DESeqDataSet}\NormalTok{(airway, }\WarningTok{design:}\NormalTok{ (}\WarningTok{:all}\AttributeTok{.til} \OperatorTok{:}\NormalTok{cell }\OperatorTok{+} \WarningTok{:dex}\NormalTok{))}
3864
+
3865
+ \CommentTok{\# Prefilter genes with almost no counts.}
3866
+ \NormalTok{keep }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.rowSums}\NormalTok{(}\ConstantTok{R}\AttributeTok{.counts}\NormalTok{(dds)) }\OperatorTok{\textgreater{}=} \DecValTok{10}
3867
+ \NormalTok{dds }\OperatorTok{=}\NormalTok{ dds}\KeywordTok{[}\NormalTok{keep, }\WarningTok{:all}\KeywordTok{]}
3868
+
3869
+ \CommentTok{\# Fit DE model and extract treatment effect.}
3870
+ \NormalTok{dds }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.}\DataTypeTok{DESeq}\NormalTok{(dds)}
3871
+ \NormalTok{res }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.results}\NormalTok{(dds, }\WarningTok{contrast:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}dex\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}trt\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}untrt\textquotesingle{}}\NormalTok{))}
3872
+
3873
+ \CommentTok{\# Compact sanity outputs for quick verification.}
3874
+ \FunctionTok{puts} \StringTok{"Samples: }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.ncol}\NormalTok{(dds)}\SpecialCharTok{\}}\StringTok{"}
3875
+ \FunctionTok{puts} \StringTok{"Genes after prefilter: }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.nrow}\NormalTok{(dds)}\SpecialCharTok{\}}\StringTok{"}
3876
+ \FunctionTok{puts} \StringTok{"Result rows: }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.nrow}\NormalTok{(res)}\SpecialCharTok{\}}\StringTok{"}
3877
+ \FunctionTok{puts} \StringTok{"Result columns: }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.colnames}\NormalTok{(res)}\SpecialCharTok{\}}\StringTok{"}
3878
+ \FunctionTok{puts} \StringTok{"Significant genes (padj \textless{} 0.05): }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.sum}\NormalTok{(res}\AttributeTok{.padj} \OperatorTok{\textless{}} \FloatTok{0.05}\NormalTok{, }\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{)}\SpecialCharTok{\}}\StringTok{"}
3879
+
3880
+ \NormalTok{res\_ordered }\OperatorTok{=}\NormalTok{ res}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.order}\NormalTok{(res}\AttributeTok{.padj}\NormalTok{), }\WarningTok{:all}\KeywordTok{]}
3881
+ \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.head}\NormalTok{(}\ConstantTok{R}\AttributeTok{.as\_\_data\_\_frame}\NormalTok{(res\_ordered), }\DecValTok{10}\NormalTok{)}
3882
+
3883
+ \CommentTok{\# Standard DESeq2 plot call written to file.}
3884
+ \ConstantTok{R}\AttributeTok{.pdf}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}examples/bioconductor\_deseq2\_airway/plotMA\_galaaz.pdf\textquotesingle{}}\NormalTok{)}
3885
+ \ConstantTok{R}\AttributeTok{.plotMA}\NormalTok{(res, }\WarningTok{ylim:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\OperatorTok{{-}}\DecValTok{5}\NormalTok{, }\DecValTok{5}\NormalTok{))}
3886
+ \ConstantTok{R}\AttributeTok{.dev\_\_off}
3887
+ \end{Highlighting}
3888
+ \end{Shaded}
3889
+
3890
+ If \textbf{DESeq2} and \textbf{airway} are installed, the next chunk
3891
+ loads the data and prints a short preview (it does \textbf{not} run
3892
+ \textbf{\texttt{DESeq}} so the manual knits quickly).
3893
+
3894
+ \begin{Shaded}
3895
+ \begin{Highlighting}[]
3896
+ \ControlFlowTok{unless} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Support}\AttributeTok{.eval}\NormalTok{(}\StringTok{"requireNamespace(\textquotesingle{}DESeq2\textquotesingle{}, quietly=TRUE) \&\& requireNamespace(\textquotesingle{}airway\textquotesingle{}, quietly=TRUE)"}\NormalTok{)}
3897
+ \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}(Skip: install DESeq2 and airway via BiocManager in R to run the full example.)\textquotesingle{}}
3898
+ \ControlFlowTok{else}
3899
+ \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}DESeq2\textquotesingle{}}\NormalTok{)}
3900
+ \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}airway\textquotesingle{}}\NormalTok{)}
3901
+ \ConstantTok{R}\AttributeTok{.data}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}airway\textquotesingle{}}\NormalTok{)}
3902
+ \NormalTok{ airway }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:airway}
3903
+ \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}airway object (head of assay / dims via R):\textquotesingle{}}
3904
+ \FunctionTok{puts} \StringTok{"ncol(samples): }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.ncol}\NormalTok{(airway)}\SpecialCharTok{\}}\StringTok{"}
3905
+ \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.head}\NormalTok{(}\ConstantTok{R}\AttributeTok{.assay}\NormalTok{(airway), }\DecValTok{3}\NormalTok{)}
3906
+ \ControlFlowTok{end}
3907
+ \end{Highlighting}
3908
+ \end{Shaded}
3909
+
3910
+ \begin{verbatim}
3911
+ ## airway object (head of assay / dims via R):
3912
+ ## ncol(samples): [1] 8
3913
+ ## SRR1039508 SRR1039509 SRR1039512 SRR1039513 SRR1039516
3914
+ ## ENSG00000000003 679 448 873 408 1138
3915
+ ## ENSG00000000005 0 0 0 0 0
3916
+ ## ENSG00000000419 467 515 621 365 587
3917
+ ## SRR1039517 SRR1039520 SRR1039521
3918
+ ## ENSG00000000003 1047 770 572
3919
+ ## ENSG00000000005 0 0 0
3920
+ ## ENSG00000000419 799 417 508
3921
+ \end{verbatim}
3922
+
3923
+ \section{Performance}\label{performance}
3924
+
3925
+ For realistic analyses, \textbf{most wall-clock time is spent inside GNU
3926
+ R} (model fitting, I/O inside R, graphics). The Galaaz \textbf{bridge}
3927
+ adds overhead mainly from \textbf{starting a session},
3928
+ \textbf{serializing requests}, and \textbf{wrapping results} in Ruby
3929
+ objects---not from reimplementing R's numerical work.
3930
+
3931
+ Practical tips:
3932
+
3933
+ \begin{itemize}
3934
+ \tightlist
3935
+ \item
3936
+ Keep \textbf{hot loops} in R or vectorized code when possible; use
3937
+ Ruby for orchestration, I/O, and glue.
3938
+ \item
3939
+ \textbf{Reuse one process}: running many short scripts cold-starts
3940
+ Ruby, the JVM, and R each time; a long-lived process or repeated calls
3941
+ in one run amortize setup (see benchmarks below).
3942
+ \item
3943
+ \textbf{Batch data}: merge shards in Ruby, then call
3944
+ \textbf{\texttt{R::Arrow.from\_ruby\_batches}} (or build one data
3945
+ frame) instead of millions of tiny R calls.
3946
+ \end{itemize}
3947
+
3948
+ For measured discussion (including DESeq2-style workloads and warm
3949
+ comparisons), see \textbf{\texttt{docs/performance.md}} and
3950
+ \textbf{\texttt{docs/deseq2\_airway\_benchmark.md}} in the Galaaz
3951
+ repository.
3952
+
3250
3953
  \section{Graphics in Galaaz}\label{graphics-in-galaaz}
3251
3954
 
3252
3955
  Creating graphics in Galaaz is quite easy, as it can use all the power
3253
- of ggplot2. There are many resources in the web that teaches ggplot, so
3956
+ of ggplot2. There are many resources on the web that teach ggplot, so
3254
3957
  here we give a quick example of ggplot integration with Ruby. We
3255
3958
  continue to use the :mtcars dataset and we will plot a diverging bar
3256
- plot, showing cars that have `above' or `below' gas consuption. Let's
3959
+ plot, showing cars that have `above' or `below' gas consumption. Let's
3257
3960
  first prepare the data frame with the necessary data:
3258
3961
 
3259
3962
  \begin{Shaded}
3260
3963
  \begin{Highlighting}[]
3261
- \CommentTok{# copy the R variable :mtcars to the Ruby mtcars variable}
3262
- \NormalTok{mtcars = ~}\StringTok{:mtcars}
3964
+ \CommentTok{\# :mtcars {-}\textgreater{} Ruby handle}
3965
+ \NormalTok{mtcars }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}
3263
3966
 
3264
- \CommentTok{# create a new column 'car_name' to store the car names so that it can be}
3265
- \CommentTok{# used for plotting. The 'rownames' of the data frame cannot be used as}
3266
- \CommentTok{# data for plotting}
3267
- \NormalTok{mtcars.car_name = R.rownames(}\StringTok{:mtcars}\NormalTok{)}
3967
+ \CommentTok{\# Row labels are not a plot column; copy them to car\_name.}
3968
+ \NormalTok{mtcars}\AttributeTok{.car\_name} \OperatorTok{=} \ConstantTok{R}\AttributeTok{.rownames}\NormalTok{(}\WarningTok{:mtcars}\NormalTok{)}
3268
3969
 
3269
- \CommentTok{# compute normalized mpg and add it to a new column called mpg_z}
3270
- \CommentTok{# Note that the mean value for mpg can be obtained by calling the 'mean'}
3271
- \CommentTok{# function on the vector 'mtcars.mpg'. The same with the standard}
3272
- \CommentTok{# deviation 'sd'. The vector is then rounded to two digits with 'round 2'}
3273
- \NormalTok{mtcars.mpg_z = ((mtcars.mpg - mtcars.mpg.mean)/mtcars.mpg.sd).round }\DecValTok{2}
3970
+ \CommentTok{\# Z{-}score mpg (mean/sd on mtcars.mpg); round to 2 decimals.}
3971
+ \NormalTok{mtcars}\AttributeTok{.mpg\_z} \OperatorTok{=}\NormalTok{ ((mtcars}\AttributeTok{.mpg} \OperatorTok{{-}}\NormalTok{ mtcars}\AttributeTok{.mpg.mean}\NormalTok{)}\OperatorTok{/}\NormalTok{mtcars}\AttributeTok{.mpg.sd}\NormalTok{)}\AttributeTok{.round} \DecValTok{2}
3274
3972
 
3275
- \CommentTok{# create a new column 'mpg_type'. Function 'ifelse' is a vectorized function}
3276
- \CommentTok{# that looks at every element of the mpg_z vector and if the value is below}
3277
- \CommentTok{# 0, returns 'below', otherwise returns 'above'}
3278
- \NormalTok{mtcars.mpg_type = (mtcars.mpg_z < }\DecValTok{0}\NormalTok{).ifelse(}\StringTok{"below"}\NormalTok{, }\StringTok{"above"}\NormalTok{)}
3973
+ \CommentTok{\# ifelse is vectorized: below / above average mpg\_z.}
3974
+ \NormalTok{mtcars}\AttributeTok{.mpg\_type} \OperatorTok{=}\NormalTok{ (mtcars}\AttributeTok{.mpg\_z} \OperatorTok{\textless{}} \DecValTok{0}\NormalTok{)}\AttributeTok{.ifelse}\NormalTok{(}\StringTok{"below"}\NormalTok{, }\StringTok{"above"}\NormalTok{)}
3279
3975
 
3280
- \CommentTok{# order the mtcar data set by the mpg_z vector from smaler to larger values}
3281
- \NormalTok{mtcars = mtcars[mtcars.mpg_z.order, }\StringTok{:all}\NormalTok{]}
3976
+ \CommentTok{\# Sort rows by mpg\_z.}
3977
+ \NormalTok{mtcars }\OperatorTok{=}\NormalTok{ mtcars}\KeywordTok{[}\NormalTok{mtcars}\AttributeTok{.mpg\_z.order}\NormalTok{, }\WarningTok{:all}\KeywordTok{]}
3282
3978
 
3283
- \CommentTok{# convert the car_name column to a factor to retain sorted order in plot}
3284
- \NormalTok{mtcars.car_name = mtcars.car_name.factor }\StringTok{levels: }\NormalTok{mtcars.car_name}
3979
+ \CommentTok{\# Factor car\_name so plot order follows sort.}
3980
+ \NormalTok{mtcars}\AttributeTok{.car\_name} \OperatorTok{=}\NormalTok{ mtcars}\AttributeTok{.car\_name.factor} \WarningTok{levels:}\NormalTok{ mtcars}\AttributeTok{.car\_name}
3285
3981
 
3286
- \CommentTok{# let's look at the final data frame}
3287
- \NormalTok{puts mtcars.head}
3982
+ \FunctionTok{puts}\NormalTok{ mtcars}\AttributeTok{.head}
3288
3983
  \end{Highlighting}
3289
3984
  \end{Shaded}
3290
3985
 
@@ -3305,53 +4000,54 @@ first prepare the data frame with the necessary data:
3305
4000
  ## Maserati Bora Maserati Bora -0.84 below
3306
4001
  \end{verbatim}
3307
4002
 
3308
- Now, lets plot the diverging bar plot. When using gKnit, there is no
3309
- need to call `R.awt' to create a plotting device, since gKnit does take
3310
- care of it. Galaaz provides integration with ggplot. The interested
3311
- reader should check online for more information on ggplot, since it is
3312
- outside the scope of this manual describing how ggplot works. We give
3313
- here but a brief description on how this plot is generated.
4003
+ Now, let's plot the diverging bar plot. When using gKnit, you normally
4004
+ do \textbf{not} need to open a graphics device manually; gKnit arranges
4005
+ the figure device for chunk output. Galaaz provides integration with
4006
+ ggplot. The interested reader should check online for more information
4007
+ on ggplot, since it is outside the scope of this manual describing how
4008
+ ggplot works. Here we give only a brief description of how this plot is
4009
+ generated.
3314
4010
 
3315
4011
  ggplot implements the `grammar of graphics'. In this approach, plots are
3316
- build by adding layers to the plot. On the first layer we describe what
4012
+ built by adding layers to the plot. On the first layer we describe what
3317
4013
  we want on the `x' and `y' axis of the plot. In this case, we have
3318
4014
  `car\_name' on the `x' axis and `mpg\_z' on the `y' axis. Then the type
3319
4015
  of graph is specified by adding `geom\_bar' (for a bar graph). We
3320
4016
  specify that our bars should be filled using `mpg\_type', which is
3321
- either `above' or `bellow' giving then two colours for filling. On the
4017
+ either `above' or `below' giving then two colours for filling. On the
3322
4018
  next layer we specify the labels for the graph, then we add the title
3323
4019
  and subtitle. Finally, in a bar chart usually bars go on the vertical
3324
- direction, but in this graph we want the bars to be horizontally layed
3325
- so we add `coord\_flip'.
4020
+ direction, but in this graph we want the bars to be horizontally laid so
4021
+ we add `coord\_flip'.
3326
4022
 
3327
4023
  \begin{Shaded}
3328
4024
  \begin{Highlighting}[]
3329
- \NormalTok{require }\StringTok{'ggplot'}
3330
-
3331
- \NormalTok{puts mtcars.ggplot(E.aes(}\StringTok{x: :car_name}\NormalTok{, }\StringTok{y: :mpg_z}\NormalTok{, }\StringTok{label: :mpg_z}\NormalTok{)) +}
3332
- \NormalTok{ R.geom_bar(E.aes(}\StringTok{fill: :mpg_type}\NormalTok{), }\StringTok{stat: 'identity'}\NormalTok{, }\StringTok{width: }\FloatTok{0.5}\NormalTok{) +}
3333
- \NormalTok{ R.scale_fill_manual(}\StringTok{name: 'Mileage'}\NormalTok{,}
3334
- \StringTok{labels: }\NormalTok{R.c(}\StringTok{'Above Average'}\NormalTok{, }\StringTok{'Below Average'}\NormalTok{),}
3335
- \StringTok{values: }\NormalTok{R.c(}\StringTok{'above'}\NormalTok{: }\StringTok{'#00ba38'}\NormalTok{, }\StringTok{'below'}\NormalTok{: }\StringTok{'#f8766d'}\NormalTok{)) +}
3336
- \NormalTok{ R.labs(}\StringTok{subtitle: "Normalised mileage from 'mtcars'"}\NormalTok{,}
3337
- \StringTok{title: "Diverging Bars"}\NormalTok{) + }
3338
- \NormalTok{ R.coord_flip}
4025
+ \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}ggplot\textquotesingle{}}
4026
+
4027
+ \FunctionTok{puts}\NormalTok{ mtcars}\AttributeTok{.ggplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{x:} \WarningTok{:car\_name}\NormalTok{, }\WarningTok{y:} \WarningTok{:mpg\_z}\NormalTok{, }\WarningTok{label:} \WarningTok{:mpg\_z}\NormalTok{)) }\OperatorTok{+}
4028
+ \ConstantTok{R}\AttributeTok{.geom\_bar}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{fill:} \WarningTok{:mpg\_type}\NormalTok{), }\WarningTok{stat:} \VerbatimStringTok{\textquotesingle{}identity\textquotesingle{}}\NormalTok{, }\WarningTok{width:} \FloatTok{0.5}\NormalTok{) }\OperatorTok{+}
4029
+ \ConstantTok{R}\AttributeTok{.scale\_fill\_manual}\NormalTok{(}\WarningTok{name:} \VerbatimStringTok{\textquotesingle{}Mileage\textquotesingle{}}\NormalTok{,}
4030
+ \WarningTok{labels:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}Above Average\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}Below Average\textquotesingle{}}\NormalTok{),}
4031
+ \WarningTok{values:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}above\textquotesingle{}}\WarningTok{:} \VerbatimStringTok{\textquotesingle{}\#00ba38\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}below\textquotesingle{}}\WarningTok{:} \VerbatimStringTok{\textquotesingle{}\#f8766d\textquotesingle{}}\NormalTok{)) }\OperatorTok{+}
4032
+ \ConstantTok{R}\AttributeTok{.labs}\NormalTok{(}\WarningTok{subtitle:} \StringTok{"Normalised mileage from \textquotesingle{}mtcars\textquotesingle{}"}\NormalTok{,}
4033
+ \WarningTok{title:} \StringTok{"Diverging Bars"}\NormalTok{) }\OperatorTok{+}
4034
+ \ConstantTok{R}\AttributeTok{.coord\_flip}
3339
4035
  \end{Highlighting}
3340
4036
  \end{Shaded}
3341
4037
 
3342
- \includegraphics{manual_files/figure-latex/diverging_bar.pdf}
4038
+ \pandocbounded{\includegraphics[keepaspectratio]{manual_files/figure-latex/diverging_bar.pdf}}
3343
4039
 
3344
4040
  \section{Coding with Tidyverse}\label{coding-with-tidyverse}
3345
4041
 
3346
4042
  In R, and when coding with `tidyverse', arguments to a function are
3347
- usually not \emph{referencially transparent}. That is, you can't replace
4043
+ usually not \emph{referentially transparent}. That is, you can't replace
3348
4044
  a value with a seemingly equivalent object that you've defined
3349
4045
  elsewhere. To see the problem, let's first define a data frame:
3350
4046
 
3351
4047
  \begin{Shaded}
3352
4048
  \begin{Highlighting}[]
3353
- \NormalTok{df = R.data__frame(}\StringTok{x: }\NormalTok{(}\DecValTok{1}\NormalTok{..}\DecValTok{3}\NormalTok{), }\StringTok{y: }\NormalTok{(}\DecValTok{3}\NormalTok{..}\DecValTok{1}\NormalTok{))}
3354
- \NormalTok{puts df}
4049
+ \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}\WarningTok{x:}\NormalTok{ (}\DecValTok{1}\OperatorTok{..}\DecValTok{3}\NormalTok{), }\WarningTok{y:}\NormalTok{ (}\DecValTok{3}\OperatorTok{..}\DecValTok{1}\NormalTok{))}
4050
+ \FunctionTok{puts}\NormalTok{ df}
3355
4051
  \end{Highlighting}
3356
4052
  \end{Shaded}
3357
4053
 
@@ -3366,15 +4062,15 @@ and now, let's look at this code:
3366
4062
 
3367
4063
  \begin{Shaded}
3368
4064
  \begin{Highlighting}[]
3369
- \NormalTok{my_var <-}\StringTok{ }\NormalTok{x}
3370
- \KeywordTok{filter}\NormalTok{(df, my_var }\OperatorTok{==}\StringTok{ }\DecValTok{1}\NormalTok{)}
4065
+ \NormalTok{my\_var }\OtherTok{\textless{}{-}}\NormalTok{ x}
4066
+ \FunctionTok{filter}\NormalTok{(df, my\_var }\SpecialCharTok{==} \DecValTok{1}\NormalTok{)}
3371
4067
  \end{Highlighting}
3372
4068
  \end{Shaded}
3373
4069
 
3374
4070
  It generates the following error: ``object `x' not found.
3375
4071
 
3376
- However, in Galaaz, arguments are referencially transparent as can be
3377
- seen by the code bellow. Note initally that `my\_var = :x' will not give
4072
+ However, in Galaaz, arguments are referentially transparent as can be
4073
+ seen by the code below. Note initially that `my\_var = :x' will not give
3378
4074
  the error ``object `x' not found'' since `:x' is treated as an
3379
4075
  expression and assigned to my\_var. Then when doing (my\_var.eq 1),
3380
4076
  my\_var is a variable that resolves to `:x' and it becomes equivalent to
@@ -3382,8 +4078,8 @@ my\_var is a variable that resolves to `:x' and it becomes equivalent to
3382
4078
 
3383
4079
  \begin{Shaded}
3384
4080
  \begin{Highlighting}[]
3385
- \NormalTok{my_var = }\StringTok{:x}
3386
- \NormalTok{puts df.filter(my_var.eq }\DecValTok{1}\NormalTok{)}
4081
+ \NormalTok{my\_var }\OperatorTok{=} \WarningTok{:x}
4082
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(my\_var}\AttributeTok{.eq} \DecValTok{1}\NormalTok{)}
3387
4083
  \end{Highlighting}
3388
4084
  \end{Shaded}
3389
4085
 
@@ -3392,7 +4088,7 @@ my\_var is a variable that resolves to `:x' and it becomes equivalent to
3392
4088
  ## 1 1 3
3393
4089
  \end{verbatim}
3394
4090
 
3395
- As stated by Hardley
4091
+ As stated by Hadley
3396
4092
 
3397
4093
  \begin{quote}
3398
4094
  dplyr code is ambiguous. Depending on what variables are defined where,
@@ -3416,11 +4112,11 @@ chunks of code:
3416
4112
 
3417
4113
  \begin{Shaded}
3418
4114
  \begin{Highlighting}[]
3419
- \NormalTok{y = }\DecValTok{1}
3420
- \NormalTok{x = }\DecValTok{2}
4115
+ \NormalTok{y }\OperatorTok{=} \DecValTok{1}
4116
+ \NormalTok{x }\OperatorTok{=} \DecValTok{2}
3421
4117
 
3422
- \CommentTok{# looking for values where the 'x' column is equal to the 'y' column}
3423
- \NormalTok{puts df.filter(}\StringTok{:x}\NormalTok{.eq }\StringTok{:y}\NormalTok{)}
4118
+ \CommentTok{\# looking for values where the \textquotesingle{}x\textquotesingle{} column is equal to the \textquotesingle{}y\textquotesingle{} column}
4119
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\WarningTok{:x}\AttributeTok{.eq} \OperatorTok{:}\NormalTok{y)}
3424
4120
  \end{Highlighting}
3425
4121
  \end{Shaded}
3426
4122
 
@@ -3431,9 +4127,9 @@ chunks of code:
3431
4127
 
3432
4128
  \begin{Shaded}
3433
4129
  \begin{Highlighting}[]
3434
- \CommentTok{# looking for values where the 'x' column is equal to the 'y' variable}
3435
- \CommentTok{# in this case, the number 1}
3436
- \NormalTok{puts df.filter(}\StringTok{:x}\NormalTok{.eq y)}
4130
+ \CommentTok{\# looking for values where the \textquotesingle{}x\textquotesingle{} column is equal to the \textquotesingle{}y\textquotesingle{} variable}
4131
+ \CommentTok{\# in this case, the number 1}
4132
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\WarningTok{:x}\AttributeTok{.eq}\NormalTok{ y)}
3437
4133
  \end{Highlighting}
3438
4134
  \end{Shaded}
3439
4135
 
@@ -3471,14 +4167,14 @@ Unfortunately, in R, this function can fail silently if one of the
3471
4167
  variables isn't present in the data frame, but is present in the global
3472
4168
  environment. We will not go through here how to solve this problem in R.
3473
4169
 
3474
- In Galaaz the method mutate\_y bellow will work fine and will never fail
4170
+ In Galaaz the method mutate\_y below will work fine and will never fail
3475
4171
  silently.
3476
4172
 
3477
4173
  \begin{Shaded}
3478
4174
  \begin{Highlighting}[]
3479
- \KeywordTok{def}\NormalTok{ mutate_y(df)}
3480
- \NormalTok{ df.mutate(}\StringTok{:y}\NormalTok{.assign }\StringTok{:a}\NormalTok{ + }\StringTok{:x}\NormalTok{)}
3481
- \KeywordTok{end}
4175
+ \ControlFlowTok{def}\NormalTok{ mutate\_y(df)}
4176
+ \NormalTok{ df}\AttributeTok{.mutate}\NormalTok{(}\WarningTok{:y}\AttributeTok{.assign} \OperatorTok{:}\NormalTok{a }\OperatorTok{+} \WarningTok{:x}\NormalTok{)}
4177
+ \ControlFlowTok{end}
3482
4178
  \end{Highlighting}
3483
4179
  \end{Shaded}
3484
4180
 
@@ -3486,8 +4182,8 @@ Here we create a data frame that has only one column named `x':
3486
4182
 
3487
4183
  \begin{Shaded}
3488
4184
  \begin{Highlighting}[]
3489
- \NormalTok{df1 = R.data__frame(}\StringTok{x: }\NormalTok{(}\DecValTok{1}\NormalTok{..}\DecValTok{3}\NormalTok{))}
3490
- \NormalTok{puts df1}
4185
+ \NormalTok{df1 }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}\WarningTok{x:}\NormalTok{ (}\DecValTok{1}\OperatorTok{..}\DecValTok{3}\NormalTok{))}
4186
+ \FunctionTok{puts}\NormalTok{ df1}
3491
4187
  \end{Highlighting}
3492
4188
  \end{Shaded}
3493
4189
 
@@ -3498,48 +4194,44 @@ Here we create a data frame that has only one column named `x':
3498
4194
  ## 3 3
3499
4195
  \end{verbatim}
3500
4196
 
3501
- Note that method mutate\_y will fail independetly from the fact that
4197
+ Note that method mutate\_y will fail independently from the fact that
3502
4198
  variable `a' is defined and in the scope of the method. Variable `a' has
3503
4199
  no relationship with the symbol `:a' used in the definition of
3504
4200
  `mutate\_y' above:
3505
4201
 
3506
4202
  \begin{Shaded}
3507
4203
  \begin{Highlighting}[]
3508
- \NormalTok{a = }\DecValTok{10}
3509
- \NormalTok{mutate_y(df1)}
4204
+ \NormalTok{a }\OperatorTok{=} \DecValTok{10}
4205
+ \NormalTok{mutate\_y(df1)}
3510
4206
  \end{Highlighting}
3511
4207
  \end{Shaded}
3512
4208
 
3513
4209
  \begin{verbatim}
3514
- ## Message:
3515
- ## Error in mutate_impl(.data, dots) :
3516
- ## Evaluation error: object 'a' not found.
3517
- ## In addition: Warning message:
3518
- ## In mutate_impl(.data, dots) :
3519
- ## mismatched protect/unprotect (unprotect with empty protect stack) (RError)
3520
- ## Translated to internal error
4210
+ ## Error in strsplit(path, "/") : non-character argument
4211
+ ## Calls: mutate ... .rlang_purrr_map_mold -> vapply -> FUN -> path_trim_prefix -> strsplit
3521
4212
  \end{verbatim}
3522
4213
 
3523
4214
  \subsection{Different expressions}\label{different-expressions}
3524
4215
 
3525
- Let's move to the next problem as presented by Hardley where trying to
4216
+ Let's move to the next problem as presented by Hadley where trying to
3526
4217
  write a function in R that will receive two argumens, the first a
3527
- variable and the second an expression is not trivial. Bellow we create a
4218
+ variable and the second an expression is not trivial. Below we create a
3528
4219
  data frame and we want to write a function that groups data by a
3529
4220
  variable and summarises it by an expression:
3530
4221
 
3531
4222
  \begin{Shaded}
3532
4223
  \begin{Highlighting}[]
3533
- \KeywordTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)}
3534
-
3535
- \NormalTok{df <-}\StringTok{ }\KeywordTok{data.frame}\NormalTok{(}
3536
- \DataTypeTok{g1 =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{),}
3537
- \DataTypeTok{g2 =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{1}\NormalTok{),}
3538
- \DataTypeTok{a =} \KeywordTok{sample}\NormalTok{(}\DecValTok{5}\NormalTok{),}
3539
- \DataTypeTok{b =} \KeywordTok{sample}\NormalTok{(}\DecValTok{5}\NormalTok{)}
4224
+ \FunctionTok{library}\NormalTok{(dplyr)}
4225
+ \FunctionTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)}
4226
+
4227
+ \NormalTok{df }\OtherTok{\textless{}{-}} \FunctionTok{data.frame}\NormalTok{(}
4228
+ \AttributeTok{g1 =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{),}
4229
+ \AttributeTok{g2 =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{1}\NormalTok{),}
4230
+ \AttributeTok{a =} \FunctionTok{sample}\NormalTok{(}\DecValTok{5}\NormalTok{),}
4231
+ \AttributeTok{b =} \FunctionTok{sample}\NormalTok{(}\DecValTok{5}\NormalTok{)}
3540
4232
  \NormalTok{)}
3541
4233
 
3542
- \KeywordTok{as.data.frame}\NormalTok{(df) }
4234
+ \FunctionTok{as.data.frame}\NormalTok{(df) }
3543
4235
  \end{Highlighting}
3544
4236
  \end{Shaded}
3545
4237
 
@@ -3554,11 +4246,11 @@ variable and summarises it by an expression:
3554
4246
 
3555
4247
  \begin{Shaded}
3556
4248
  \begin{Highlighting}[]
3557
- \NormalTok{d2 <-}\StringTok{ }\NormalTok{df }\OperatorTok{%>%}
3558
- \StringTok{ }\KeywordTok{group_by}\NormalTok{(g1) }\OperatorTok{%>%}
3559
- \StringTok{ }\KeywordTok{summarise}\NormalTok{(}\DataTypeTok{a =} \KeywordTok{mean}\NormalTok{(a))}
4249
+ \NormalTok{d2 }\OtherTok{\textless{}{-}}\NormalTok{ df }\SpecialCharTok{\%\textgreater{}\%}
4250
+ \FunctionTok{group\_by}\NormalTok{(g1) }\SpecialCharTok{\%\textgreater{}\%}
4251
+ \FunctionTok{summarise}\NormalTok{(}\AttributeTok{a =} \FunctionTok{mean}\NormalTok{(a))}
3560
4252
 
3561
- \KeywordTok{as.data.frame}\NormalTok{(d2) }
4253
+ \FunctionTok{as.data.frame}\NormalTok{(d2) }
3562
4254
  \end{Highlighting}
3563
4255
  \end{Shaded}
3564
4256
 
@@ -3570,11 +4262,11 @@ variable and summarises it by an expression:
3570
4262
 
3571
4263
  \begin{Shaded}
3572
4264
  \begin{Highlighting}[]
3573
- \NormalTok{d2 <-}\StringTok{ }\NormalTok{df }\OperatorTok{%>%}
3574
- \StringTok{ }\KeywordTok{group_by}\NormalTok{(g2) }\OperatorTok{%>%}
3575
- \StringTok{ }\KeywordTok{summarise}\NormalTok{(}\DataTypeTok{a =} \KeywordTok{mean}\NormalTok{(a))}
4265
+ \NormalTok{d2 }\OtherTok{\textless{}{-}}\NormalTok{ df }\SpecialCharTok{\%\textgreater{}\%}
4266
+ \FunctionTok{group\_by}\NormalTok{(g2) }\SpecialCharTok{\%\textgreater{}\%}
4267
+ \FunctionTok{summarise}\NormalTok{(}\AttributeTok{a =} \FunctionTok{mean}\NormalTok{(a))}
3576
4268
 
3577
- \KeywordTok{as.data.frame}\NormalTok{(d2) }
4269
+ \FunctionTok{as.data.frame}\NormalTok{(d2) }
3578
4270
  \end{Highlighting}
3579
4271
  \end{Shaded}
3580
4272
 
@@ -3584,35 +4276,35 @@ variable and summarises it by an expression:
3584
4276
  ## 2 2 3
3585
4277
  \end{verbatim}
3586
4278
 
3587
- As shown by Hardley, one might expect this function to do the trick:
4279
+ As shown by Hadley, one might expect this function to do the trick:
3588
4280
 
3589
4281
  \begin{Shaded}
3590
4282
  \begin{Highlighting}[]
3591
- \NormalTok{my_summarise <-}\StringTok{ }\ControlFlowTok{function}\NormalTok{(df, group_var) \{}
3592
- \NormalTok{ df }\OperatorTok{%>%}
3593
- \StringTok{ }\KeywordTok{group_by}\NormalTok{(group_var) }\OperatorTok{%>%}
3594
- \StringTok{ }\KeywordTok{summarise}\NormalTok{(}\DataTypeTok{a =} \KeywordTok{mean}\NormalTok{(a))}
4283
+ \NormalTok{my\_summarise }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(df, group\_var) \{}
4284
+ \NormalTok{ df }\SpecialCharTok{\%\textgreater{}\%}
4285
+ \FunctionTok{group\_by}\NormalTok{(group\_var) }\SpecialCharTok{\%\textgreater{}\%}
4286
+ \FunctionTok{summarise}\NormalTok{(}\AttributeTok{a =} \FunctionTok{mean}\NormalTok{(a))}
3595
4287
  \NormalTok{\}}
3596
4288
 
3597
- \CommentTok{# my_summarise(df, g1)}
3598
- \CommentTok{#> Error: Column `group_var` is unknown}
4289
+ \CommentTok{\# my\_summarise(df, g1)}
4290
+ \CommentTok{\#\textgreater{} Error: Column \textasciigrave{}group\_var\textasciigrave{} is unknown}
3599
4291
  \end{Highlighting}
3600
4292
  \end{Shaded}
3601
4293
 
3602
4294
  In order to solve this problem, coding with dplyr requires the
3603
4295
  introduction of many new concepts and functions such as `quo', `quos',
3604
4296
  `enquo', `enquos', `!!' (bang bang), `!!!' (triple bang). Again, we'll
3605
- leave to Hardley the explanation on how to use all those functions.
4297
+ leave to Hadley the explanation on how to use all those functions.
3606
4298
 
3607
4299
  Now, let's try to implement the same function in galaaz. The next code
3608
4300
  block first prints the `df' data frame defined previously in R (to
3609
- access an R variable from Galaaz, we use the tilda operator
3610
- `\textasciitilde{}' applied to the R variable name as symbol, i.e.,
3611
- `:df'.
4301
+ access an R variable from Galaaz, we use the tilde operator
4302
+ \texttt{\textasciitilde{}} applied to the R variable name as a symbol,
4303
+ e.g.~\texttt{:df}).
3612
4304
 
3613
4305
  \begin{Shaded}
3614
4306
  \begin{Highlighting}[]
3615
- \NormalTok{puts ~}\StringTok{:df}
4307
+ \FunctionTok{puts} \OperatorTok{\textasciitilde{}}\WarningTok{:df}
3616
4308
  \end{Highlighting}
3617
4309
  \end{Shaded}
3618
4310
 
@@ -3630,12 +4322,12 @@ frame and the group by variable `:g1':
3630
4322
 
3631
4323
  \begin{Shaded}
3632
4324
  \begin{Highlighting}[]
3633
- \KeywordTok{def}\NormalTok{ my_summarize(df, group_var)}
3634
- \NormalTok{ df.group_by(group_var).}
3635
- \NormalTok{ summarize(}\StringTok{a: :a}\NormalTok{.mean)}
3636
- \KeywordTok{end}
4325
+ \ControlFlowTok{def}\NormalTok{ my\_summarize(df, group\_var)}
4326
+ \NormalTok{ df}\AttributeTok{.group\_by}\NormalTok{(group\_var)}\AttributeTok{.}
4327
+ \AttributeTok{summarize}\NormalTok{(}\WarningTok{a:} \WarningTok{:a}\AttributeTok{.mean}\NormalTok{)}
4328
+ \ControlFlowTok{end}
3637
4329
 
3638
- \NormalTok{puts my_summarize(}\StringTok{:df}\NormalTok{, }\StringTok{:g1}\NormalTok{)}
4330
+ \FunctionTok{puts}\NormalTok{ my\_summarize(}\WarningTok{:df}\NormalTok{, }\WarningTok{:g1}\NormalTok{)}
3639
4331
  \end{Highlighting}
3640
4332
  \end{Shaded}
3641
4333
 
@@ -3651,7 +4343,7 @@ It works!!! Well, let's make sure this was not just some coincidence
3651
4343
 
3652
4344
  \begin{Shaded}
3653
4345
  \begin{Highlighting}[]
3654
- \NormalTok{puts my_summarize(}\StringTok{:df}\NormalTok{, }\StringTok{:g2}\NormalTok{)}
4346
+ \FunctionTok{puts}\NormalTok{ my\_summarize(}\WarningTok{:df}\NormalTok{, }\WarningTok{:g2}\NormalTok{)}
3655
4347
  \end{Highlighting}
3656
4348
  \end{Shaded}
3657
4349
 
@@ -3674,9 +4366,9 @@ for a simple example, but does this remain true for more complex
3674
4366
  examples, or will the Galaaz way prove inpractical for more complex
3675
4367
  code?
3676
4368
 
3677
- In the next example Hardley proposes us to write a function that given
3678
- an expression such as `a' or `a * b', calculates three summaries. What
3679
- we want a function that does the same as these R statements:
4369
+ In the next example Hadley proposes us to write a function that given an
4370
+ expression such as `a' or `a * b', calculates three summaries. What we
4371
+ want a function that does the same as these R statements:
3680
4372
 
3681
4373
  \begin{verbatim}
3682
4374
  summarise(df, mean = mean(a), sum = sum(a), n = n())
@@ -3696,17 +4388,18 @@ Let's try it in galaaz:
3696
4388
 
3697
4389
  \begin{Shaded}
3698
4390
  \begin{Highlighting}[]
3699
- \KeywordTok{def}\NormalTok{ my_summarise2(df, expr)}
3700
- \NormalTok{ df.summarize(}
3701
- \StringTok{mean: }\NormalTok{E.mean(expr),}
3702
- \StringTok{sum: }\NormalTok{E.sum(expr),}
3703
- \StringTok{n: }\NormalTok{E.n}
4391
+ \ControlFlowTok{def}\NormalTok{ my\_summarise2(df, expr)}
4392
+ \NormalTok{ df}\AttributeTok{.summarize}\NormalTok{(}
4393
+ \WarningTok{mean:} \ConstantTok{E}\AttributeTok{.mean}\NormalTok{(expr),}
4394
+ \WarningTok{sum:} \ConstantTok{E}\AttributeTok{.sum}\NormalTok{(expr),}
4395
+ \WarningTok{n:} \ConstantTok{E}\AttributeTok{.n}
3704
4396
  \NormalTok{ )}
3705
- \KeywordTok{end}
4397
+ \ControlFlowTok{end}
3706
4398
 
3707
- \NormalTok{puts my_summarise2((~}\StringTok{:df}\NormalTok{), }\StringTok{:a}\NormalTok{)}
3708
- \NormalTok{puts }\StringTok{"\textbackslash{}n"}
3709
- \NormalTok{puts my_summarise2((~}\StringTok{:df}\NormalTok{), }\StringTok{:a}\NormalTok{ * }\StringTok{:b}\NormalTok{)}
4399
+ \FunctionTok{puts}\NormalTok{ my\_summarise2((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:a}\NormalTok{)}
4400
+ \FunctionTok{puts} \StringTok{"}
4401
+ \StringTok{"}
4402
+ \FunctionTok{puts}\NormalTok{ my\_summarise2((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:a} \OperatorTok{*} \WarningTok{:b}\NormalTok{)}
3710
4403
  \end{Highlighting}
3711
4404
  \end{Shaded}
3712
4405
 
@@ -3725,7 +4418,7 @@ from functions `mean', `sum' and `n'.
3725
4418
  \subsection{Different input and output
3726
4419
  variable}\label{different-input-and-output-variable}
3727
4420
 
3728
- Now the next challenge presented by Hardley is to vary the name of the
4421
+ Now the next challenge presented by Hadley is to vary the name of the
3729
4422
  output variables based on the received expression. So, if the input
3730
4423
  expression is `a', we want our data frame columns to be named `mean\_a'
3731
4424
  and `sum\_a'. Now, if the input expression is `b', columns should be
@@ -3753,25 +4446,26 @@ mutate(df, mean_b = mean(b), sum_b = sum(b))
3753
4446
  #> # … with 1 more row
3754
4447
  \end{verbatim}
3755
4448
 
3756
- In order to solve this problem in R, Hardley needs to introduce some
3757
- more new functions and notations: `quo\_name' and the `:=' operator from
4449
+ In order to solve this problem in R, Hadley needs to introduce some more
4450
+ new functions and notations: `quo\_name' and the `:=' operator from
3758
4451
  package `rlang'
3759
4452
 
3760
4453
  Here is our Ruby code:
3761
4454
 
3762
4455
  \begin{Shaded}
3763
4456
  \begin{Highlighting}[]
3764
- \KeywordTok{def}\NormalTok{ my_mutate(df, expr)}
3765
- \NormalTok{ mean_name = }\StringTok{"mean_}\OtherTok{#\{}\NormalTok{expr.to_s}\OtherTok{\}}\StringTok{"}
3766
- \NormalTok{ sum_name = }\StringTok{"sum_}\OtherTok{#\{}\NormalTok{expr.to_s}\OtherTok{\}}\StringTok{"}
3767
-
3768
- \NormalTok{ df.mutate(mean_name => E.mean(expr),}
3769
- \NormalTok{ sum_name => E.sum(expr))}
3770
- \KeywordTok{end}
3771
-
3772
- \NormalTok{puts my_mutate((~}\StringTok{:df}\NormalTok{), }\StringTok{:a}\NormalTok{)}
3773
- \NormalTok{puts }\StringTok{"\textbackslash{}n"}
3774
- \NormalTok{puts my_mutate((~}\StringTok{:df}\NormalTok{), }\StringTok{:b}\NormalTok{)}
4457
+ \ControlFlowTok{def}\NormalTok{ my\_mutate(df, expr)}
4458
+ \NormalTok{ mean\_name }\OperatorTok{=} \StringTok{"mean\_}\SpecialCharTok{\#\{}\NormalTok{expr}\AttributeTok{.to\_s}\SpecialCharTok{\}}\StringTok{"}
4459
+ \NormalTok{ sum\_name }\OperatorTok{=} \StringTok{"sum\_}\SpecialCharTok{\#\{}\NormalTok{expr}\AttributeTok{.to\_s}\SpecialCharTok{\}}\StringTok{"}
4460
+
4461
+ \NormalTok{ df}\AttributeTok{.mutate}\NormalTok{(mean\_name }\OperatorTok{=\textgreater{}} \ConstantTok{E}\AttributeTok{.mean}\NormalTok{(expr),}
4462
+ \NormalTok{ sum\_name }\OperatorTok{=\textgreater{}} \ConstantTok{E}\AttributeTok{.sum}\NormalTok{(expr))}
4463
+ \ControlFlowTok{end}
4464
+
4465
+ \FunctionTok{puts}\NormalTok{ my\_mutate((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:a}\NormalTok{)}
4466
+ \FunctionTok{puts} \StringTok{"}
4467
+ \StringTok{"}
4468
+ \FunctionTok{puts}\NormalTok{ my\_mutate((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:b}\NormalTok{)}
3775
4469
  \end{Highlighting}
3776
4470
  \end{Shaded}
3777
4471
 
@@ -3794,38 +4488,38 @@ Here is our Ruby code:
3794
4488
  It really seems that ``Non Standard Evaluation'' is actually quite
3795
4489
  standard in Galaaz! But, you might have noticed a small change in the
3796
4490
  way the arguments to the mutate method were called. In a previous
3797
- example we used df.summarise(mean: E.mean(:a), \ldots{}) where the
3798
- column name was followed by a `:' colom. In this example, we have
3799
- df.mutate(mean\_name =\textgreater{} E.mean(expr), \ldots{}) and
3800
- variable mean\_name is not followed by `:' but by `=\textgreater{}'.
3801
- This is standard Ruby notation.
4491
+ example we used df.summarise(mean: E.mean(:a), \ldots) where the column
4492
+ name was followed by a `:' colom. In this example, we have
4493
+ df.mutate(mean\_name =\textgreater{} E.mean(expr), \ldots) and variable
4494
+ mean\_name is not followed by `:' but by `=\textgreater{}'. This is
4495
+ standard Ruby notation.
3802
4496
 
3803
- {[}explain\ldots{}.{]}
4497
+ {[}explain\ldots.{]}
3804
4498
 
3805
4499
  \subsection{Capturing multiple
3806
4500
  variables}\label{capturing-multiple-variables}
3807
4501
 
3808
- Moving on with new complexities, Hardley proposes us to solve the
3809
- problem in which the summarise function will receive any number of
3810
- grouping variables.
4502
+ Moving on with new complexities, Hadley proposes us to solve the problem
4503
+ in which the summarise function will receive any number of grouping
4504
+ variables.
3811
4505
 
3812
4506
  This again is quite standard Ruby. In order to receive an undefined
3813
4507
  number of paramenters the paramenter is preceded by '*':
3814
4508
 
3815
4509
  \begin{Shaded}
3816
4510
  \begin{Highlighting}[]
3817
- \KeywordTok{def}\NormalTok{ my_summarise3(df, *group_vars)}
3818
- \NormalTok{ df.group_by(*group_vars).}
3819
- \NormalTok{ summarise(}\StringTok{a: }\NormalTok{E.mean(}\StringTok{:a}\NormalTok{))}
3820
- \KeywordTok{end}
4511
+ \ControlFlowTok{def}\NormalTok{ my\_summarise3(df, }\OperatorTok{*}\NormalTok{group\_vars)}
4512
+ \NormalTok{ df}\AttributeTok{.group\_by}\NormalTok{(}\OperatorTok{*}\NormalTok{group\_vars)}\AttributeTok{.}
4513
+ \AttributeTok{summarise}\NormalTok{(}\WarningTok{a:} \ConstantTok{E}\AttributeTok{.mean}\NormalTok{(}\WarningTok{:a}\NormalTok{))}
4514
+ \ControlFlowTok{end}
3821
4515
 
3822
- \NormalTok{puts my_summarise3((~}\StringTok{:df}\NormalTok{), }\StringTok{:g1}\NormalTok{, }\StringTok{:g2}\NormalTok{)}
4516
+ \FunctionTok{puts}\NormalTok{ my\_summarise3((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:g1}\NormalTok{, }\WarningTok{:g2}\NormalTok{)}
3823
4517
  \end{Highlighting}
3824
4518
  \end{Shaded}
3825
4519
 
3826
4520
  \begin{verbatim}
3827
4521
  ## # A tibble: 4 x 3
3828
- ## # Groups: g1 [?]
4522
+ ## # Groups: g1 [2]
3829
4523
  ## g1 g2 a
3830
4524
  ## <dbl> <dbl> <dbl>
3831
4525
  ## 1 1 1 3
@@ -3895,41 +4589,59 @@ the Starwars movies:
3895
4589
 
3896
4590
  \begin{Shaded}
3897
4591
  \begin{Highlighting}[]
3898
- \NormalTok{puts (~}\StringTok{:starwars}\NormalTok{).head}
4592
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:starwars}\NormalTok{)}\AttributeTok{.head}
3899
4593
  \end{Highlighting}
3900
4594
  \end{Shaded}
3901
4595
 
3902
4596
  \begin{verbatim}
3903
- ## # A tibble: 6 x 13
3904
- ## name height mass hair_color skin_color eye_color birth_year gender
3905
- ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr>
3906
- ## 1 Luke~ 172 77 blond fair blue 19 male
3907
- ## 2 C-3PO 167 75 <NA> gold yellow 112 <NA>
3908
- ## 3 R2-D2 96 32 <NA> white, bl~ red 33 <NA>
3909
- ## 4 Dart~ 202 136 none white yellow 41.9 male
3910
- ## 5 Leia~ 150 49 brown light brown 19 female
3911
- ## 6 Owen~ 178 120 brown, gr~ light blue 52 male
3912
- ## # ... with 5 more variables: homeworld <chr>, species <chr>, films <list>,
4597
+ ## # A tibble: 6 x 14
4598
+ ## name height mass hair_color skin_color eye_color birth_year sex gender
4599
+ ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr>
4600
+ ## 1 Luke Sky~ 172 77 blond fair blue 19 male mascu~
4601
+ ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu~
4602
+ ## 3 R2-D2 96 32 <NA> white, bl~ red 33 none mascu~
4603
+ ## 4 Darth Va~ 202 136 none white yellow 41.9 male mascu~
4604
+ ## 5 Leia Org~ 150 49 brown light brown 19 fema~ femin~
4605
+ ## 6 Owen Lars 178 120 brown, gr~ light blue 52 male mascu~
4606
+ ## # i 5 more variables: homeworld <chr>, species <chr>, films <list>,
3913
4607
  ## # vehicles <list>, starships <list>
3914
4608
  \end{verbatim}
3915
4609
 
3916
- The grouped\_mean function bellow will receive a grouping variable and
4610
+ The grouped\_mean function below will receive a grouping variable and
3917
4611
  calculate summaries for the value\_variables given:
3918
4612
 
3919
4613
  \begin{Shaded}
3920
4614
  \begin{Highlighting}[]
3921
- \NormalTok{grouped_mean <-}\StringTok{ }\ControlFlowTok{function}\NormalTok{(data, grouping_variables, value_variables) \{}
3922
- \NormalTok{ data }\OperatorTok{%>%}
3923
- \StringTok{ }\KeywordTok{group_by_at}\NormalTok{(grouping_variables) }\OperatorTok{%>%}
3924
- \StringTok{ }\KeywordTok{mutate}\NormalTok{(}\DataTypeTok{count =} \KeywordTok{n}\NormalTok{()) }\OperatorTok{%>%}
3925
- \StringTok{ }\KeywordTok{summarise_at}\NormalTok{(}\KeywordTok{c}\NormalTok{(value_variables, }\StringTok{"count"}\NormalTok{), mean, }\DataTypeTok{na.rm =} \OtherTok{TRUE}\NormalTok{) }\OperatorTok{%>%}
3926
- \StringTok{ }\KeywordTok{rename_at}\NormalTok{(value_variables, }\KeywordTok{funs}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(}\StringTok{"mean_"}\NormalTok{, .)))}
4615
+ \FunctionTok{library}\NormalTok{(dplyr)}
4616
+ \NormalTok{grouped\_mean }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(data, grouping\_variables, value\_variables) \{}
4617
+ \NormalTok{ data }\SpecialCharTok{\%\textgreater{}\%}
4618
+ \FunctionTok{group\_by\_at}\NormalTok{(grouping\_variables) }\SpecialCharTok{\%\textgreater{}\%}
4619
+ \FunctionTok{mutate}\NormalTok{(}\AttributeTok{count =} \FunctionTok{n}\NormalTok{()) }\SpecialCharTok{\%\textgreater{}\%}
4620
+ \FunctionTok{summarise\_at}\NormalTok{(}\FunctionTok{c}\NormalTok{(value\_variables, }\StringTok{"count"}\NormalTok{), mean, }\AttributeTok{na.rm =} \ConstantTok{TRUE}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%}
4621
+ \FunctionTok{rename\_at}\NormalTok{(value\_variables, }\FunctionTok{funs}\NormalTok{(}\FunctionTok{paste0}\NormalTok{(}\StringTok{"mean\_"}\NormalTok{, .)))}
3927
4622
  \NormalTok{ \}}
3928
4623
 
3929
- \NormalTok{gm =}\StringTok{ }\NormalTok{starwars }\OperatorTok{%>%}\StringTok{ }
3930
- \StringTok{ }\KeywordTok{grouped_mean}\NormalTok{(}\StringTok{"eye_color"}\NormalTok{, }\KeywordTok{c}\NormalTok{(}\StringTok{"mass"}\NormalTok{, }\StringTok{"birth_year"}\NormalTok{))}
4624
+ \NormalTok{gm }\OtherTok{=}\NormalTok{ starwars }\SpecialCharTok{\%\textgreater{}\%}
4625
+ \FunctionTok{grouped\_mean}\NormalTok{(}\StringTok{"eye\_color"}\NormalTok{, }\FunctionTok{c}\NormalTok{(}\StringTok{"mass"}\NormalTok{, }\StringTok{"birth\_year"}\NormalTok{))}
4626
+ \end{Highlighting}
4627
+ \end{Shaded}
4628
+
4629
+ \begin{verbatim}
4630
+ ## Warning: `funs()` was deprecated in dplyr 0.8.0.
4631
+ ## i Please use a list of either functions or lambdas:
4632
+ ##
4633
+ ## # Simple named list: list(mean = mean, median = median)
4634
+ ##
4635
+ ## # Auto named with `tibble::lst()`: tibble::lst(mean, median)
4636
+ ##
4637
+ ## # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
4638
+ ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
4639
+ ## generated.
4640
+ \end{verbatim}
3931
4641
 
3932
- \KeywordTok{as.data.frame}\NormalTok{(gm) }
4642
+ \begin{Shaded}
4643
+ \begin{Highlighting}[]
4644
+ \FunctionTok{as.data.frame}\NormalTok{(gm) }
3933
4645
  \end{Highlighting}
3934
4646
  \end{Shaded}
3935
4647
 
@@ -3956,15 +4668,15 @@ The same code with Galaaz, becomes:
3956
4668
 
3957
4669
  \begin{Shaded}
3958
4670
  \begin{Highlighting}[]
3959
- \KeywordTok{def}\NormalTok{ grouped_mean(data, grouping_variables, value_variables)}
3960
- \NormalTok{ data.}
3961
- \NormalTok{ group_by_at(grouping_variables).}
3962
- \NormalTok{ mutate(}\StringTok{count: }\NormalTok{E.n).}
3963
- \NormalTok{ summarise_at(E.c(value_variables, }\StringTok{"count"}\NormalTok{), ~}\StringTok{:mean}\NormalTok{, }\StringTok{na__rm: }\DecValTok{true}\NormalTok{).}
3964
- \NormalTok{ rename_at(value_variables, E.funs(E.paste0(}\StringTok{"mean_"}\NormalTok{, value_variables)))}
3965
- \KeywordTok{end}
3966
-
3967
- \NormalTok{puts grouped_mean((~}\StringTok{:starwars}\NormalTok{), }\StringTok{"eye_color"}\NormalTok{, E.c(}\StringTok{"mass"}\NormalTok{, }\StringTok{"birth_year"}\NormalTok{))}
4671
+ \ControlFlowTok{def}\NormalTok{ grouped\_mean(data, grouping\_variables, value\_variables)}
4672
+ \NormalTok{ data}\AttributeTok{.}
4673
+ \AttributeTok{group\_by\_at}\NormalTok{(grouping\_variables)}\AttributeTok{.}
4674
+ \AttributeTok{mutate}\NormalTok{(}\WarningTok{count:} \ConstantTok{E}\AttributeTok{.n}\NormalTok{)}\AttributeTok{.}
4675
+ \AttributeTok{summarise\_at}\NormalTok{(}\ConstantTok{E}\AttributeTok{.c}\NormalTok{(value\_variables, }\StringTok{"count"}\NormalTok{), }\OperatorTok{\textasciitilde{}}\WarningTok{:mean}\NormalTok{, }\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{)}\AttributeTok{.}
4676
+ \AttributeTok{rename\_at}\NormalTok{(value\_variables, }\ConstantTok{E}\AttributeTok{.funs}\NormalTok{(}\ConstantTok{E}\AttributeTok{.paste0}\NormalTok{(}\StringTok{"mean\_"}\NormalTok{, value\_variables)))}
4677
+ \ControlFlowTok{end}
4678
+
4679
+ \FunctionTok{puts}\NormalTok{ grouped\_mean((}\OperatorTok{\textasciitilde{}}\WarningTok{:starwars}\NormalTok{), }\StringTok{"eye\_color"}\NormalTok{, }\ConstantTok{E}\AttributeTok{.c}\NormalTok{(}\StringTok{"mass"}\NormalTok{, }\StringTok{"birth\_year"}\NormalTok{))}
3968
4680
  \end{Highlighting}
3969
4681
  \end{Shaded}
3970
4682
 
@@ -3989,7 +4701,11 @@ The same code with Galaaz, becomes:
3989
4701
  ## 15 yellow 81.1 76.4 11
3990
4702
  \end{verbatim}
3991
4703
 
3992
- {[}TO BE CONTINUED\ldots{}{]}
4704
+ The examples above cover programmatic dplyr with string column names and
4705
+ \texttt{\_at} helpers. The same Galaaz patterns (symbols, \texttt{E.*}
4706
+ for expression-safe functions, and Ruby methods on R-backed objects)
4707
+ extend to other tidyverse workflows; consult R package documentation for
4708
+ function-specific arguments.
3993
4709
 
3994
4710
  \section{Contributing}\label{contributing}
3995
4711
 
@@ -3998,29 +4714,35 @@ The same code with Galaaz, becomes:
3998
4714
  \item
3999
4715
  Fork it
4000
4716
  \item
4001
- Create your feature branch (git checkout -b my-new-feature)
4717
+ Create your feature branch
4718
+ (\texttt{git\ checkout\ -b\ my-new-feature})
4002
4719
  \item
4003
- Write Tests!
4720
+ Write tests --- use \textbf{\texttt{bin/run\_rspec}} or
4721
+ \textbf{\texttt{bin/run\_all\_rspec}} with \textbf{JRuby} so JVM flags
4722
+ and the load path match \textbf{\texttt{docs/testing.md}}
4004
4723
  \item
4005
- Commit your changes (git commit -am `Add some feature')
4724
+ Commit your changes
4725
+ (\texttt{git\ commit\ -am\ \textquotesingle{}Add\ some\ feature\textquotesingle{}})
4006
4726
  \item
4007
- Push to the branch (git push origin my-new-feature)
4727
+ Push to the branch (\texttt{git\ push\ origin\ my-new-feature})
4008
4728
  \item
4009
- Create new Pull Request
4729
+ Open a pull request
4010
4730
  \end{itemize}
4011
4731
 
4012
4732
  \section*{References}\label{references}
4013
4733
  \addcontentsline{toc}{section}{References}
4014
4734
 
4015
- \hypertarget{refs}{}
4016
- \hypertarget{ref-Knuth:literate_programming}{}
4017
- Knuth, Donald E. 1984. ``Literate Programming.'' \emph{Comput. J.} 27
4018
- (2). Oxford, UK: Oxford University Press: 97--111.
4019
- doi:\href{https://doi.org/10.1093/comjnl/27.2.97}{10.1093/comjnl/27.2.97}.
4735
+ \protect\phantomsection\label{refs}
4736
+ \begin{CSLReferences}{1}{1}
4737
+ \bibitem[\citeproctext]{ref-Knuth:literate_programming}
4738
+ Knuth, Donald E. 1984. {``Literate Programming.''} \emph{Comput. J.}
4739
+ (Oxford, UK) 27 (2): 97--111.
4740
+ \url{https://doi.org/10.1093/comjnl/27.2.97}.
4020
4741
 
4021
- \hypertarget{ref-Wilkinson:grammar_of_graphics}{}
4742
+ \bibitem[\citeproctext]{ref-Wilkinson:grammar_of_graphics}
4022
4743
  Wilkinson, Leland. 2005. \emph{The Grammar of Graphics (Statistics and
4023
- Computing)}. Berlin, Heidelberg: Springer-Verlag.
4744
+ Computing)}. Springer-Verlag.
4024
4745
 
4746
+ \end{CSLReferences}
4025
4747
 
4026
4748
  \end{document}