galaaz 0.5.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (359) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/LICENSE +0 -0
  4. data/README.md +1360 -636
  5. data/Rakefile +61 -41
  6. data/bin/galaaz-bootstrap +137 -0
  7. data/bin/galaaz-jruby +14 -0
  8. data/bin/galaaz_jruby_env.inc.sh +6 -0
  9. data/bin/gbookdown +64 -0
  10. data/bin/gknit +84 -13
  11. data/bin/gknit-draft.rb +0 -0
  12. data/bin/gstudio +5 -3
  13. data/bin/gstudio_irb.rb +0 -0
  14. data/bin/gstudio_pry.rb +0 -0
  15. data/bin/install-tinytex +6 -0
  16. data/bin/run_all_rspec +43 -0
  17. data/bin/run_example +14 -0
  18. data/bin/run_old_rspec +19 -0
  19. data/bin/run_rspec +23 -0
  20. data/bin/run_rspec_subset +38 -0
  21. data/bin/run_slow_rspec +19 -0
  22. data/blogs/R-on-Rails-Planning-Document.md +940 -0
  23. data/blogs/README.md +100 -0
  24. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +38 -66
  25. data/blogs/galaaz_ggplot/galaaz_ggplot.log +754 -0
  26. data/blogs/galaaz_ggplot/galaaz_ggplot.md +115 -155
  27. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +607 -0
  28. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
  29. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
  30. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
  31. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
  32. data/blogs/galaaz_ggplot/midwest.Rmd +3 -3
  33. data/blogs/galaaz_ggplot/midwest_external_png +0 -0
  34. data/blogs/gknit/gknit.Rmd +47 -52
  35. data/blogs/gknit/gknit.md +1430 -0
  36. data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
  37. data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
  38. data/blogs/gknit/lst.rds +0 -0
  39. data/blogs/gknit/model.rb +1 -1
  40. data/blogs/gknit/stats.bib +0 -0
  41. data/blogs/manual/include_model_local_repro.Rmd +14 -0
  42. data/blogs/manual/include_model_local_repro.md +75 -0
  43. data/blogs/manual/lst.rds +0 -0
  44. data/blogs/manual/manual.Rmd +852 -239
  45. data/blogs/manual/manual.log +1786 -0
  46. data/blogs/manual/manual.md +1360 -636
  47. data/blogs/manual/manual.tex +1883 -1161
  48. data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
  49. data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
  50. data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
  51. data/blogs/manual/model.rb +1 -1
  52. data/blogs/nse_dplyr/nse_dplyr.Rmd +84 -111
  53. data/blogs/nse_dplyr/nse_dplyr.log +928 -0
  54. data/blogs/nse_dplyr/nse_dplyr.md +198 -229
  55. data/blogs/oh_my/not_so.rb +0 -0
  56. data/blogs/oh_my/oh_my.Rmd +1234 -25
  57. data/blogs/oh_my/oh_my.log +804 -0
  58. data/blogs/oh_my/oh_my.md +1663 -86
  59. data/blogs/oh_my/oh_my.tex +821 -0
  60. data/blogs/oh_my/old.Rmd +15 -14
  61. data/blogs/ruby_plot/ruby_plot.Rmd +58 -82
  62. data/blogs/ruby_plot/ruby_plot.log +885 -0
  63. data/blogs/ruby_plot/ruby_plot.md +71 -102
  64. data/blogs/ruby_plot/ruby_plot.tex +940 -0
  65. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
  66. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
  67. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
  68. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
  69. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
  70. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
  71. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
  72. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
  73. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
  74. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
  75. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
  76. data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
  77. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  78. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  79. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  80. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  81. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  82. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  83. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  84. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  85. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  86. data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  87. data/blogs/test/test.Rmd +14 -0
  88. data/examples/50Plots_MasterList/Images/midwest-scatterplot.PNG +0 -0
  89. data/examples/50Plots_MasterList/ScatterPlot.rb +0 -0
  90. data/examples/50Plots_MasterList/scatter_plot.rb +0 -0
  91. data/examples/Bibliography/master.bib +0 -0
  92. data/examples/Bibliography/stats.bib +0 -0
  93. data/examples/R/calc.R +0 -0
  94. data/examples/R/java_interop.R +0 -0
  95. data/examples/bioconductor_deseq2_airway/Documentation/DESeq2-airway-walkthrough.md +56 -0
  96. data/examples/bioconductor_deseq2_airway/bench_galaaz_three_same_process.rb +53 -0
  97. data/examples/bioconductor_deseq2_airway/bench_r_three_same_process.R +34 -0
  98. data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb +33 -0
  99. data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz_optimized.rb +34 -0
  100. data/examples/bioconductor_deseq2_airway/deseq2_airway_minimal.R +30 -0
  101. data/examples/bioconductor_deseq2_airway/deseq2_airway_pipeline_for_bench.R +36 -0
  102. data/examples/islr/all.rb +13 -0
  103. data/examples/islr/ch2.spec.rb +37 -7
  104. data/examples/islr/ch3.spec.rb +11 -2
  105. data/examples/islr/ch3_boston.rb +27 -0
  106. data/examples/islr/ch3_multiple_regression.rb +0 -0
  107. data/examples/islr/ch6.spec.rb +24 -1
  108. data/examples/islr/x_y_rnorm.jpg +0 -0
  109. data/examples/latex_templates/Test-acm_article/acm_proc_article-sp.cls +0 -0
  110. data/examples/latex_templates/Test-acm_article/sigproc.bib +0 -0
  111. data/examples/latex_templates/Test-acs_article/acs-Test-acs_article.bib +0 -0
  112. data/examples/latex_templates/Test-acs_article/acs-my_output.bib +0 -0
  113. data/examples/latex_templates/Test-aea_article/BibFile.bib +0 -0
  114. data/examples/latex_templates/Test-aea_article/Test-aea_article.Rmd +0 -0
  115. data/examples/latex_templates/Test-aea_article/references.bib +0 -0
  116. data/examples/latex_templates/Test-amq_article/Test-amq_article.Rmd +0 -0
  117. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdfsync +0 -0
  118. data/examples/latex_templates/Test-ieee_article/IEEEtran.bst +0 -0
  119. data/examples/latex_templates/Test-ieee_article/mybibfile.bib +0 -0
  120. data/examples/latex_templates/Test-rjournal_article/RJournal.sty +0 -0
  121. data/examples/latex_templates/Test-rjournal_article/RJreferences.bib +0 -0
  122. data/examples/latex_templates/Test-rjournal_article/Test-rjournal_article.Rmd +0 -0
  123. data/examples/misc/baseball.csv +0 -0
  124. data/examples/misc/ggplot.rb +3 -2
  125. data/examples/misc/moneyball.rb +0 -0
  126. data/examples/misc/subsetting.rb +0 -0
  127. data/examples/multithread_shards_to_r/shards_to_r.rb +67 -0
  128. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.Rmd +0 -0
  129. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.Rmd +0 -0
  130. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.Rmd +0 -0
  131. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.Rmd +0 -0
  132. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/attend-grade-relationships.csv +0 -0
  133. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.Rmd +0 -0
  134. data/examples/rmarkdown/svm-xaringan-example/svm-xaringan-example.Rmd +0 -0
  135. data/examples/sthda_ggplot/README.md +0 -0
  136. data/examples/sthda_ggplot/RUN.md +41 -0
  137. data/examples/sthda_ggplot/all.rb +0 -0
  138. data/examples/sthda_ggplot/one_variable_continuous/density_gg.rb +0 -0
  139. data/examples/sthda_ggplot/one_variable_continuous/geom_area.rb +0 -0
  140. data/examples/sthda_ggplot/one_variable_continuous/geom_density.rb +2 -0
  141. data/examples/sthda_ggplot/one_variable_continuous/geom_dotplot.rb +0 -0
  142. data/examples/sthda_ggplot/one_variable_continuous/geom_freqpoly.rb +0 -0
  143. data/examples/sthda_ggplot/one_variable_continuous/geom_histogram.rb +0 -0
  144. data/examples/sthda_ggplot/one_variable_continuous/histogram_density.rb +0 -0
  145. data/examples/sthda_ggplot/one_variable_continuous/stat.rb +0 -0
  146. data/examples/sthda_ggplot/one_variable_discrete/bar.rb +0 -0
  147. data/examples/sthda_ggplot/qplots/box_violin_dot.rb +0 -0
  148. data/examples/sthda_ggplot/qplots/scatter_plots.rb +0 -0
  149. data/examples/sthda_ggplot/scatter_gg.rb +0 -0
  150. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_bin2d.rb +0 -0
  151. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_density2d.rb +0 -0
  152. data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_hex.rb +0 -0
  153. data/examples/sthda_ggplot/two_variables_cont_cont/geom_point.rb +0 -0
  154. data/examples/sthda_ggplot/two_variables_cont_cont/geom_smooth.rb +0 -0
  155. data/examples/sthda_ggplot/two_variables_cont_cont/misc.rb +0 -0
  156. data/examples/sthda_ggplot/two_variables_cont_function/geom_area.rb +4 -3
  157. data/examples/sthda_ggplot/two_variables_disc_cont/geom_bar.rb +0 -0
  158. data/examples/sthda_ggplot/two_variables_disc_cont/geom_boxplot.rb +0 -0
  159. data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +0 -0
  160. data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +0 -0
  161. data/examples/sthda_ggplot/two_variables_disc_cont/geom_line.rb +0 -0
  162. data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +0 -0
  163. data/examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb +0 -0
  164. data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +0 -0
  165. data/ext/new_bridge/Makefile +46 -0
  166. data/ext/new_bridge/galaaz_gatekeeper_phase0.cpp +12 -0
  167. data/ext/new_bridge/galaaz_gatekeeper_phase1.cpp +1639 -0
  168. data/lib/R_interface/galaaz_device.R +20 -0
  169. data/lib/R_interface/include_engine.R +109 -0
  170. data/lib/R_interface/new_bridge_adapter.rb +824 -0
  171. data/lib/R_interface/r.rb +177 -25
  172. data/lib/R_interface/r_arrow.rb +113 -0
  173. data/lib/R_interface/r_libs.R +3 -3
  174. data/lib/R_interface/r_methods.rb +13 -126
  175. data/lib/R_interface/r_module_s.rb +0 -0
  176. data/lib/R_interface/rbinary_operators.rb +20 -2
  177. data/lib/R_interface/rclosure.rb +5 -1
  178. data/lib/R_interface/rdata_frame.rb +34 -70
  179. data/lib/R_interface/rdevice.rb +125 -0
  180. data/lib/R_interface/rdevices.R +0 -0
  181. data/lib/R_interface/renvironment.rb +10 -4
  182. data/lib/R_interface/rexpression.rb +5 -1
  183. data/lib/R_interface/rindexed_object.rb +41 -13
  184. data/lib/R_interface/rlanguage.rb +20 -62
  185. data/lib/R_interface/rlist.rb +115 -25
  186. data/lib/R_interface/rlogical_operators.rb +0 -0
  187. data/lib/R_interface/rmatrix.rb +2 -11
  188. data/lib/R_interface/rmd_indexed_object.rb +5 -1
  189. data/lib/R_interface/robject.rb +348 -290
  190. data/lib/R_interface/rpkg.rb +0 -0
  191. data/lib/R_interface/rsupport.rb +609 -328
  192. data/lib/R_interface/rsupport_scope.rb +2 -1
  193. data/lib/R_interface/rsymbol.rb +50 -0
  194. data/lib/R_interface/ruby_callback.rb +2 -3
  195. data/lib/R_interface/ruby_extensions.rb +225 -175
  196. data/lib/R_interface/runary_operators.rb +0 -0
  197. data/lib/R_interface/rvector.rb +147 -31
  198. data/lib/galaaz.rb +0 -0
  199. data/lib/galaaz_jruby.rb +22 -0
  200. data/lib/gknit/diagnostics.rb +50 -0
  201. data/lib/gknit/draft.rb +23 -17
  202. data/lib/gknit/include_engine.rb +15 -7
  203. data/lib/gknit/knitr_engine.rb +223 -74
  204. data/lib/gknit/rb_engine.rb +3 -3
  205. data/lib/gknit/ruby_engine.rb +0 -0
  206. data/lib/gknit.rb +1 -0
  207. data/lib/new_bridge/bootstrap/windows_bootstrap.rb +285 -0
  208. data/lib/new_bridge/envelope.rb +51 -0
  209. data/lib/new_bridge/eval_result.rb +26 -0
  210. data/lib/new_bridge/framing.rb +39 -0
  211. data/lib/new_bridge/instance_pool_client.rb +38 -0
  212. data/lib/new_bridge/r_instance_manager.rb +404 -0
  213. data/lib/new_bridge/session_client.rb +530 -0
  214. data/lib/new_bridge/tcp_framed.rb +44 -0
  215. data/lib/new_bridge.rb +9 -0
  216. data/lib/util/exec_ruby.rb +95 -20
  217. data/lib/util/inline_file.rb +35 -30
  218. data/new_bridge_specs/benchmark_phase5_5_unboxing_spec.rb +96 -0
  219. data/new_bridge_specs/eval_r_async_spec.rb +113 -0
  220. data/new_bridge_specs/integration_phase5_1_concurrent_spec.rb +50 -0
  221. data/new_bridge_specs/integration_phase5_1_eval_spec.rb +16 -0
  222. data/new_bridge_specs/integration_phase5_1_r_api_spec.rb +25 -0
  223. data/new_bridge_specs/integration_phase5_1_smoke_spec.rb +31 -0
  224. data/new_bridge_specs/integration_phase5_2_dataframe_unboxing_spec.rb +19 -0
  225. data/new_bridge_specs/integration_phase5_2_handle_eval_unboxing_spec.rb +25 -0
  226. data/new_bridge_specs/integration_phase5_3_callback_args_spec.rb +28 -0
  227. data/new_bridge_specs/integration_phase5_3_callback_error_spec.rb +22 -0
  228. data/new_bridge_specs/integration_phase5_3_callback_timeout_spec.rb +28 -0
  229. data/new_bridge_specs/integration_phase5_3_callbacks_smoke_spec.rb +22 -0
  230. data/new_bridge_specs/integration_phase5_3_edge_cases_spec.rb +52 -0
  231. data/new_bridge_specs/integration_phase5_3_nested_spec.rb +30 -0
  232. data/new_bridge_specs/integration_phase5_4_concurrent_sessions_spec.rb +53 -0
  233. data/new_bridge_specs/integration_phase5_4_nested_session_callbacks_spec.rb +49 -0
  234. data/new_bridge_specs/integration_phase5_4_session_routing_spec.rb +38 -0
  235. data/new_bridge_specs/integration_phase5_5_stress_concurrency_spec.rb +52 -0
  236. data/new_bridge_specs/integration_phase5_5_unbox_walk_spec.rb +46 -0
  237. data/new_bridge_specs/phase0_protocol_spec.rb +96 -0
  238. data/new_bridge_specs/phase1_req_ret_spec.rb +66 -0
  239. data/new_bridge_specs/phase2_multi_instance_spec.rb +67 -0
  240. data/new_bridge_specs/phase3_callbacks_spec.rb +71 -0
  241. data/new_bridge_specs/phase4_2_hardening_spec.rb +252 -0
  242. data/new_bridge_specs/phase4_3_r_instance_manager_spec.rb +85 -0
  243. data/new_bridge_specs/phase4_nested_callbacks_spec.rb +123 -0
  244. data/r_requires/ggplot.rb +0 -0
  245. data/r_requires/knitr.rb +0 -0
  246. data/specs/all.rb +15 -11
  247. data/specs/arrow_from_ruby_batches_spec.rb +50 -0
  248. data/specs/arrow_semantics_spec.rb +64 -0
  249. data/specs/bridge_concurrent_spec.rb +46 -0
  250. data/specs/bridge_nested_spec.rb +25 -0
  251. data/specs/dataframe_semantics_spec.rb +122 -0
  252. data/specs/dataframe_single_index_logical_filter_spec.rb +21 -0
  253. data/specs/dispatch_probe_cache_spec.rb +38 -0
  254. data/specs/dispatch_probe_error_class_fallback_spec.rb +20 -0
  255. data/specs/dispatch_probe_fallback_spec.rb +18 -0
  256. data/specs/environment_semantics_spec.rb +89 -0
  257. data/specs/field_access_spec.rb +31 -0
  258. data/specs/figures/bg.jpeg +0 -0
  259. data/specs/figures/bg.png +0 -0
  260. data/specs/figures/bg.svg +168 -57
  261. data/specs/figures/dose_len.png +0 -0
  262. data/specs/figures/no_args.jpeg +0 -0
  263. data/specs/figures/no_args.png +0 -0
  264. data/specs/figures/no_args.svg +168 -57
  265. data/specs/figures/width_height.jpeg +0 -0
  266. data/specs/figures/width_height.png +0 -0
  267. data/specs/figures/width_height_units1.jpeg +0 -0
  268. data/specs/figures/width_height_units1.png +0 -0
  269. data/specs/figures/width_height_units2.jpeg +0 -0
  270. data/specs/figures/width_height_units2.png +0 -0
  271. data/specs/formula_semantics_spec.rb +81 -0
  272. data/specs/galaaz_util_exec_ruby_spec.rb +85 -0
  273. data/specs/galaaz_util_inline_file_spec.rb +54 -0
  274. data/specs/gknit_cli_option_permutation_spec.rb +24 -0
  275. data/specs/gknit_include_engine_spec.rb +72 -0
  276. data/specs/gknit_install_timeout_report_spec.rb +69 -0
  277. data/specs/gknit_internal_error_report_spec.rb +57 -0
  278. data/specs/gknit_vector_map_output_spec.rb +59 -0
  279. data/specs/globalenv_guardrail_spec.rb +52 -0
  280. data/specs/language_expression_semantics_spec.rb +145 -0
  281. data/specs/list_semantics_spec.rb +111 -0
  282. data/specs/new_bridge_bulk_dataframe_transfer_spec.rb +44 -0
  283. data/specs/new_bridge_bulk_vector_transfer_spec.rb +73 -0
  284. data/specs/new_bridge_callback_timeout_spec.rb +69 -0
  285. data/specs/new_bridge_eval_r_fallback_spec.rb +55 -0
  286. data/specs/nil_null_spec.rb +42 -0
  287. data/specs/object_build_phase2_spec.rb +53 -0
  288. data/specs/phase1_callback_bridge_spec.rb +84 -0
  289. data/specs/phase2_gknit_generic_rendering_guardrail_spec.rb +46 -0
  290. data/specs/phase2_gknit_no_raw_code_leakage_spec.rb +43 -0
  291. data/specs/phase3_gknit_generic_graphics_capture_spec.rb +71 -0
  292. data/specs/plot_device_semantics_spec.rb +28 -0
  293. data/specs/plot_snapshot_semantics_spec.rb +58 -0
  294. data/specs/protocol_result_spec.rb +236 -0
  295. data/specs/r_batch_fail_fast_spec.rb +47 -0
  296. data/specs/r_bridge_bootstrap_spec.rb +11 -0
  297. data/specs/r_devices.spec.rb +1 -1
  298. data/specs/r_eval.spec.rb +16 -18
  299. data/specs/r_function.spec.rb +1 -1
  300. data/specs/r_instance_manager_spec.rb +285 -0
  301. data/specs/r_list_apply.spec.rb +15 -15
  302. data/specs/r_matrix.spec.rb +0 -0
  303. data/specs/r_nse.spec.rb +5 -5
  304. data/specs/r_object_send_dispatch_spec.rb +13 -0
  305. data/specs/r_vector_comparator_spec.rb +8 -0
  306. data/specs/r_vector_creation.spec.rb +0 -0
  307. data/specs/r_vector_functions.spec.rb +0 -0
  308. data/specs/r_vector_object.spec.rb +0 -0
  309. data/specs/r_vector_operators.spec.rb +0 -0
  310. data/specs/r_vector_structured_scalar_reads_spec.rb +35 -0
  311. data/specs/r_vector_subsetting.spec.rb +0 -0
  312. data/specs/range_helper_spec.rb +21 -0
  313. data/specs/rsupport_scope_spec.rb +28 -0
  314. data/specs/rsupport_var_name_thread_safety_spec.rb +24 -0
  315. data/specs/scalar_character_spec.rb +44 -0
  316. data/specs/scoped_symbol_dsl_refinement_spec.rb +40 -0
  317. data/specs/session_env_bridge_spec.rb +25 -0
  318. data/specs/simplecov_bootstrap_spec.rb +10 -0
  319. data/specs/spec_helper.rb +10 -0
  320. data/specs/tmp.rb +0 -0
  321. data/specs/unboxing_recursion_regression_spec.rb +30 -0
  322. data/specs/unboxing_spec.rb +49 -0
  323. data/specs/verify_callbacks.rb +42 -0
  324. data/sty/galaaz.sty +0 -0
  325. data/version.rb +1 -1
  326. metadata +194 -64
  327. data/blogs/galaaz_ggplot/galaaz_ggplot.html +0 -520
  328. data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
  329. data/blogs/galaaz_ggplot/midwest.html +0 -188
  330. data/blogs/gknit/gknit.html +0 -2266
  331. data/blogs/gknit/gknit.pdf +0 -0
  332. data/blogs/manual/manual.html +0 -4638
  333. data/blogs/manual/manual.pdf +0 -0
  334. data/blogs/manual/manual_files/figure-latex/diverging_bar.pdf +0 -0
  335. data/blogs/nse_dplyr/nse_dplyr.html +0 -878
  336. data/blogs/nse_dplyr/nse_dplyr.pdf +0 -0
  337. data/blogs/oh_my/oh_my.html +0 -568
  338. data/blogs/ruby_plot/ruby_plot.html +0 -544
  339. data/blogs/ruby_plot/ruby_plot.pdf +0 -0
  340. data/examples/latex_templates/Test-acs_article/Test-acs_article.pdf +0 -0
  341. data/examples/latex_templates/Test-aea_article/Test-aea_article.pdf +0 -0
  342. data/examples/latex_templates/Test-amq_article/Test-amq_article.pdf +0 -0
  343. data/examples/latex_templates/Test-amq_article/pics/Figure2.pdf +0 -0
  344. data/examples/latex_templates/Test-asa_article/Test-asa_article.pdf +0 -0
  345. data/examples/latex_templates/Test-ieee_article/Test-ieee_article.pdf +0 -0
  346. data/examples/latex_templates/Test-rjournal_article/RJwrapper.pdf +0 -0
  347. data/examples/latex_templates/Test-springer_article/Test-springer_article.pdf +0 -0
  348. data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.pdf +0 -0
  349. data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.pdf +0 -0
  350. data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.pdf +0 -0
  351. data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.pdf +0 -0
  352. data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.pdf +0 -0
  353. data/specs/r_dataframe.spec.rb +0 -379
  354. data/specs/r_environment.spec.rb +0 -140
  355. data/specs/r_formula.spec.rb +0 -232
  356. data/specs/r_language.spec.rb +0 -112
  357. data/specs/r_list.spec.rb +0 -293
  358. data/specs/r_plots.spec.rb +0 -72
  359. data/specs/ruby_expression.spec.rb +0 -316
@@ -1,232 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- ##########################################################################################
4
- # @author Rodrigo Botafogo
5
- #
6
- # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
- # and distribute this software and its documentation, without fee and without a signed
8
- # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
- # paragraph and the following two paragraphs appear in all copies, modifications, and
10
- # distributions.
11
- #
12
- # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
- # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
- # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
- # POSSIBILITY OF SUCH DAMAGE.
16
- #
17
- # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
- # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
- # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
- # OR MODIFICATIONS.
22
- ##########################################################################################
23
-
24
- require 'galaaz'
25
- R.install_and_loads('ISLR', 'MASS')
26
-
27
- describe R::Language do
28
-
29
- #========================================================================================
30
- context "When working with Formulas" do
31
-
32
- it "should create formulas with the 'formula' function" do
33
- formula = R.formula("log(y) ~ a + log(x)")
34
- # formulas also capture their environment. When printing the
35
- # formula, two lines are printed: the first one with the formula
36
- # and the second one with the environmnet. We are keeping only the
37
- # first line for comparing with the expected formula
38
- expect(formula.to_s.lines.first.chomp).to eq "log(y) ~ a + log(x)"
39
- end
40
-
41
- it "should create formulas with the '.til' function" do
42
- formula = R.formula("cyl ~ exp")
43
- expect(formula.to_s.lines.first.chomp).to eq "cyl ~ exp"
44
-
45
- formula = (:cyl.til :exp)
46
- expect(formula.to_s.lines.first.chomp).to eq "cyl ~ exp"
47
- rform = R.identity(formula)
48
- expect(rform.typeof).to eq 'language'
49
- expect(rform.rclass).to eq 'formula'
50
- end
51
-
52
- it "should create a formula with '.' in the rhs" do
53
- formula = R.formula("supp ~ .")
54
- expect(formula.to_s.lines.first.chomp).to eq "supp ~ ."
55
-
56
- # this formula is interpreted as 'supp ~ .' In this statement formula
57
- # is an R::Expression which has infix and prefix notation
58
- formula = :supp.til :__
59
- expect(formula.to_s.lines.first.chomp).to eq "supp ~ ."
60
- expect(formula.rclass).to eq "formula"
61
- expect(formula.typeof).to eq "language"
62
- end
63
-
64
- it "should create a formula with '.' by using the ':__' keyword in the lhs" do
65
- formula = R.formula(". ~ supp")
66
- expect(formula.to_s.lines.first.chomp).to eq ". ~ supp"
67
-
68
- # this formula is interpreted as '. ~ supp'
69
- formula = :__.til :supp
70
- expect(formula.to_s.lines.first.chomp).to eq ". ~ supp"
71
- expect(formula.rclass).to eq "formula"
72
- expect(formula.typeof).to eq "language"
73
- end
74
-
75
- it "should create a formula starting with '~' with the ':all' symbol in the lhs" do
76
- formula = R.formula("~ supp")
77
- expect(formula.to_s.lines.first.chomp).to eq "~supp"
78
-
79
- formula = :all.til :supp
80
- expect(formula.to_s.lines.first.chomp).to eq "~supp"
81
- expect(formula.rclass).to eq "formula"
82
- expect(formula.typeof).to eq "language"
83
- end
84
-
85
- it "should allow formulas with conditional" do
86
- formula = R.formula("Sepal.Width ~ Petal.Width | Species")
87
- expect(formula.to_s.lines.first.chomp).to eq "Sepal.Width ~ Petal.Width | Species"
88
-
89
- formula = :Sepal__Width.til :Petal__Width | :Species
90
- expect(formula.to_s.lines.first.chomp).to eq "Sepal.Width ~ Petal.Width | Species"
91
- end
92
-
93
- it "should allow creating formulas with functions in the lhs" do
94
- formula = E.log(:y).til :a + E.log(:x)
95
- expect(formula.to_s.lines.first.chomp).to eq "log(y) ~ a + log(x)"
96
- end
97
-
98
- end
99
-
100
- #========================================================================================
101
- context "Formula operators" do
102
-
103
- it "should add multiple independent variables to a formula with '+'" do
104
- # Use multiple independent variables
105
- formula = :y.til :x1 + :x2
106
- expect(formula.to_s.lines.first.chomp).to eq "y ~ x1 + x2"
107
- end
108
-
109
- it "should ignore objects in an analysis with '-'" do
110
- # Ignore objects in an analysis
111
- formula = :y.til :x1 - :x2
112
- expect(formula.to_s.lines.first.chomp).to eq "y ~ x1 - x2"
113
- end
114
-
115
- it "should create interaction between objects with '*'" do
116
- # Ignore objects in an analysis
117
- formula = :y.til :x * :x2
118
- expect(formula.to_s.lines.first.chomp).to eq "y ~ x * x2"
119
-
120
- # Set seed
121
- R.set__seed(123)
122
-
123
- # Data
124
- R.x = R.rnorm(5)
125
- R.x2 = R.rnorm(5)
126
- R.y = R.rnorm(5)
127
-
128
- # Model frame
129
- model = R.model__frame(formula, data: R.data__frame(x: :x, y: :y, x2: :x2))
130
- expect(model[1, 1].all__equal(1.22408179743946)).to eq true
131
- expect(model[1, 3].all__equal(1.71506498688328)).to eq true
132
- expect(model[3, 2].all__equal(1.55870831414912)).to eq true
133
- expect(model[5, 1].all__equal(-0.555841134754075)).to eq true
134
- end
135
-
136
- it "should allow creating formulas with interaction between variables with 'inter'" do
137
- formula = :y.til :x + :x2 + (:x.inter :x2)
138
- expect(formula.to_s.lines.first.chomp).to eq "y ~ x + x2 + x:x2"
139
-
140
- # Set seed
141
- R.set__seed(123)
142
-
143
- # Data
144
- R.x = R.rnorm(5)
145
- R.x2 = R.rnorm(5)
146
- R.y = R.rnorm(5)
147
-
148
- # Model frame
149
- model = R.model__frame(formula, data: R.data__frame(x: :x, y: :y, x2: :x2))
150
- expect(model[1, 1].all__equal(1.22408179743946)).to eq true
151
- expect(model[1, 3].all__equal(1.71506498688328)).to eq true
152
- expect(model[3, 2].all__equal(1.55870831414912)).to eq true
153
- expect(model[5, 1].all__equal(-0.555841134754075)).to eq true
154
- end
155
-
156
- it "should allow creating formulas with interaction with ':in'" do
157
- # note that '_' is a method with two arguments ':in' and ':a' and
158
- # that it is necessary to put the whole expression in parenthesis or
159
- # add parenthesis on the arguments
160
- formula = :y.til :a + (:b._ :in, :a)
161
- expect(formula.to_s.lines.first.chomp).to eq "y ~ a + b %in% a"
162
- end
163
-
164
- end
165
-
166
- #========================================================================================
167
- context "When modeling with formulas - Simple linear regression" do
168
-
169
- before(:each) do
170
- @boston_lm = R.lm((:medv.til :lstat), data: :Boston)
171
- end
172
-
173
- it "should obtain data from the model" do
174
- expect(@boston_lm.coefficients[[1]].all__equal(34.5538408)).to eq true
175
- expect(@boston_lm.coefficients[[2]].all__equal(-0.950049353)).to eq true
176
-
177
- expect(@boston_lm.names[[1]]).to eq "coefficients"
178
- expect(@boston_lm.names[[2]]).to eq "residuals"
179
- expect(@boston_lm.names[[12]]).to eq "model"
180
- end
181
-
182
- it "should do predictions (confidence) based on the model" do
183
- # predict the confidence interval
184
- conf = R.predict(@boston_lm, R.data__frame(lstat: (R.c(5, 10, 15))),
185
- interval: "confidence")
186
- expect(conf[1, :all][['fit']].all__equal(29.8035941)).to eq true
187
- expect(conf[2, :all][['lwr']].all__equal(24.4741320)).to eq true
188
- expect(conf[3, :all][['upr']].all__equal(20.8746129)).to eq true
189
- end
190
-
191
- it "should do prediction (prediction) based on the model" do
192
- pred = R.predict(@boston_lm, R.data__frame(lstat: (R.c(5, 10, 15))),
193
- interval: "prediction")
194
- expect(pred[1, :all][['fit']].all__equal(29.8035941)).to eq true
195
- expect(pred[2, :all][['lwr']].all__equal(12.82762634)).to eq true
196
- expect(pred[3, :all][['upr']].all__equal(32.5284590)).to eq true
197
- end
198
-
199
- end
200
-
201
- #========================================================================================
202
- context "Multiple linear regression" do
203
-
204
- it "should do multiple linear regression" do
205
- # Multiple linear regression from ISLR book. Chapter 3 Lab, pg 113
206
- lm_fit = R.lm((:medv.til :lstat + :age), data: :Boston)
207
-
208
- # Intercept
209
- expect(lm_fit.coefficients[[1]].all__equal(33.2227605317)).to eq true
210
- # lstat
211
- expect(lm_fit.coefficients[[2]].all__equal(-1.0320685641)).to eq true
212
- expect(lm_fit.coefficients[['lstat']].all__equal(-1.0320685641)).to eq true
213
- # age
214
- expect(lm_fit.coefficients[[3]].all__equal(0.0345443385)).to eq true
215
- end
216
-
217
- it "should do multiple linear regression with polynomials" do
218
- lm_fit5 = R.lm((:medv.til E.poly(:lstat, 5)), data: :Boston)
219
-
220
- # Intercept
221
- expect(lm_fit5.coefficients[[1]].all__equal(22.53280632411)).to eq true
222
- # Poly 1
223
- expect(lm_fit5.coefficients[[2]].all__equal(-152.4595487225)).to eq true
224
- # Poly 3
225
- expect(lm_fit5.coefficients[[4]].all__equal(-27.0510978864097)).to eq true
226
- # Poly 5
227
- expect(lm_fit5.coefficients[[6]].all__equal(-19.2524177100554)).to eq true
228
- end
229
-
230
- end
231
-
232
- end
@@ -1,112 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- ##########################################################################################
4
- # @author Rodrigo Botafogo
5
- #
6
- # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
- # and distribute this software and its documentation, without fee and without a signed
8
- # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
- # paragraph and the following two paragraphs appear in all copies, modifications, and
10
- # distributions.
11
- #
12
- # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
- # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
- # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
- # POSSIBILITY OF SUCH DAMAGE.
16
- #
17
- # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
- # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
- # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
- # OR MODIFICATIONS.
22
- ##########################################################################################
23
-
24
- require 'galaaz'
25
-
26
- describe R::Language do
27
-
28
- #========================================================================================
29
- context "Working with symbols" do
30
-
31
- it "should convert a Ruby Symbol to an R Symbol with '+'" do
32
- a = +:cyl
33
- expect(a.is_a? R::RSymbol).to eq true
34
- expect(a.to_s).to eq "cyl"
35
- end
36
-
37
- it "should assign to an R symbol and retrieve from it" do
38
- R.cyl = 10
39
- expect(~:cyl).to eq 10
40
- end
41
-
42
- it "should allow calling evaluate on the symbol" do
43
- R.cyl = 10
44
- expect(R.eval(~:cyl)).to eq 10
45
- end
46
-
47
- end
48
-
49
- #========================================================================================
50
-
51
- context "Executing R expressions" do
52
-
53
- it "should eval an R expression in the context of a list" do
54
- ct = R.list(a: 10, b: 20, c: 30)
55
- exp = :a + :b * :c
56
- expect(R.eval(exp, ct)).to eq 610
57
- end
58
-
59
- it "should eval an R function in the context of a list" do
60
- R.x = 5
61
- expect(R.eval(:x + 10)).to eq 15
62
- ct = R.list(x: 20)
63
- expect(R.eval(:x + 10, ct)).to eq 30
64
- end
65
-
66
- end
67
-
68
-
69
- #========================================================================================
70
- context "When working with Formulas" do
71
- # When working with formulas, Ruby symbols such be preceded by the '+' function.
72
- # If you want to make a formula such as 'a ~ b' in R, then this should be written
73
- # as '+:a =~ +:b'. When, in an binary operation, the Ruby symbol will be converted
74
- # to an R symbol. The formula '+:a =~ +:b', can also be written as '+:a =~ :b'. Be
75
- # careful, however, when using the Ruby symbol without the '+' since in a more complex
76
- # formula, Ruby's precedence rules might not result in what is expected. As an example
77
- # '+:a =~ :b * +:c' crashes with the error 'b' not found, since '*' has precedence over
78
- # '=~' and this is equivalent to '+:a =~ (:b * +:c)' and there is no sense in
79
- # multiplying a Ruby symbol. The recomendation is to always use the '+' function
80
- # before the Ruby symbol.
81
-
82
- it "should create a RSymbol from a Ruby Symbol using +" do
83
- sym = +:sym
84
- expect(sym.to_s).to eq "sym"
85
- end
86
-
87
- =begin
88
-
89
- it "should create a formula without the lhs" do
90
- pending "formulas need to be reimplemented"
91
- formula = ~(:cyl + :exp)
92
- expect formula.to_s == '~.Primitive("+")(cyl, exp)'
93
- expect formula.typeof == 'language'
94
- expect formula.rclass == 'formula'
95
- end
96
-
97
- it "should create formulas with the '=~' operator" do
98
- formula = (:cyl =~ :exp)
99
- expect(formula.to_s) == '.Primitive("~")(cyl, exp)'
100
- expect formula.typeof == 'language'
101
- expect formula.rclass == 'formula'
102
-
103
- formula2 = (:cyl =~ :exp + :exp2 - :exp3)
104
- expect formula2.to_s == 'cyl ~ .Primitive("-")(.Primitive("+")(exp, exp2), exp3)'
105
- expect formula.typeof == 'language'
106
- expect formula.rclass == 'formula'
107
- end
108
- =end
109
-
110
- end
111
-
112
- end
data/specs/r_list.spec.rb DELETED
@@ -1,293 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- ##########################################################################################
4
- # @author Rodrigo Botafogo
5
- #
6
- # Copyright © 2018 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
- # and distribute this software and its documentation, without fee and without a signed
8
- # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
- # paragraph and the following two paragraphs appear in all copies, modifications, and
10
- # distributions.
11
- #
12
- # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
- # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
- # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
- # POSSIBILITY OF SUCH DAMAGE.
16
- #
17
- # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
- # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
- # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
- # OR MODIFICATIONS.
22
- ##########################################################################################
23
-
24
- require 'galaaz'
25
-
26
- describe R::List do
27
-
28
- #----------------------------------------------------------------------------------------
29
- context "When creating lists" do
30
-
31
- it "should create an empty list" do
32
- l = R.list
33
- expect(l.length).to eq 0
34
- expect(l.class).to eq R::List
35
- expect(l.typeof).to eq "list"
36
- end
37
-
38
- it "should return a list when R.list is called" do
39
- l = R.list(1, 2)
40
- expect(l.length).to eq 2
41
- expect(l.class).to eq R::List
42
- expect(l.typeof).to eq "list"
43
- end
44
-
45
- it "should allow creating list of lists" do
46
- l = R.list(1, 2, 3, R.list(4, 5, 6))
47
- expect(l.length).to eq 4
48
- end
49
-
50
- it "should allow mixing different types of objects" do
51
- l = R.list(R.c(1, 2, 3), R.c(1.0, 2.0, 3.0), R.list(a: 1, b: 2, c: 3),
52
- R.complex(real: R.rnorm(5), imag: R.rnorm(5)))
53
- end
54
-
55
- it "should create lists using sequences" do
56
- x = R.list(a: (1..10), beta: R.exp(-3..3), logic: R.c(true, false, false, true))
57
- end
58
-
59
- end
60
-
61
- #----------------------------------------------------------------------------------------
62
- context "When subsetting a list with '>>' (starts at 0)" do
63
-
64
- before(:each) do
65
- @l = R.list(1, a: 2, b: 3, c: R.list(4, 5, 6))
66
- end
67
-
68
- it "should return the 'native' (Ruby) element of the list at numeric index" do
69
- expect(@l >> 0).to eq 1
70
- expect(@l >> 1).to eq 2
71
- expect(@l >> 2).to eq 3
72
- end
73
-
74
- it "should return the 'native' (Ruby) element of the list at named index" do
75
- expect(@l['a'] >> 0).to eq 2
76
- expect(@l[['a']] >> 0).to eq 2
77
- expect(@l['b'] >> 0).to eq 3
78
- end
79
-
80
- it "should raise an exception (IndexError) if index out of bounds" do
81
- expect { @l >> 4 }.to raise_error(IndexError)
82
- end
83
-
84
- it "should raise an exception (Argument error) if indexed element is not a vector" do
85
- expect { @l >> 3 }.to raise_error(ArgumentError)
86
- end
87
-
88
- it "should return nil if named index does not exists" do
89
- expect(@l['k'] >> 0).to eq nil
90
- end
91
-
92
- end
93
-
94
- #----------------------------------------------------------------------------------------
95
- context "When subsetting a list with '['" do
96
-
97
- before(:each) do
98
- # the 'all' keywork means 'empty', so this is a list of the form
99
- # list(a = 1, b = 2, list(c = 3))... note that the 3rd element of the
100
- # list has no name. In Ruby, doing R.list(a: 1, b: 2, R.list(c: 3)) is
101
- # a syntax error, since named parameters need to come at the end of the
102
- # parameter list. To fix that we do: R.list(a: 1, b: 2, all: R.list(c: 3))
103
- # However, note that we cannot have two identical named parameters in a
104
- # function call, as Ruby will detect it as an error and pass only one of
105
- # the named parameters and not both.
106
-
107
- # The following list has only 3 elements and not 4 since the 'all' parameter
108
- # was used twice. This is a limitation of Ruby
109
- @l = R.list(a: 1, b: 2, all: 3, all: R.list(i: 4, j: 5, all: 6))
110
-
111
- # This list has 4 elements.
112
- @l1 = R.list(a: 1, b: 2, all: 3, d: R.list(i: 4, j: 5, all: 6))
113
-
114
- # if possible, change the order of the list with unamed parameters first.
115
- # Although clearly those lists are different, named parameters can still
116
- # be recovered by name
117
- @l2 = R.list(3, R.list(6, i:4, j: 5), a: 1, b: 2)
118
- end
119
-
120
- it "should allow accessing parameters named with 'all' by position" do
121
- expect(@l.length).to eq 3
122
- # Note that the first 'all' parameter was droped. Don't know if this
123
- # is implementation dependend, but in TruffleRuby that's the way it is
124
- # (at least for now).
125
- expect(@l[[3]]).to eq R.list(i:4, j: 5, all: 6)
126
- end
127
-
128
- it "should subset with [] and positve integer. Returns a list" do
129
- expect(@l1.length).to eq 4
130
- # Subsetting a list with [] returns a list
131
- expect(@l1[1]).to eq R.list(a: 1)
132
- expect(@l1[1] == R.c(a: 1)).to eq false
133
- expect(@l1[1]).not_to eq R.c(a: 1)
134
-
135
- # the 4th element of the list is another list
136
- expect(@l1[4]).to eq R.list(d: R.list(i: 4, j: 5, all: 6))
137
- end
138
-
139
- it "should subset with [] and negative integer. Returns a list" do
140
- expect(@l1[-4] == R.list(a: 1, b: 2, all: 3)).to eq true
141
- end
142
-
143
- it "should subset with [] and a vector as index" do
144
- expect(@l1[R.c(4, 1)] == R.list(d: R.list(i: 4, j: 5, all: 6), a: 1)).to eq true
145
- end
146
-
147
- it "should raise an exception when index dimension is wrong" do
148
- expect { @l[4, 1] }.to raise_error(ArgumentError)
149
- end
150
-
151
- end
152
-
153
- #----------------------------------------------------------------------------------------
154
- context "When subsetting a list with '[['" do
155
-
156
- before(:each) do
157
- @l = R.list(1, 2, 3, R.list(4, 5, 6))
158
- end
159
-
160
- it "should subset with [[]] and positive integer. Returns the actual element of the list" do
161
- # to extract an element of a list we need double square (dbk) indexing
162
- expect(@l[[1]]).to eq 1
163
- # dbk indexing to get a list
164
- expect(@l[[4]].identical(R.list(4, 5, 6))).to eq true
165
- end
166
-
167
- it "can chain subsetting operations" do
168
- # 1rst element of 4th vector is a list
169
- expect(@l[[4]][1].identical(R.list(4))).to eq true
170
- expect(@l[[4]][[1]]).to eq 4
171
- end
172
-
173
- it "should subset with [[]] with a vector" do
174
- # Note that for a list or other recursive object, the index can be a vector
175
- # and each element of the vector is applied in turn to the list, the
176
- # selected component, the selected component of that component, and so on.
177
- # The result is still a single element.
178
- expect(@l[[R.c(4, 1)]]).to eq 4
179
- end
180
-
181
- end
182
-
183
- #----------------------------------------------------------------------------------------
184
- context "When subsetting a list with '.'" do
185
-
186
- before(:each) do
187
- # This list has 4 elements.
188
- @l1 = R.list(a: 1, b: 2, all: 3, d: R.list(i: 4, j: 5, all: 6))
189
- end
190
-
191
- it "should access named elements with '.<name>'" do
192
- # access with '.' is equivalent to access with '[[
193
- expect(@l1.a == R.c(1)).to eq true
194
- expect(@l1.a).to eq 1
195
- expect(@l1.b).to eq 2
196
- expect(@l1.d == R.list(i: 4, j: 5, all: 6)).to eq true
197
- end
198
-
199
- end
200
-
201
- #----------------------------------------------------------------------------------------
202
- context "When subsetting a list with 'each' and 'each_with_index'" do
203
-
204
- before(:each) do
205
- @l = R.list(1, 2, 3, R.list(4, 5, 6))
206
- end
207
-
208
- it "should subset with 'each' returning every element as if subsetting with '[['" do
209
- i = 1
210
- @l.each do |elmt|
211
- if (i < 4)
212
- expect(elmt).to eq i
213
- else
214
- expect(elmt.identical(R.list(4, 5, 6))).to eq true
215
- end
216
- i = i + 1
217
- end
218
- end
219
-
220
- it "should subset with 'each_with_index'" do
221
- @l.each_with_index do |elmt, i|
222
- if (i < 4)
223
- expect(elmt).to eq i
224
- else
225
- expect(elmt.identical(R.list(4, 5, 6))).to eq true
226
- end
227
- end
228
- end
229
-
230
- end
231
-
232
- #----------------------------------------------------------------------------------------
233
- context "When assigning to a list subset" do
234
-
235
- before(:each) do
236
- @l = R.list(a: 1, b: 2, c: 3, d: R.list(i: 4, j: 5, k: 6))
237
- end
238
-
239
- it "should be possible to modify a list by index" do
240
- @l[[1]] = 10
241
- expect(@l.length).to eq 4
242
- expect(@l[[1]]).to eq 10
243
- end
244
-
245
- it "should be possible to modify a list by element name in '[[" do
246
- @l[['a']] = 10
247
- expect(@l[['a']]).to eq 10
248
- expect(@l.a).to eq 10
249
- end
250
-
251
- it "should be possible to modify a list by element name with '.'" do
252
- @l.b = 20
253
- expect(@l[['b']]).to eq 20
254
- expect(@l.b).to eq 20
255
- end
256
-
257
- it "should be possible to add an element to the list with '[[" do
258
- @l[['married']] = true
259
- expect(@l.length).to eq 5
260
- expect(@l[['married']]).to eq true
261
- expect(@l.married).to eq true
262
- end
263
-
264
- it "should be possible to add an element to the list with '.'" do
265
- @l.married = true
266
- expect(@l.length).to eq 5
267
- expect(@l[['married']]).to eq true
268
- expect(@l.married).to eq true
269
-
270
- @l.number = 5.345
271
- @l.lst = R.list(100, 200)
272
- @l.vec = R.c(500, 600)
273
-
274
- expect(@l.length).to eq 8
275
- expect(@l.vec).to eq R.c(500, 600)
276
- expect(@l.vec).not_to eq R.c(1000)
277
- end
278
-
279
- it "should be possible to remove an element from a list by assigning 'nil' to it" do
280
- @l[['d']] = nil
281
- expect(@l.length).to eq 3
282
- expect(@l).to eq R.list(a: 1, b: 2, c: 3)
283
- end
284
-
285
- it "should be possible to remove an element from a list by assigning 'nil' with '.'" do
286
- @l.d = nil
287
- expect(@l.length).to eq 3
288
- expect(@l).to eq R.list(a: 1, b: 2, c: 3)
289
- end
290
-
291
- end
292
-
293
- end