galaaz 0.4.10 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/LICENSE +0 -0
- data/README.md +3123 -882
- data/Rakefile +62 -41
- data/bin/galaaz-bootstrap +137 -0
- data/bin/galaaz-jruby +14 -0
- data/bin/galaaz_jruby_env.inc.sh +6 -0
- data/bin/gbookdown +64 -0
- data/bin/gknit +223 -6
- data/bin/gknit-draft +105 -0
- data/bin/gknit-draft.rb +28 -0
- data/bin/gknit_Rscript +127 -0
- data/bin/grun +27 -1
- data/bin/gstudio +49 -4
- data/bin/{gstudio.rb → gstudio_irb.rb} +0 -0
- data/bin/gstudio_pry.rb +7 -0
- data/bin/install-tinytex +6 -0
- data/bin/run_all_rspec +43 -0
- data/bin/run_example +14 -0
- data/bin/run_old_rspec +19 -0
- data/bin/run_rspec +23 -0
- data/bin/run_rspec_subset +38 -0
- data/bin/run_slow_rspec +19 -0
- data/blogs/R-on-Rails-Planning-Document.md +940 -0
- data/blogs/README.md +100 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +38 -66
- data/blogs/galaaz_ggplot/galaaz_ggplot.log +754 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.md +364 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +607 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
- data/blogs/galaaz_ggplot/midwest.Rmd +3 -3
- data/blogs/galaaz_ggplot/midwest_external_png +0 -0
- data/blogs/gknit/gknit.Rmd +52 -55
- data/blogs/gknit/gknit.md +94 -94
- data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
- data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
- data/blogs/gknit/lst.rds +0 -0
- data/blogs/gknit/model.rb +1 -1
- data/blogs/gknit/stats.bib +0 -0
- data/blogs/manual/include_model_local_repro.Rmd +14 -0
- data/blogs/manual/include_model_local_repro.md +75 -0
- data/blogs/manual/lst.rds +0 -0
- data/blogs/manual/manual.Rmd +1582 -196
- data/blogs/manual/manual.log +1786 -0
- data/blogs/manual/manual.md +3107 -890
- data/blogs/manual/manual.tex +3018 -1086
- data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-html/diverging_bar.png +0 -0
- data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
- data/blogs/manual/model.rb +41 -0
- data/blogs/nse_dplyr/nse_dplyr.Rmd +277 -151
- data/blogs/nse_dplyr/nse_dplyr.log +928 -0
- data/blogs/nse_dplyr/nse_dplyr.md +457 -293
- data/blogs/oh_my/not_so.rb +0 -0
- data/blogs/oh_my/oh_my.Rmd +1234 -25
- data/blogs/oh_my/oh_my.log +804 -0
- data/blogs/oh_my/oh_my.md +1808 -228
- data/blogs/oh_my/oh_my.tex +821 -0
- data/blogs/oh_my/old.Rmd +15 -14
- data/blogs/ruby_plot/ruby_plot.Rmd +58 -82
- data/blogs/ruby_plot/ruby_plot.log +885 -0
- data/blogs/ruby_plot/ruby_plot.md +71 -103
- data/blogs/ruby_plot/ruby_plot.tex +940 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
- data/blogs/test/test.Rmd +14 -0
- data/examples/50Plots_MasterList/Images/midwest-scatterplot.PNG +0 -0
- data/examples/50Plots_MasterList/ScatterPlot.rb +0 -0
- data/examples/50Plots_MasterList/scatter_plot.rb +0 -0
- data/examples/Bibliography/master.bib +50 -0
- data/examples/Bibliography/stats.bib +72 -0
- data/examples/R/calc.R +0 -0
- data/examples/R/java_interop.R +0 -0
- data/examples/bioconductor_deseq2_airway/Documentation/DESeq2-airway-walkthrough.md +56 -0
- data/examples/bioconductor_deseq2_airway/bench_galaaz_three_same_process.rb +53 -0
- data/examples/bioconductor_deseq2_airway/bench_r_three_same_process.R +34 -0
- data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb +33 -0
- data/examples/bioconductor_deseq2_airway/deseq2_airway_galaaz_optimized.rb +34 -0
- data/examples/bioconductor_deseq2_airway/deseq2_airway_minimal.R +30 -0
- data/examples/bioconductor_deseq2_airway/deseq2_airway_pipeline_for_bench.R +36 -0
- data/examples/islr/all.rb +13 -0
- data/examples/islr/ch2.spec.rb +37 -7
- data/examples/islr/ch3.spec.rb +11 -2
- data/examples/islr/ch3_boston.rb +27 -0
- data/examples/islr/ch3_multiple_regression.rb +0 -0
- data/examples/islr/ch6.spec.rb +24 -1
- data/examples/islr/x_y_rnorm.jpg +0 -0
- data/examples/latex_templates/Test-acm_article/Makefile +16 -0
- data/examples/latex_templates/Test-acm_article/Test-acm_article.Rmd +65 -0
- data/examples/latex_templates/Test-acm_article/acm_proc_article-sp.cls +1670 -0
- data/examples/latex_templates/Test-acm_article/sensys-abstract.cls +703 -0
- data/examples/latex_templates/Test-acm_article/sigproc.bib +59 -0
- data/examples/latex_templates/Test-acs_article/Test-acs_article.Rmd +260 -0
- data/examples/latex_templates/Test-acs_article/acs-Test-acs_article.bib +11 -0
- data/examples/latex_templates/Test-acs_article/acs-my_output.bib +11 -0
- data/examples/latex_templates/Test-acs_article/acstest.bib +17 -0
- data/examples/latex_templates/Test-aea_article/AEA.cls +1414 -0
- data/{blogs/gknit/marshal.dump → examples/latex_templates/Test-aea_article/BibFile.bib} +0 -0
- data/examples/latex_templates/Test-aea_article/Test-aea_article.Rmd +108 -0
- data/examples/latex_templates/Test-aea_article/aea.bst +1269 -0
- data/examples/latex_templates/Test-aea_article/multicol.sty +853 -0
- data/examples/latex_templates/Test-aea_article/references.bib +0 -0
- data/examples/latex_templates/Test-aea_article/setspace.sty +546 -0
- data/examples/latex_templates/Test-amq_article/Test-amq_article.Rmd +256 -0
- data/examples/latex_templates/Test-amq_article/Test-amq_article.pdfsync +3397 -0
- data/examples/latex_templates/Test-ams_article/Test-ams_article.Rmd +215 -0
- data/examples/latex_templates/Test-ams_article/amstest.bib +436 -0
- data/examples/latex_templates/Test-asa_article/Test-asa_article.Rmd +153 -0
- data/examples/latex_templates/Test-asa_article/agsm.bst +1353 -0
- data/examples/latex_templates/Test-asa_article/bibliography.bib +233 -0
- data/examples/latex_templates/Test-ieee_article/IEEEtran.bst +2409 -0
- data/examples/latex_templates/Test-ieee_article/IEEEtran.cls +6346 -0
- data/examples/latex_templates/Test-ieee_article/Test-ieee_article.Rmd +175 -0
- data/examples/latex_templates/Test-ieee_article/mybibfile.bib +20 -0
- data/examples/latex_templates/Test-rjournal_article/RJournal.sty +335 -0
- data/examples/latex_templates/Test-rjournal_article/RJreferences.bib +18 -0
- data/examples/latex_templates/Test-rjournal_article/Test-rjournal_article.Rmd +52 -0
- data/examples/latex_templates/Test-springer_article/Test-springer_article.Rmd +65 -0
- data/examples/latex_templates/Test-springer_article/bibliography.bib +26 -0
- data/examples/latex_templates/Test-springer_article/spbasic.bst +1658 -0
- data/examples/latex_templates/Test-springer_article/spmpsci.bst +1512 -0
- data/examples/latex_templates/Test-springer_article/spphys.bst +1443 -0
- data/examples/latex_templates/Test-springer_article/svglov3.clo +113 -0
- data/examples/latex_templates/Test-springer_article/svjour3.cls +1431 -0
- data/examples/misc/baseball.csv +0 -0
- data/examples/misc/ggplot.rb +3 -2
- data/examples/misc/moneyball.rb +0 -0
- data/examples/misc/subsetting.rb +0 -0
- data/examples/multithread_shards_to_r/shards_to_r.rb +67 -0
- data/examples/rmarkdown/svm-rmarkdown-anon-ms-example/svm-rmarkdown-anon-ms-example.Rmd +73 -0
- data/examples/rmarkdown/svm-rmarkdown-article-example/svm-rmarkdown-article-example.Rmd +382 -0
- data/examples/rmarkdown/svm-rmarkdown-beamer-example/svm-rmarkdown-beamer-example.Rmd +164 -0
- data/examples/rmarkdown/svm-rmarkdown-cv/svm-rmarkdown-cv.Rmd +92 -0
- data/examples/rmarkdown/svm-rmarkdown-syllabus-example/attend-grade-relationships.csv +482 -0
- data/examples/rmarkdown/svm-rmarkdown-syllabus-example/svm-rmarkdown-syllabus-example.Rmd +280 -0
- data/examples/rmarkdown/svm-xaringan-example/svm-xaringan-example.Rmd +386 -0
- data/examples/sthda_ggplot/README.md +0 -0
- data/examples/sthda_ggplot/RUN.md +41 -0
- data/examples/sthda_ggplot/all.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/density_gg.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_area.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_density.rb +2 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_dotplot.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_freqpoly.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/geom_histogram.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/histogram_density.rb +0 -0
- data/examples/sthda_ggplot/one_variable_continuous/stat.rb +0 -0
- data/examples/sthda_ggplot/one_variable_discrete/bar.rb +0 -0
- data/examples/sthda_ggplot/qplots/box_violin_dot.rb +0 -0
- data/examples/sthda_ggplot/qplots/scatter_plots.rb +0 -0
- data/examples/sthda_ggplot/scatter_gg.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_bin2d.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_density2d.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_bivariate/geom_hex.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/geom_point.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/geom_smooth.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_cont/misc.rb +0 -0
- data/examples/sthda_ggplot/two_variables_cont_function/geom_area.rb +4 -3
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_bar.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_boxplot.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_dotplot.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_jitter.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_line.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_cont/geom_violin.rb +0 -0
- data/examples/sthda_ggplot/two_variables_disc_disc/geom_jitter.rb +0 -0
- data/examples/sthda_ggplot/two_variables_error/geom_crossbar.rb +0 -0
- data/ext/new_bridge/Makefile +46 -0
- data/ext/new_bridge/galaaz_gatekeeper_phase0.cpp +12 -0
- data/ext/new_bridge/galaaz_gatekeeper_phase1.cpp +1639 -0
- data/lib/R_interface/galaaz_device.R +20 -0
- data/lib/R_interface/include_engine.R +109 -0
- data/lib/R_interface/new_bridge_adapter.rb +824 -0
- data/lib/R_interface/r.rb +177 -25
- data/lib/R_interface/r_arrow.rb +113 -0
- data/lib/R_interface/r_libs.R +4 -4
- data/lib/R_interface/r_methods.rb +13 -116
- data/lib/R_interface/r_module_s.rb +0 -0
- data/lib/R_interface/rbinary_operators.rb +20 -2
- data/lib/R_interface/rclosure.rb +5 -1
- data/lib/R_interface/rdata_frame.rb +34 -70
- data/lib/R_interface/rdevice.rb +125 -0
- data/lib/R_interface/rdevices.R +0 -0
- data/lib/R_interface/renvironment.rb +10 -4
- data/lib/R_interface/rexpression.rb +5 -1
- data/lib/R_interface/rindexed_object.rb +41 -13
- data/lib/R_interface/rlanguage.rb +20 -62
- data/lib/R_interface/rlist.rb +115 -25
- data/lib/R_interface/rlogical_operators.rb +0 -0
- data/lib/R_interface/rmatrix.rb +2 -11
- data/lib/R_interface/rmd_indexed_object.rb +5 -1
- data/lib/R_interface/robject.rb +348 -290
- data/lib/R_interface/rpkg.rb +1 -0
- data/lib/R_interface/rsupport.rb +610 -331
- data/lib/R_interface/rsupport_scope.rb +2 -1
- data/lib/R_interface/rsymbol.rb +50 -0
- data/lib/R_interface/ruby_callback.rb +2 -3
- data/lib/R_interface/ruby_extensions.rb +225 -175
- data/lib/R_interface/runary_operators.rb +0 -0
- data/lib/R_interface/rvector.rb +147 -31
- data/lib/galaaz.rb +0 -0
- data/lib/galaaz_jruby.rb +22 -0
- data/lib/gknit/diagnostics.rb +50 -0
- data/lib/gknit/draft.rb +111 -0
- data/lib/gknit/include_engine.rb +15 -7
- data/lib/gknit/knitr_engine.rb +223 -107
- data/lib/gknit/rb_engine.rb +3 -3
- data/lib/gknit/ruby_engine.rb +0 -0
- data/lib/gknit.rb +3 -0
- data/lib/new_bridge/bootstrap/windows_bootstrap.rb +285 -0
- data/lib/new_bridge/envelope.rb +51 -0
- data/lib/new_bridge/eval_result.rb +26 -0
- data/lib/new_bridge/framing.rb +39 -0
- data/lib/new_bridge/instance_pool_client.rb +38 -0
- data/lib/new_bridge/r_instance_manager.rb +404 -0
- data/lib/new_bridge/session_client.rb +530 -0
- data/lib/new_bridge/tcp_framed.rb +44 -0
- data/lib/new_bridge.rb +9 -0
- data/lib/util/exec_ruby.rb +95 -46
- data/lib/util/inline_file.rb +35 -30
- data/new_bridge_specs/benchmark_phase5_5_unboxing_spec.rb +96 -0
- data/new_bridge_specs/eval_r_async_spec.rb +113 -0
- data/new_bridge_specs/integration_phase5_1_concurrent_spec.rb +50 -0
- data/new_bridge_specs/integration_phase5_1_eval_spec.rb +16 -0
- data/new_bridge_specs/integration_phase5_1_r_api_spec.rb +25 -0
- data/new_bridge_specs/integration_phase5_1_smoke_spec.rb +31 -0
- data/new_bridge_specs/integration_phase5_2_dataframe_unboxing_spec.rb +19 -0
- data/new_bridge_specs/integration_phase5_2_handle_eval_unboxing_spec.rb +25 -0
- data/new_bridge_specs/integration_phase5_3_callback_args_spec.rb +28 -0
- data/new_bridge_specs/integration_phase5_3_callback_error_spec.rb +22 -0
- data/new_bridge_specs/integration_phase5_3_callback_timeout_spec.rb +28 -0
- data/new_bridge_specs/integration_phase5_3_callbacks_smoke_spec.rb +22 -0
- data/new_bridge_specs/integration_phase5_3_edge_cases_spec.rb +52 -0
- data/new_bridge_specs/integration_phase5_3_nested_spec.rb +30 -0
- data/new_bridge_specs/integration_phase5_4_concurrent_sessions_spec.rb +53 -0
- data/new_bridge_specs/integration_phase5_4_nested_session_callbacks_spec.rb +49 -0
- data/new_bridge_specs/integration_phase5_4_session_routing_spec.rb +38 -0
- data/new_bridge_specs/integration_phase5_5_stress_concurrency_spec.rb +52 -0
- data/new_bridge_specs/integration_phase5_5_unbox_walk_spec.rb +46 -0
- data/new_bridge_specs/phase0_protocol_spec.rb +96 -0
- data/new_bridge_specs/phase1_req_ret_spec.rb +66 -0
- data/new_bridge_specs/phase2_multi_instance_spec.rb +67 -0
- data/new_bridge_specs/phase3_callbacks_spec.rb +71 -0
- data/new_bridge_specs/phase4_2_hardening_spec.rb +252 -0
- data/new_bridge_specs/phase4_3_r_instance_manager_spec.rb +85 -0
- data/new_bridge_specs/phase4_nested_callbacks_spec.rb +123 -0
- data/r_requires/ggplot.rb +0 -0
- data/r_requires/knitr.rb +0 -0
- data/specs/all.rb +15 -11
- data/specs/arrow_from_ruby_batches_spec.rb +50 -0
- data/specs/arrow_semantics_spec.rb +64 -0
- data/specs/bridge_concurrent_spec.rb +46 -0
- data/specs/bridge_nested_spec.rb +25 -0
- data/specs/dataframe_semantics_spec.rb +122 -0
- data/specs/dataframe_single_index_logical_filter_spec.rb +21 -0
- data/specs/dispatch_probe_cache_spec.rb +38 -0
- data/specs/dispatch_probe_error_class_fallback_spec.rb +20 -0
- data/specs/dispatch_probe_fallback_spec.rb +18 -0
- data/specs/environment_semantics_spec.rb +89 -0
- data/specs/field_access_spec.rb +31 -0
- data/specs/figures/bg.jpeg +0 -0
- data/specs/figures/bg.png +0 -0
- data/specs/figures/bg.svg +168 -57
- data/specs/figures/dose_len.png +0 -0
- data/specs/figures/no_args.jpeg +0 -0
- data/specs/figures/no_args.png +0 -0
- data/specs/figures/no_args.svg +168 -57
- data/specs/figures/width_height.jpeg +0 -0
- data/specs/figures/width_height.png +0 -0
- data/specs/figures/width_height_units1.jpeg +0 -0
- data/specs/figures/width_height_units1.png +0 -0
- data/specs/figures/width_height_units2.jpeg +0 -0
- data/specs/figures/width_height_units2.png +0 -0
- data/specs/formula_semantics_spec.rb +81 -0
- data/specs/galaaz_util_exec_ruby_spec.rb +85 -0
- data/specs/galaaz_util_inline_file_spec.rb +54 -0
- data/specs/gknit_cli_option_permutation_spec.rb +24 -0
- data/specs/gknit_include_engine_spec.rb +72 -0
- data/specs/gknit_install_timeout_report_spec.rb +69 -0
- data/specs/gknit_internal_error_report_spec.rb +57 -0
- data/specs/gknit_vector_map_output_spec.rb +59 -0
- data/specs/globalenv_guardrail_spec.rb +52 -0
- data/specs/language_expression_semantics_spec.rb +145 -0
- data/specs/list_semantics_spec.rb +111 -0
- data/specs/new_bridge_bulk_dataframe_transfer_spec.rb +44 -0
- data/specs/new_bridge_bulk_vector_transfer_spec.rb +73 -0
- data/specs/new_bridge_callback_timeout_spec.rb +69 -0
- data/specs/new_bridge_eval_r_fallback_spec.rb +55 -0
- data/specs/nil_null_spec.rb +42 -0
- data/specs/object_build_phase2_spec.rb +53 -0
- data/specs/phase1_callback_bridge_spec.rb +84 -0
- data/specs/phase2_gknit_generic_rendering_guardrail_spec.rb +46 -0
- data/specs/phase2_gknit_no_raw_code_leakage_spec.rb +43 -0
- data/specs/phase3_gknit_generic_graphics_capture_spec.rb +71 -0
- data/specs/plot_device_semantics_spec.rb +28 -0
- data/specs/plot_snapshot_semantics_spec.rb +58 -0
- data/specs/protocol_result_spec.rb +236 -0
- data/specs/r_batch_fail_fast_spec.rb +47 -0
- data/specs/r_bridge_bootstrap_spec.rb +11 -0
- data/specs/r_devices.spec.rb +1 -1
- data/specs/r_eval.spec.rb +16 -18
- data/specs/r_function.spec.rb +1 -1
- data/specs/r_instance_manager_spec.rb +285 -0
- data/specs/r_list_apply.spec.rb +15 -15
- data/specs/r_matrix.spec.rb +0 -0
- data/specs/r_nse.spec.rb +5 -5
- data/specs/r_object_send_dispatch_spec.rb +13 -0
- data/specs/r_vector_comparator_spec.rb +8 -0
- data/specs/r_vector_creation.spec.rb +0 -0
- data/specs/r_vector_functions.spec.rb +0 -0
- data/specs/r_vector_object.spec.rb +0 -0
- data/specs/r_vector_operators.spec.rb +0 -0
- data/specs/r_vector_structured_scalar_reads_spec.rb +35 -0
- data/specs/r_vector_subsetting.spec.rb +0 -0
- data/specs/range_helper_spec.rb +21 -0
- data/specs/rsupport_scope_spec.rb +28 -0
- data/specs/rsupport_var_name_thread_safety_spec.rb +24 -0
- data/specs/scalar_character_spec.rb +44 -0
- data/specs/scoped_symbol_dsl_refinement_spec.rb +40 -0
- data/specs/session_env_bridge_spec.rb +25 -0
- data/specs/simplecov_bootstrap_spec.rb +10 -0
- data/specs/spec_helper.rb +10 -0
- data/specs/tmp.rb +41 -20
- data/specs/unboxing_recursion_regression_spec.rb +30 -0
- data/specs/unboxing_spec.rb +49 -0
- data/specs/verify_callbacks.rb +42 -0
- data/sty/galaaz.sty +0 -0
- data/version.rb +1 -1
- metadata +239 -71
- data/blogs/galaaz_ggplot/galaaz_ggplot.aux +0 -41
- data/blogs/galaaz_ggplot/galaaz_ggplot.html +0 -705
- data/blogs/galaaz_ggplot/galaaz_ggplot.out +0 -10
- data/blogs/galaaz_ggplot/galaaz_ggplot.pdf +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-latex/midwest_rb.pdf +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-latex/scatter_plot_rb.pdf +0 -0
- data/blogs/galaaz_ggplot/midwest.html +0 -188
- data/blogs/gknit/gknit.html +0 -2266
- data/blogs/gknit/gknit.pdf +0 -0
- data/blogs/gknit/gknit.tex +0 -1358
- data/blogs/manual/graph.rb +0 -29
- data/blogs/manual/manual.html +0 -2995
- data/blogs/manual/manual.pdf +0 -0
- data/blogs/manual/manual_files/figure-latex/diverging_bar.pdf +0 -0
- data/blogs/nse_dplyr/nse_dplyr.html +0 -960
- data/blogs/nse_dplyr/nse_dplyr.pdf +0 -0
- data/blogs/nse_dplyr/nse_dplyr.tex +0 -1373
- data/blogs/oh_my/oh_my.html +0 -680
- data/blogs/ruby_plot/ruby_plot.Rmd_external_figs +0 -662
- data/blogs/ruby_plot/ruby_plot.html +0 -729
- data/blogs/ruby_plot/ruby_plot.pdf +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.svg +0 -57
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.svg +0 -106
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.svg +0 -110
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.svg +0 -174
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.svg +0 -236
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.svg +0 -296
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.svg +0 -236
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.svg +0 -218
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.svg +0 -128
- data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.svg +0 -150
- data/examples/paper/paper.rb +0 -36
- data/specs/r_dataframe.spec.rb +0 -379
- data/specs/r_environment.spec.rb +0 -140
- data/specs/r_formula.spec.rb +0 -232
- data/specs/r_language.spec.rb +0 -112
- data/specs/r_list.spec.rb +0 -293
- data/specs/r_plots.spec.rb +0 -72
- data/specs/ruby_expression.spec.rb +0 -315
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
% Options for packages loaded elsewhere
|
|
2
|
+
\PassOptionsToPackage{unicode}{hyperref}
|
|
3
|
+
\PassOptionsToPackage{hyphens}{url}
|
|
4
|
+
\documentclass[
|
|
5
|
+
11pt,
|
|
6
|
+
]{article}
|
|
7
|
+
\usepackage{xcolor}
|
|
8
|
+
\usepackage[margin=1in]{geometry}
|
|
9
|
+
\usepackage{amsmath,amssymb}
|
|
10
|
+
\setcounter{secnumdepth}{5}
|
|
11
|
+
\usepackage{iftex}
|
|
12
|
+
\ifPDFTeX
|
|
13
|
+
\usepackage[T1]{fontenc}
|
|
14
|
+
\usepackage[utf8]{inputenc}
|
|
15
|
+
\usepackage{textcomp} % provide euro and other symbols
|
|
16
|
+
\else % if luatex or xetex
|
|
17
|
+
\usepackage{unicode-math} % this also loads fontspec
|
|
18
|
+
\defaultfontfeatures{Scale=MatchLowercase}
|
|
19
|
+
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
|
|
20
|
+
\fi
|
|
21
|
+
\usepackage{lmodern}
|
|
22
|
+
\ifPDFTeX\else
|
|
23
|
+
% xetex/luatex font selection
|
|
24
|
+
\fi
|
|
25
|
+
% Use upquote if available, for straight quotes in verbatim environments
|
|
26
|
+
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
|
|
27
|
+
\IfFileExists{microtype.sty}{% use microtype if available
|
|
28
|
+
\usepackage[]{microtype}
|
|
29
|
+
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
|
|
30
|
+
}{}
|
|
31
|
+
\makeatletter
|
|
32
|
+
\@ifundefined{KOMAClassName}{% if non-KOMA class
|
|
33
|
+
\IfFileExists{parskip.sty}{%
|
|
34
|
+
\usepackage{parskip}
|
|
35
|
+
}{% else
|
|
36
|
+
\setlength{\parindent}{0pt}
|
|
37
|
+
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
|
|
38
|
+
}{% if KOMA class
|
|
39
|
+
\KOMAoptions{parskip=half}}
|
|
40
|
+
\makeatother
|
|
41
|
+
\usepackage{color}
|
|
42
|
+
\usepackage{fancyvrb}
|
|
43
|
+
\newcommand{\VerbBar}{|}
|
|
44
|
+
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
|
|
45
|
+
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
|
|
46
|
+
% Add ',fontsize=\small' for more characters per line
|
|
47
|
+
\usepackage{framed}
|
|
48
|
+
\definecolor{shadecolor}{RGB}{248,248,248}
|
|
49
|
+
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
|
|
50
|
+
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
|
|
51
|
+
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
52
|
+
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
|
|
53
|
+
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
|
54
|
+
\newcommand{\BuiltInTok}[1]{#1}
|
|
55
|
+
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
|
56
|
+
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
|
|
57
|
+
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
58
|
+
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
|
|
59
|
+
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
|
|
60
|
+
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
|
|
61
|
+
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
|
62
|
+
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
63
|
+
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
|
|
64
|
+
\newcommand{\ExtensionTok}[1]{#1}
|
|
65
|
+
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
|
|
66
|
+
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
|
|
67
|
+
\newcommand{\ImportTok}[1]{#1}
|
|
68
|
+
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
69
|
+
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
|
|
70
|
+
\newcommand{\NormalTok}[1]{#1}
|
|
71
|
+
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
|
|
72
|
+
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
|
|
73
|
+
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
|
|
74
|
+
\newcommand{\RegionMarkerTok}[1]{#1}
|
|
75
|
+
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
|
|
76
|
+
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
|
77
|
+
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
|
78
|
+
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
|
|
79
|
+
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
|
|
80
|
+
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
|
|
81
|
+
\usepackage{graphicx}
|
|
82
|
+
\makeatletter
|
|
83
|
+
\newsavebox\pandoc@box
|
|
84
|
+
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
|
|
85
|
+
\sbox\pandoc@box{#1}%
|
|
86
|
+
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
|
|
87
|
+
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
|
|
88
|
+
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
|
|
89
|
+
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
|
|
90
|
+
\else\usebox{\pandoc@box}%
|
|
91
|
+
\fi%
|
|
92
|
+
}
|
|
93
|
+
% Set default figure placement to htbp
|
|
94
|
+
\def\fps@figure{htbp}
|
|
95
|
+
\makeatother
|
|
96
|
+
\setlength{\emergencystretch}{3em} % prevent overfull lines
|
|
97
|
+
\providecommand{\tightlist}{%
|
|
98
|
+
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
|
|
99
|
+
% usar portugues do Brasil
|
|
100
|
+
% \usepackage[brazilian]{babel}
|
|
101
|
+
\usepackage[utf8]{inputenc}
|
|
102
|
+
|
|
103
|
+
\usepackage{geometry}
|
|
104
|
+
\geometry{a4paper, top=1in}
|
|
105
|
+
|
|
106
|
+
% needed for kableExtra
|
|
107
|
+
\usepackage{longtable}
|
|
108
|
+
\usepackage{multirow}
|
|
109
|
+
\usepackage[table]{xcolor}
|
|
110
|
+
\usepackage{wrapfig}
|
|
111
|
+
\usepackage{float}
|
|
112
|
+
\usepackage{colortbl}
|
|
113
|
+
\usepackage{pdflscape}
|
|
114
|
+
\usepackage{tabu}
|
|
115
|
+
\usepackage{threeparttable}
|
|
116
|
+
\usepackage[normalem]{ulem}
|
|
117
|
+
|
|
118
|
+
\usepackage{bbm}
|
|
119
|
+
\usepackage{booktabs}
|
|
120
|
+
\usepackage{expex}
|
|
121
|
+
|
|
122
|
+
\usepackage{graphicx}
|
|
123
|
+
|
|
124
|
+
\usepackage{fancyhdr}
|
|
125
|
+
% set the header and foot style
|
|
126
|
+
% style 'fancy' adds the section name on the header
|
|
127
|
+
% and the page number on the footer
|
|
128
|
+
\pagestyle{fancy}
|
|
129
|
+
|
|
130
|
+
% style 'fancyhf' leaves header and footer empty
|
|
131
|
+
%\fancyhf{}
|
|
132
|
+
|
|
133
|
+
% sets the left head element to \rightmark, which contains the
|
|
134
|
+
% current section (\leftmark is the current chapter)
|
|
135
|
+
%\fancyhead[L]{\rightmark} .
|
|
136
|
+
|
|
137
|
+
% sets the right head element to the page number.
|
|
138
|
+
% \fancyhead[R]{\thepage}
|
|
139
|
+
|
|
140
|
+
% lets the head rule disappear.
|
|
141
|
+
% \renewcommand{\headrulewidth}{0pt}
|
|
142
|
+
% Possible selectors for the optional argument of \fancyhead/\fancyfoot
|
|
143
|
+
% are L (left), C (center) or R (right) for the position of the element
|
|
144
|
+
% and E (even) or O (odd) to distinguish even and odd pages. If you omit
|
|
145
|
+
% E/O the element is set for all pages.
|
|
146
|
+
|
|
147
|
+
% \usepackage{lipsum}
|
|
148
|
+
|
|
149
|
+
% make available command lastpage
|
|
150
|
+
\usepackage{lastpage}
|
|
151
|
+
|
|
152
|
+
% default fontsize 11pt better to add
|
|
153
|
+
% fontsize on the yaml header
|
|
154
|
+
% \usepackage[fontsize=11pt]{scrextend}
|
|
155
|
+
|
|
156
|
+
% comandos para formatar uma tabela
|
|
157
|
+
\usepackage{array}
|
|
158
|
+
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
|
159
|
+
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
|
160
|
+
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
|
|
161
|
+
|
|
162
|
+
% necessário if we need to import other latex documents
|
|
163
|
+
\usepackage{import}
|
|
164
|
+
|
|
165
|
+
% Command to import an R variable to latex
|
|
166
|
+
\newcommand{\RtoLatex}[2]{\newcommand{#1}{#2}}
|
|
167
|
+
|
|
168
|
+
%
|
|
169
|
+
%\newcommand{\atraso}[1]{\color{red} \textbf {Tempo desde a Assinatura do Contrato: #1 dias}}
|
|
170
|
+
\usepackage{bookmark}
|
|
171
|
+
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
|
|
172
|
+
\urlstyle{same}
|
|
173
|
+
\hypersetup{
|
|
174
|
+
pdftitle={Extending R with classes{,} modules{,} procs{,} lambdas{,} oh my!},
|
|
175
|
+
pdfauthor={Rodrigo Botafogo; Daniel Mossé - University of Pittsburgh},
|
|
176
|
+
hidelinks,
|
|
177
|
+
pdfcreator={LaTeX via pandoc}}
|
|
178
|
+
|
|
179
|
+
\title{Extending R with classes, modules, procs, lambdas, oh my!}
|
|
180
|
+
\author{Rodrigo Botafogo \and Daniel Mossé - University of Pittsburgh}
|
|
181
|
+
\date{November 19th, 2018 (narrative updated for Galaaz 2.0, 2026)}
|
|
182
|
+
|
|
183
|
+
\begin{document}
|
|
184
|
+
\maketitle
|
|
185
|
+
|
|
186
|
+
{
|
|
187
|
+
\setcounter{tocdepth}{2}
|
|
188
|
+
\tableofcontents
|
|
189
|
+
}
|
|
190
|
+
\section{Introduction}\label{introduction}
|
|
191
|
+
|
|
192
|
+
This paper introduces and compares Galaaz with R's S4. It is a shameless
|
|
193
|
+
rip off of
|
|
194
|
+
\href{https://cran.r-project.org/doc/contrib/Genolini-S4tutorialV0-5en.pdf}{``A
|
|
195
|
+
`(not so)' Short Introduction to S4''} by Christophe Genolini and
|
|
196
|
+
follows the same structure and examples presented there.
|
|
197
|
+
|
|
198
|
+
Galaaz is a Ruby Gem (library) that allows very tight integration
|
|
199
|
+
between Ruby and R.\\
|
|
200
|
+
Its integration is tighter and more transparent than what one can get
|
|
201
|
+
between RinRuby or similar solutions in Python, such as
|
|
202
|
+
\href{https://pypi.python.org/pypi/PypeR/1.1.0}{PypeR},
|
|
203
|
+
\href{http://rpy2.bitbucket.org/}{rpy2} and other similar solutions.
|
|
204
|
+
|
|
205
|
+
\textbf{Galaaz 2.0} runs on
|
|
206
|
+
\textbf{\href{https://www.jruby.org/}{JRuby}} and drives \textbf{GNU R}
|
|
207
|
+
through a \textbf{bridge}, so Ruby code can create and manipulate R
|
|
208
|
+
objects and call R functions while staying idiomatic Ruby. An earlier
|
|
209
|
+
prototype used Oracle's \textbf{GraalVM} with \textbf{TruffleRuby} and
|
|
210
|
+
\textbf{FastR}; that stack is historical and is \textbf{not} what
|
|
211
|
+
current Galaaz targets.
|
|
212
|
+
|
|
213
|
+
\section{Bases of Object Programming}\label{bases-of-object-programming}
|
|
214
|
+
|
|
215
|
+
In this paper, we will start our discussion from Part II of ``The (not
|
|
216
|
+
so) Short Introduction to S4'', which from now on we will reference as
|
|
217
|
+
SS4 for ``short S4''. Interested readers are directed to this paper to
|
|
218
|
+
understand the motivation and examples in that paper. In this paper we
|
|
219
|
+
will present the S4 code from SS4 and then the same code in Ruby/Galaaz.
|
|
220
|
+
We will not comment on the S4 code, as all the comments can be found in
|
|
221
|
+
SS4, we will only focus on the Ruby/Galaaz description.
|
|
222
|
+
|
|
223
|
+
S4 defines classes by using the setClass function:
|
|
224
|
+
|
|
225
|
+
\section{Classes Declaration}\label{classes-declaration}
|
|
226
|
+
|
|
227
|
+
\begin{verbatim}
|
|
228
|
+
# > setClass(
|
|
229
|
+
# + Class="Trajectories",
|
|
230
|
+
# + representation=representation(
|
|
231
|
+
# + times = "numeric",
|
|
232
|
+
# + traj = "matrix"
|
|
233
|
+
# + )
|
|
234
|
+
# + )
|
|
235
|
+
\end{verbatim}
|
|
236
|
+
|
|
237
|
+
\section{Instance Variables}\label{instance-variables}
|
|
238
|
+
|
|
239
|
+
In Ruby a class is defined by the keyword `class'. Every class should
|
|
240
|
+
start with a capital letter. S4 `slots' are called `instance variables'
|
|
241
|
+
in Ruby. Differently from R's S4, instance variables in Ruby do not have
|
|
242
|
+
type information. It should be clear though, that S4 type information is
|
|
243
|
+
also not a ``compile'' time type, since R is not compiled. The type is
|
|
244
|
+
checked at runtime. The same checking can be done in Ruby and we will do
|
|
245
|
+
it later in this document.
|
|
246
|
+
|
|
247
|
+
In the example bellow, we create class Trajectories with two instance
|
|
248
|
+
variables, `times' and `matrix'. We will not go over the details of
|
|
249
|
+
instance variables in Ruby, but here we created those variables with the
|
|
250
|
+
keyword `attr\_reader' and a colom before the variables name:
|
|
251
|
+
|
|
252
|
+
\begin{Shaded}
|
|
253
|
+
\begin{Highlighting}[]
|
|
254
|
+
\ControlFlowTok{class} \DataTypeTok{Trajectories}
|
|
255
|
+
\OtherTok{attr\_reader} \WarningTok{:times}
|
|
256
|
+
\OtherTok{attr\_reader} \WarningTok{:matrix}
|
|
257
|
+
\ControlFlowTok{end}
|
|
258
|
+
\end{Highlighting}
|
|
259
|
+
\end{Shaded}
|
|
260
|
+
|
|
261
|
+
In order to create a new instance of object Trajectories we call method
|
|
262
|
+
new on the class and we can store the result in a varible (not an
|
|
263
|
+
instance variable) as bellow:
|
|
264
|
+
|
|
265
|
+
\begin{Shaded}
|
|
266
|
+
\begin{Highlighting}[]
|
|
267
|
+
\OtherTok{@traj} \OperatorTok{=} \DataTypeTok{Trajectories}\AttributeTok{.new}
|
|
268
|
+
\end{Highlighting}
|
|
269
|
+
\end{Shaded}
|
|
270
|
+
|
|
271
|
+
We now have in variable `@traj' a Trajectories object. In Ruby, printing
|
|
272
|
+
variable `traj' will only print the class name of the object and not it
|
|
273
|
+
contents as in R.
|
|
274
|
+
|
|
275
|
+
\begin{Shaded}
|
|
276
|
+
\begin{Highlighting}[]
|
|
277
|
+
\FunctionTok{puts} \OtherTok{@traj}
|
|
278
|
+
\end{Highlighting}
|
|
279
|
+
\end{Shaded}
|
|
280
|
+
|
|
281
|
+
\begin{verbatim}
|
|
282
|
+
## #<RC::Trajectories:0x378c2595>
|
|
283
|
+
\end{verbatim}
|
|
284
|
+
|
|
285
|
+
To see the contents of an object, one needs to access its components
|
|
286
|
+
using the `.' operator:
|
|
287
|
+
|
|
288
|
+
\begin{Shaded}
|
|
289
|
+
\begin{Highlighting}[]
|
|
290
|
+
\FunctionTok{puts} \OtherTok{@traj}\AttributeTok{.times}
|
|
291
|
+
\end{Highlighting}
|
|
292
|
+
\end{Shaded}
|
|
293
|
+
|
|
294
|
+
\section{Constructor}\label{constructor}
|
|
295
|
+
|
|
296
|
+
Since there is no content stored in `times' nor `matrix', nil is
|
|
297
|
+
returned. In order to add a value in the variables, we need to add a
|
|
298
|
+
constructor to the class Trajectories. In R, a constructor is build by
|
|
299
|
+
default, in Ruby, this has to be created by adding a method called
|
|
300
|
+
`initialize'. In the example bellow, we will create the initializer that
|
|
301
|
+
accepts two values, a `times' value and a `matrix' value and they are
|
|
302
|
+
used to initialize the value of the instance variables:
|
|
303
|
+
|
|
304
|
+
\begin{Shaded}
|
|
305
|
+
\begin{Highlighting}[]
|
|
306
|
+
\ControlFlowTok{class} \DataTypeTok{Trajectories}
|
|
307
|
+
|
|
308
|
+
\OtherTok{attr\_reader} \WarningTok{:times}
|
|
309
|
+
\OtherTok{attr\_reader} \WarningTok{:matrix}
|
|
310
|
+
|
|
311
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
312
|
+
\CommentTok{\# Initializes the Trajectories class. Takes two parameters}
|
|
313
|
+
\CommentTok{\# @param times}
|
|
314
|
+
\CommentTok{\# @param matrix}
|
|
315
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
316
|
+
|
|
317
|
+
\ControlFlowTok{def}\NormalTok{ initialize(times}\OperatorTok{:} \DecValTok{nil}\NormalTok{, }\WarningTok{matrix:} \DecValTok{nil}\NormalTok{)}
|
|
318
|
+
\OtherTok{@times} \OperatorTok{=}\NormalTok{ times}
|
|
319
|
+
\OtherTok{@matrix} \OperatorTok{=}\NormalTok{ matrix}
|
|
320
|
+
\ControlFlowTok{end}
|
|
321
|
+
|
|
322
|
+
\ControlFlowTok{end}
|
|
323
|
+
\end{Highlighting}
|
|
324
|
+
\end{Shaded}
|
|
325
|
+
|
|
326
|
+
Up to this point, everything described is pure Ruby code and has
|
|
327
|
+
absolutely no relationship with R. We now want to create a Trajectories
|
|
328
|
+
with a `times' vector. Ruby has a vector class and we could use this
|
|
329
|
+
class to create a vector and add it to the `times' instance variable;
|
|
330
|
+
however, in order to make use of R's functions, we want to create a R
|
|
331
|
+
vector to add to `times'. In Galaaz, creating R objects is done using
|
|
332
|
+
the corresponding R functions by just preceding them with `R.', i.e., R
|
|
333
|
+
functions are all defined in Galaaz in the R namespace.
|
|
334
|
+
|
|
335
|
+
Since Galaaz is Ruby and not R, some syntax adjustments are sometimes
|
|
336
|
+
necessary. For instance, in R, a range is represented as `(1:4)', in
|
|
337
|
+
Ruby, the same range is represented as `(1..4)'. When passing arguments
|
|
338
|
+
to an R function in R one uses the `=' sign after the slot name; in R,
|
|
339
|
+
one uses the `:' operator after parameter's name as we can see bellow:
|
|
340
|
+
|
|
341
|
+
\begin{Shaded}
|
|
342
|
+
\begin{Highlighting}[]
|
|
343
|
+
\CommentTok{\# Create a Trajectories passing a times vector, but no matrix parameter}
|
|
344
|
+
\OtherTok{@traj} \OperatorTok{=} \DataTypeTok{Trajectories}\AttributeTok{.new}\NormalTok{(}\WarningTok{times:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{))}
|
|
345
|
+
|
|
346
|
+
\CommentTok{\# Create a Trajectories with times and matrix}
|
|
347
|
+
\OtherTok{@traj2} \OperatorTok{=} \DataTypeTok{Trajectories}\AttributeTok{.new}\NormalTok{(}\WarningTok{times:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{), }\WarningTok{matrix:} \ConstantTok{R}\AttributeTok{.matrix}\NormalTok{((}\DecValTok{1}\OperatorTok{..}\DecValTok{4}\NormalTok{), }\WarningTok{ncol:} \DecValTok{2}\NormalTok{))}
|
|
348
|
+
\end{Highlighting}
|
|
349
|
+
\end{Shaded}
|
|
350
|
+
|
|
351
|
+
\section{Access to Instance Variables (to reach a
|
|
352
|
+
slot)}\label{access-to-instance-variables-to-reach-a-slot}
|
|
353
|
+
|
|
354
|
+
In order to access data in an instance variable the operator `.' is
|
|
355
|
+
used. In R, a similar result is obtained by use of the `@' operator, but
|
|
356
|
+
SS4 does not recommend its use. In Galaaz, the `.' operator is the
|
|
357
|
+
recommended way of accessing an instance variable.
|
|
358
|
+
|
|
359
|
+
Now that we have created two trajectories, let's try to print its
|
|
360
|
+
instance variables to see that everything is fine:
|
|
361
|
+
|
|
362
|
+
\begin{Shaded}
|
|
363
|
+
\begin{Highlighting}[]
|
|
364
|
+
\FunctionTok{puts} \OtherTok{@traj}\AttributeTok{.times}
|
|
365
|
+
\end{Highlighting}
|
|
366
|
+
\end{Shaded}
|
|
367
|
+
|
|
368
|
+
\begin{verbatim}
|
|
369
|
+
## [1] 1 2 3 4
|
|
370
|
+
\end{verbatim}
|
|
371
|
+
|
|
372
|
+
We now have the expected value. Note that the `times' vector is printed
|
|
373
|
+
exactly as it would if we were using GNU R. Let's now take a look at
|
|
374
|
+
variable `traj2':
|
|
375
|
+
|
|
376
|
+
\begin{Shaded}
|
|
377
|
+
\begin{Highlighting}[]
|
|
378
|
+
\FunctionTok{puts} \OtherTok{@traj2}\AttributeTok{.times}
|
|
379
|
+
\FunctionTok{puts}
|
|
380
|
+
\FunctionTok{puts} \OtherTok{@traj2}\AttributeTok{.matrix}
|
|
381
|
+
\end{Highlighting}
|
|
382
|
+
\end{Shaded}
|
|
383
|
+
|
|
384
|
+
\begin{verbatim}
|
|
385
|
+
## [1] 1 3
|
|
386
|
+
##
|
|
387
|
+
## [,1] [,2]
|
|
388
|
+
## [1,] 1 3
|
|
389
|
+
## [2,] 2 4
|
|
390
|
+
\end{verbatim}
|
|
391
|
+
|
|
392
|
+
Let's now build the same examples as in SS4: Three hospitals take part
|
|
393
|
+
in a study. The Pitié Salpêtriere (which has not yet returned its data
|
|
394
|
+
file, shame on them!), Cochin and Saint-Anne. We first show the code in
|
|
395
|
+
R and the corresponding Galaaz:
|
|
396
|
+
|
|
397
|
+
\begin{verbatim}
|
|
398
|
+
> trajPitie <- new(Class="Trajectories")
|
|
399
|
+
> trajCochin <- new(
|
|
400
|
+
+ Class= "Trajectories",
|
|
401
|
+
+ times=c(1,3,4,5),
|
|
402
|
+
+ traj=rbind (
|
|
403
|
+
+ c(15,15.1, 15.2, 15.2),
|
|
404
|
+
+ c(16,15.9, 16,16.4),
|
|
405
|
+
+ c(15.2, NA, 15.3, 15.3),
|
|
406
|
+
+ c(15.7, 15.6, 15.8, 16)
|
|
407
|
+
+ )
|
|
408
|
+
+ )
|
|
409
|
+
> trajStAnne <- new(
|
|
410
|
+
+ Class= "Trajectories",
|
|
411
|
+
+ times=c(1: 10, (6: 16) *2),
|
|
412
|
+
+ traj=rbind(
|
|
413
|
+
+ matrix (seq (16,19, length=21), ncol=21, nrow=50, byrow=TRUE),
|
|
414
|
+
+ matrix (seq (15.8, 18, length=21), ncol=21, nrow=30, byrow=TRUE)
|
|
415
|
+
+ )+rnorm (21*80,0,0.2)
|
|
416
|
+
+ )
|
|
417
|
+
\end{verbatim}
|
|
418
|
+
|
|
419
|
+
This same code in Galaaz becomes:
|
|
420
|
+
|
|
421
|
+
\begin{Shaded}
|
|
422
|
+
\begin{Highlighting}[]
|
|
423
|
+
\OtherTok{@trajPitie} \OperatorTok{=} \DataTypeTok{Trajectories}\AttributeTok{.new}
|
|
424
|
+
|
|
425
|
+
\OtherTok{@trajCochin} \OperatorTok{=} \DataTypeTok{Trajectories}\AttributeTok{.new}\NormalTok{(}\WarningTok{times:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{,}\DecValTok{5}\NormalTok{),}
|
|
426
|
+
\WarningTok{matrix:} \ConstantTok{R}\AttributeTok{.rbind}\NormalTok{(}
|
|
427
|
+
\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{15}\NormalTok{,}\FloatTok{15.1}\NormalTok{, }\FloatTok{15.2}\NormalTok{, }\FloatTok{15.2}\NormalTok{),}
|
|
428
|
+
\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{16}\NormalTok{,}\FloatTok{15.9}\NormalTok{, }\DecValTok{16}\NormalTok{,}\FloatTok{16.4}\NormalTok{),}
|
|
429
|
+
\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{15.2}\NormalTok{, }\ConstantTok{R}\OperatorTok{::}\ConstantTok{NA}\NormalTok{, }\FloatTok{15.3}\NormalTok{, }\FloatTok{15.3}\NormalTok{),}
|
|
430
|
+
\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\FloatTok{15.7}\NormalTok{, }\FloatTok{15.6}\NormalTok{, }\FloatTok{15.8}\NormalTok{, }\DecValTok{16}\NormalTok{)))}
|
|
431
|
+
|
|
432
|
+
\OtherTok{@trajStAnne} \OperatorTok{=}
|
|
433
|
+
\DataTypeTok{Trajectories}\AttributeTok{.new}\NormalTok{(}\WarningTok{times:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{((}\DecValTok{1}\OperatorTok{..}\DecValTok{10}\NormalTok{), }\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{6}\OperatorTok{..}\DecValTok{16}\NormalTok{) }\OperatorTok{*} \DecValTok{2}\NormalTok{),}
|
|
434
|
+
\WarningTok{matrix:}\NormalTok{ (}\ConstantTok{R}\AttributeTok{.rbind}\NormalTok{(}
|
|
435
|
+
\ConstantTok{R}\AttributeTok{.matrix}\NormalTok{(}\ConstantTok{R}\AttributeTok{.seq}\NormalTok{(}\DecValTok{16}\NormalTok{, }\DecValTok{19}\NormalTok{, }\WarningTok{length:} \DecValTok{21}\NormalTok{), }\WarningTok{ncol:} \DecValTok{21}\NormalTok{,}
|
|
436
|
+
\WarningTok{nrow:} \DecValTok{50}\NormalTok{, }\WarningTok{byrow:} \DecValTok{true}\NormalTok{),}
|
|
437
|
+
\ConstantTok{R}\AttributeTok{.matrix}\NormalTok{(}\ConstantTok{R}\AttributeTok{.seq}\NormalTok{(}\FloatTok{15.8}\NormalTok{, }\DecValTok{18}\NormalTok{, }\WarningTok{length:} \DecValTok{21}\NormalTok{), }\WarningTok{ncol:} \DecValTok{21}\NormalTok{,}
|
|
438
|
+
\WarningTok{nrow:} \DecValTok{30}\NormalTok{, }\WarningTok{byrow:} \DecValTok{true}\NormalTok{)) }\OperatorTok{+} \ConstantTok{R}\AttributeTok{.rnorm}\NormalTok{(}\DecValTok{21}\OperatorTok{*}\DecValTok{80}\NormalTok{, }\DecValTok{0}\NormalTok{, }\FloatTok{0.2}\NormalTok{)))}
|
|
439
|
+
\end{Highlighting}
|
|
440
|
+
\end{Shaded}
|
|
441
|
+
|
|
442
|
+
Let's check that the `times' and `matrix' instance variables were
|
|
443
|
+
correctly set:
|
|
444
|
+
|
|
445
|
+
\begin{Shaded}
|
|
446
|
+
\begin{Highlighting}[]
|
|
447
|
+
\FunctionTok{puts} \OtherTok{@trajCochin}\AttributeTok{.times}
|
|
448
|
+
\FunctionTok{puts}
|
|
449
|
+
\FunctionTok{puts} \OtherTok{@trajCochin}\AttributeTok{.matrix}
|
|
450
|
+
\FunctionTok{puts}
|
|
451
|
+
\FunctionTok{puts} \OtherTok{@trajStAnne}\AttributeTok{.times}
|
|
452
|
+
\end{Highlighting}
|
|
453
|
+
\end{Shaded}
|
|
454
|
+
|
|
455
|
+
\begin{verbatim}
|
|
456
|
+
## [1] 1 3 4 5
|
|
457
|
+
##
|
|
458
|
+
## [,1] [,2] [,3] [,4]
|
|
459
|
+
## g2_v2114 15.0 15.1 15.2 15.2
|
|
460
|
+
## g2_v2115 16.0 15.9 16.0 16.4
|
|
461
|
+
## g2_v2116 15.2 NA 15.3 15.3
|
|
462
|
+
## g2_v2117 15.7 15.6 15.8 16.0
|
|
463
|
+
##
|
|
464
|
+
## [1] 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 22 24 26 28 30 32
|
|
465
|
+
\end{verbatim}
|
|
466
|
+
|
|
467
|
+
We will not at this time print trajStAnne.matrix, since this is a huge
|
|
468
|
+
matrix and the result would just take too much space. Later we will
|
|
469
|
+
print just a partial view of the matrix.
|
|
470
|
+
|
|
471
|
+
\section{Default Values}\label{default-values}
|
|
472
|
+
|
|
473
|
+
Default values are very useful and quite often used in Ruby programs.
|
|
474
|
+
Although SS4 does not recommend its use, there are many cases in which
|
|
475
|
+
default values are useful and make code simpler. We have already seen
|
|
476
|
+
default values in this document, with the default being `nil'. This was
|
|
477
|
+
necessary in order to be able to create our constructor and passing it
|
|
478
|
+
the proper values.
|
|
479
|
+
|
|
480
|
+
In the example bellow, a class TrajectoriesBis is created with default
|
|
481
|
+
value 1 for times and a matrix with no elements in matrix.
|
|
482
|
+
|
|
483
|
+
\begin{Shaded}
|
|
484
|
+
\begin{Highlighting}[]
|
|
485
|
+
\ControlFlowTok{class} \DataTypeTok{TrajectoriesBis}
|
|
486
|
+
|
|
487
|
+
\OtherTok{attr\_reader} \WarningTok{:times}
|
|
488
|
+
\OtherTok{attr\_reader} \WarningTok{:matrix}
|
|
489
|
+
|
|
490
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
491
|
+
\CommentTok{\# Initializes the Trajectories class. Takes two parameters}
|
|
492
|
+
\CommentTok{\# @param times}
|
|
493
|
+
\CommentTok{\# @param matrix}
|
|
494
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
495
|
+
|
|
496
|
+
\ControlFlowTok{def}\NormalTok{ initialize(times}\OperatorTok{:} \DecValTok{1}\NormalTok{, }\WarningTok{matrix:} \ConstantTok{R}\AttributeTok{.matrix}\NormalTok{(}\DecValTok{0}\NormalTok{))}
|
|
497
|
+
\OtherTok{@times} \OperatorTok{=}\NormalTok{ times}
|
|
498
|
+
\OtherTok{@matrix} \OperatorTok{=}\NormalTok{ matrix}
|
|
499
|
+
\ControlFlowTok{end}
|
|
500
|
+
|
|
501
|
+
\ControlFlowTok{end}
|
|
502
|
+
|
|
503
|
+
\OtherTok{@traj\_bis} \OperatorTok{=} \DataTypeTok{TrajectoriesBis}\AttributeTok{.new}
|
|
504
|
+
\end{Highlighting}
|
|
505
|
+
\end{Shaded}
|
|
506
|
+
|
|
507
|
+
Let's take a look at our new class:
|
|
508
|
+
|
|
509
|
+
\begin{Shaded}
|
|
510
|
+
\begin{Highlighting}[]
|
|
511
|
+
\FunctionTok{puts} \OtherTok{@traj\_bis}\AttributeTok{.times}
|
|
512
|
+
\FunctionTok{puts}
|
|
513
|
+
\FunctionTok{puts} \OtherTok{@traj\_bis}\AttributeTok{.matrix}
|
|
514
|
+
\end{Highlighting}
|
|
515
|
+
\end{Shaded}
|
|
516
|
+
|
|
517
|
+
\begin{verbatim}
|
|
518
|
+
## 1
|
|
519
|
+
##
|
|
520
|
+
## [,1]
|
|
521
|
+
## [1,] 0
|
|
522
|
+
\end{verbatim}
|
|
523
|
+
|
|
524
|
+
Note that `@traj\_bis.times' is the numeric 1, and what we actually want
|
|
525
|
+
is a vector with {[}1{]} in it.
|
|
526
|
+
|
|
527
|
+
\begin{Shaded}
|
|
528
|
+
\begin{Highlighting}[]
|
|
529
|
+
\ControlFlowTok{class} \DataTypeTok{TrajectoriesBis}
|
|
530
|
+
|
|
531
|
+
\OtherTok{attr\_reader} \WarningTok{:times}
|
|
532
|
+
\OtherTok{attr\_reader} \WarningTok{:matrix}
|
|
533
|
+
|
|
534
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
535
|
+
\CommentTok{\# Initializes the Trajectories class. Takes two parameters}
|
|
536
|
+
\CommentTok{\# @param times [R::Vector] should be an R vector.}
|
|
537
|
+
\CommentTok{\# @param matrix [R::Matrix] should be an R matrix.}
|
|
538
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
539
|
+
|
|
540
|
+
\CommentTok{\# Use R.c to convert number 1 to a vector}
|
|
541
|
+
\ControlFlowTok{def}\NormalTok{ initialize(times}\OperatorTok{:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{), }\WarningTok{matrix:} \ConstantTok{R}\AttributeTok{.matrix}\NormalTok{(}\DecValTok{0}\NormalTok{))}
|
|
542
|
+
\OtherTok{@times} \OperatorTok{=}\NormalTok{ times}
|
|
543
|
+
\OtherTok{@matrix} \OperatorTok{=}\NormalTok{ matrix}
|
|
544
|
+
\ControlFlowTok{end}
|
|
545
|
+
|
|
546
|
+
\ControlFlowTok{end}
|
|
547
|
+
|
|
548
|
+
\OtherTok{@traj\_bis} \OperatorTok{=} \DataTypeTok{TrajectoriesBis}\AttributeTok{.new}
|
|
549
|
+
\end{Highlighting}
|
|
550
|
+
\end{Shaded}
|
|
551
|
+
|
|
552
|
+
\begin{Shaded}
|
|
553
|
+
\begin{Highlighting}[]
|
|
554
|
+
\FunctionTok{puts} \OtherTok{@traj\_bis}\AttributeTok{.times}
|
|
555
|
+
\FunctionTok{puts}
|
|
556
|
+
\FunctionTok{puts} \OtherTok{@traj\_bis}\AttributeTok{.matrix}
|
|
557
|
+
\end{Highlighting}
|
|
558
|
+
\end{Shaded}
|
|
559
|
+
|
|
560
|
+
\begin{verbatim}
|
|
561
|
+
## [1] 1
|
|
562
|
+
##
|
|
563
|
+
## [,1]
|
|
564
|
+
## [1,] 0
|
|
565
|
+
\end{verbatim}
|
|
566
|
+
|
|
567
|
+
\section{The Empty Object}\label{the-empty-object}
|
|
568
|
+
|
|
569
|
+
When a Trajectories is created with new, and no argument is given, all
|
|
570
|
+
its instance variables will have the default nil value. Since Ruby has
|
|
571
|
+
no type information, then there is only one type (or actually no type)
|
|
572
|
+
of nil. To check if a variable is empty, we check it against the nil
|
|
573
|
+
value.
|
|
574
|
+
|
|
575
|
+
\section{To See an Object}\label{to-see-an-object}
|
|
576
|
+
|
|
577
|
+
Ruby has very strong meta-programming features, in particular, one can
|
|
578
|
+
use introspection to see methods and instance variables from a given
|
|
579
|
+
class. Method `instance\_variables' shows all the instance variables of
|
|
580
|
+
an object:
|
|
581
|
+
|
|
582
|
+
\begin{verbatim}
|
|
583
|
+
puts @traj.instance_variables
|
|
584
|
+
\end{verbatim}
|
|
585
|
+
|
|
586
|
+
The description of all meta-programming features of Ruby is well beyond
|
|
587
|
+
the scope of this document, but it is a very frequent a powerful feature
|
|
588
|
+
of Ruby, that makes programming in Ruby a different experience than
|
|
589
|
+
programming in other languages.
|
|
590
|
+
|
|
591
|
+
\section{Methods}\label{methods}
|
|
592
|
+
|
|
593
|
+
Methods are a fundamental feature of object oriented programming. We
|
|
594
|
+
will now extend our class Trajectories to add methods to it. In SS4, a
|
|
595
|
+
method `plot' is added to Trajectories. At this point, Renjin and Galaaz
|
|
596
|
+
do not yet have plotting capabilities, so we will have to skip this
|
|
597
|
+
method and go directly to the implementation of the `print' method.
|
|
598
|
+
|
|
599
|
+
Bellow is the R code for method print:
|
|
600
|
+
|
|
601
|
+
\begin{verbatim}
|
|
602
|
+
> setMethod ("print","Trajectories",
|
|
603
|
+
+ function(x,...){
|
|
604
|
+
+ cat("*** Class Trajectories, method Print *** \\n")
|
|
605
|
+
+ cat("* Times ="); print (x@times)
|
|
606
|
+
+ cat("* Traj = \\n"); print (x@traj)
|
|
607
|
+
+ cat("******* End Print (trajectories) ******* \\n")
|
|
608
|
+
+ }
|
|
609
|
+
+ )
|
|
610
|
+
\end{verbatim}
|
|
611
|
+
|
|
612
|
+
Now the same code for class Trajectories in Galaaz. In general methods
|
|
613
|
+
are defined in a class together with all the class definition. We will
|
|
614
|
+
first use this approach. Later, we will show how to `reopen' a class to
|
|
615
|
+
add new methods to it.
|
|
616
|
+
|
|
617
|
+
In this example, we are defining a method named `print'. We have being
|
|
618
|
+
using method `puts' to output data. There is a Ruby method that is more
|
|
619
|
+
flexible than puts and that we need to use to implement our function:
|
|
620
|
+
`print'. However, trying to use Ruby print inside the definition of
|
|
621
|
+
Trajectories's print will not work, as Ruby will understand that as a
|
|
622
|
+
recursive call to print. Ruby's print is defined inside the Kernel
|
|
623
|
+
class, so, in order to call Ruby's print inside the definition of
|
|
624
|
+
Trajectories's print we need to write `Kernel.print'.
|
|
625
|
+
|
|
626
|
+
\begin{Shaded}
|
|
627
|
+
\begin{Highlighting}[]
|
|
628
|
+
\ControlFlowTok{class} \DataTypeTok{Trajectories}
|
|
629
|
+
|
|
630
|
+
\OtherTok{attr\_reader} \WarningTok{:times}
|
|
631
|
+
\OtherTok{attr\_reader} \WarningTok{:matrix}
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
635
|
+
\CommentTok{\# Initializes the Trajectories class. Takes two parameters}
|
|
636
|
+
\CommentTok{\# @param times [R::Vector] should be an R vector.}
|
|
637
|
+
\CommentTok{\# @param matrix [R::Matrix] should be an R matrix.}
|
|
638
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
639
|
+
|
|
640
|
+
\ControlFlowTok{def}\NormalTok{ initialize(times}\OperatorTok{:} \DecValTok{nil}\NormalTok{, }\WarningTok{matrix:} \DecValTok{nil}\NormalTok{)}
|
|
641
|
+
\OtherTok{@times} \OperatorTok{=}\NormalTok{ times}
|
|
642
|
+
\OtherTok{@matrix} \OperatorTok{=}\NormalTok{ matrix}
|
|
643
|
+
\ControlFlowTok{end}
|
|
644
|
+
|
|
645
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
646
|
+
\CommentTok{\# }
|
|
647
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
648
|
+
|
|
649
|
+
\ControlFlowTok{def} \FunctionTok{print}
|
|
650
|
+
\FunctionTok{puts}\NormalTok{(}\StringTok{"*** Class Trajectories, method Print *** "}\NormalTok{)}
|
|
651
|
+
\DataTypeTok{Kernel}\AttributeTok{.print}\NormalTok{(}\StringTok{"times = "}\NormalTok{)}
|
|
652
|
+
\FunctionTok{puts} \OtherTok{@times}
|
|
653
|
+
\FunctionTok{puts}\NormalTok{(}\StringTok{"traj ="}\NormalTok{)}
|
|
654
|
+
\FunctionTok{puts} \OtherTok{@matrix}
|
|
655
|
+
\FunctionTok{puts}\NormalTok{(}\StringTok{"******* End Print (trajectories) ******* "}\NormalTok{)}
|
|
656
|
+
\ControlFlowTok{end}
|
|
657
|
+
|
|
658
|
+
\ControlFlowTok{end}
|
|
659
|
+
\end{Highlighting}
|
|
660
|
+
\end{Shaded}
|
|
661
|
+
|
|
662
|
+
\begin{Shaded}
|
|
663
|
+
\begin{Highlighting}[]
|
|
664
|
+
\OtherTok{@trajCochin}\AttributeTok{.print}
|
|
665
|
+
\end{Highlighting}
|
|
666
|
+
\end{Shaded}
|
|
667
|
+
|
|
668
|
+
\begin{verbatim}
|
|
669
|
+
## *** Class Trajectories, method Print ***
|
|
670
|
+
## times = 1
|
|
671
|
+
## 3
|
|
672
|
+
## 4
|
|
673
|
+
## 5
|
|
674
|
+
## traj =
|
|
675
|
+
## [,1] [,2] [,3] [,4]
|
|
676
|
+
## g2_v2114 15.0 15.1 15.2 15.2
|
|
677
|
+
## g2_v2115 16.0 15.9 16.0 16.4
|
|
678
|
+
## g2_v2116 15.2 NA 15.3 15.3
|
|
679
|
+
## g2_v2117 15.7 15.6 15.8 16.0
|
|
680
|
+
## ******* End Print (trajectories) *******
|
|
681
|
+
\end{verbatim}
|
|
682
|
+
|
|
683
|
+
For Cochin, the result is correct. For Saint-Anne, print will display
|
|
684
|
+
too much information. So we need a second method.
|
|
685
|
+
|
|
686
|
+
Show is the default R method used to show an object when its name is
|
|
687
|
+
written in the console. We thus define `show' by taking into account the
|
|
688
|
+
size of the object: if there are too many trajectories, `show' posts
|
|
689
|
+
only part of them.
|
|
690
|
+
|
|
691
|
+
Here is the R code for method `show':
|
|
692
|
+
|
|
693
|
+
\begin{verbatim}
|
|
694
|
+
> setMethod("show","Trajectories",
|
|
695
|
+
+ function(object){
|
|
696
|
+
+ cat("*** Class Trajectories, method Show *** \\n")
|
|
697
|
+
+ cat("* Times ="); print(object@times)
|
|
698
|
+
+ nrowShow <- min(10,nrow(object@traj))
|
|
699
|
+
+ ncolShow <- min(10,ncol(object@traj))
|
|
700
|
+
+ cat("* Traj (limited to a matrix 10x10) = \\n")
|
|
701
|
+
+ print(formatC(object@traj[1:nrowShow,1:ncolShow]),quote=FALSE)
|
|
702
|
+
+ cat("******* End Show (trajectories) ******* \\n")
|
|
703
|
+
+ }
|
|
704
|
+
+ )
|
|
705
|
+
\end{verbatim}
|
|
706
|
+
|
|
707
|
+
Now, let's write it with Galaaz. This time though, we will not rewrite
|
|
708
|
+
the whole Trajectories class, but just reopen it to add this specific
|
|
709
|
+
method. The next example has many interesting features of Galaaz, some
|
|
710
|
+
we have already seen, others will be described now:
|
|
711
|
+
|
|
712
|
+
\begin{itemize}
|
|
713
|
+
\item
|
|
714
|
+
As we have already seen, to call an R function one uses the R.
|
|
715
|
+
notation. There is however another way: when the first argument to the
|
|
716
|
+
R function is an R object such as a matrix, a list, a vector, etc. we
|
|
717
|
+
can use `.' notation to call the function. This makes the function
|
|
718
|
+
look like a method of the object. For instance, R.nrow(@matrix), can
|
|
719
|
+
be called by doing @matrix.nrow;
|
|
720
|
+
\item
|
|
721
|
+
In R, every number is converted to a vector and this can be done with
|
|
722
|
+
method R.i. Converting a vector with only one number back to a number
|
|
723
|
+
can be done with method `.gz'. So if @num is an R vector that holds a
|
|
724
|
+
number, then @num.gz is a number that can be used normally with Ruby
|
|
725
|
+
methods;
|
|
726
|
+
\item
|
|
727
|
+
R functions and Ruby methods can be used freely in Galaaz. We show
|
|
728
|
+
bellow two different ways of getting the minimum of a number, either
|
|
729
|
+
by calling R.min or by getting the minimum of an array, with the min
|
|
730
|
+
method;
|
|
731
|
+
\item
|
|
732
|
+
Galaaz allows for method `chaining'. Method chaining, also known as
|
|
733
|
+
named parameter idiom, is a common syntax for invoking multiple method
|
|
734
|
+
calls in object-oriented programming languages. Each method returns an
|
|
735
|
+
object, allowing the calls to be chained together in a single
|
|
736
|
+
statement without requiring variables to store the intermediate
|
|
737
|
+
results. For instance @matrix.nrow.gz, which returns the number of
|
|
738
|
+
rows of the matrix as a number;
|
|
739
|
+
\item
|
|
740
|
+
Ranges in Ruby are represented by (x..y), where x is the beginning of
|
|
741
|
+
the range and y its end. An R matrix can be indexed by range,
|
|
742
|
+
\href{mailto:object@traj}{\nolinkurl{object@traj}}{[}1:nrowShow,1:ncolShow{]},
|
|
743
|
+
the same result is obtained in Galaaz by indexing @matrix
|
|
744
|
+
{[}(1..nrow\_show), (1..ncol\_show){]}. Observe that this statement is
|
|
745
|
+
then chained with the format function and with the pp method to print
|
|
746
|
+
the matrix.
|
|
747
|
+
\end{itemize}
|
|
748
|
+
|
|
749
|
+
\begin{Shaded}
|
|
750
|
+
\begin{Highlighting}[]
|
|
751
|
+
\ControlFlowTok{class} \DataTypeTok{Trajectories}
|
|
752
|
+
|
|
753
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
754
|
+
\CommentTok{\#}
|
|
755
|
+
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
|
|
756
|
+
|
|
757
|
+
\ControlFlowTok{def}\NormalTok{ show}
|
|
758
|
+
\FunctionTok{puts}\NormalTok{(}\StringTok{"*** Class Trajectories, method Show *** "}\NormalTok{)}
|
|
759
|
+
\DataTypeTok{Kernel}\AttributeTok{.print}\NormalTok{(}\StringTok{"times = "}\NormalTok{)}
|
|
760
|
+
\FunctionTok{puts} \OtherTok{@times}
|
|
761
|
+
\NormalTok{ nrow\_show }\OperatorTok{=} \KeywordTok{[}\DecValTok{10}\NormalTok{, }\OtherTok{@matrix}\AttributeTok{.nrow} \OperatorTok{\textless{}\textless{}} \DecValTok{0}\KeywordTok{]}\AttributeTok{.min}
|
|
762
|
+
\NormalTok{ ncol\_show }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.min}\NormalTok{(}\DecValTok{10}\NormalTok{, }\OtherTok{@matrix}\AttributeTok{.ncol}\NormalTok{) }\OperatorTok{\textless{}\textless{}} \DecValTok{0}
|
|
763
|
+
\FunctionTok{puts}\NormalTok{(}\StringTok{"* Traj (limited to a matrix 10x10) = "}\NormalTok{)}
|
|
764
|
+
\FunctionTok{puts} \OtherTok{@matrix}\KeywordTok{[}\NormalTok{(}\DecValTok{1}\OperatorTok{..}\NormalTok{nrow\_show), (}\DecValTok{1}\OperatorTok{..}\NormalTok{ncol\_show)}\KeywordTok{]}\AttributeTok{.format}\NormalTok{(}\WarningTok{digits:} \DecValTok{2}\NormalTok{, }\WarningTok{nsmall:} \DecValTok{2}\NormalTok{)}
|
|
765
|
+
\FunctionTok{puts}\NormalTok{(}\StringTok{"******* End Show (trajectories) ******* "}\NormalTok{)}
|
|
766
|
+
\ControlFlowTok{end}
|
|
767
|
+
|
|
768
|
+
\ControlFlowTok{end}
|
|
769
|
+
\end{Highlighting}
|
|
770
|
+
\end{Shaded}
|
|
771
|
+
|
|
772
|
+
\begin{Shaded}
|
|
773
|
+
\begin{Highlighting}[]
|
|
774
|
+
\OtherTok{@trajStAnne}\AttributeTok{.show}
|
|
775
|
+
\end{Highlighting}
|
|
776
|
+
\end{Shaded}
|
|
777
|
+
|
|
778
|
+
\begin{verbatim}
|
|
779
|
+
## parse error
|
|
780
|
+
\end{verbatim}
|
|
781
|
+
|
|
782
|
+
\begin{verbatim}
|
|
783
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/new_bridge/session_client.rb:268:in 'eval_r'
|
|
784
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/new_bridge_adapter.rb:231:in 'eval_r_with_result'
|
|
785
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/rsupport.rb:359:in 'exec_function'
|
|
786
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/rsupport.rb:618:in 'process_missing_dispatch'
|
|
787
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/rsupport.rb:468:in 'process_missing'
|
|
788
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/robject.rb:404:in 'method_missing'
|
|
789
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:180:in 'show'
|
|
790
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:170:in 'exec_ruby'
|
|
791
|
+
## org/jruby/RubyKernel.java:1268:in 'eval'
|
|
792
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:169:in 'exec_ruby'
|
|
793
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:777:in 'block in initialize'
|
|
794
|
+
## org/jruby/RubyBasicObject.java:2695:in 'instance_eval'
|
|
795
|
+
## org/jruby/RubyBasicObject.java:2723:in 'instance_eval'
|
|
796
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:748:in 'block in initialize'
|
|
797
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/new_bridge_adapter.rb:358:in 'block in register_callback_proc_stub'
|
|
798
|
+
## /home/rbotafogo/desenv_linux/galaaz/lib/new_bridge/session_client.rb:413:in 'block in handle_call'
|
|
799
|
+
\end{verbatim}
|
|
800
|
+
|
|
801
|
+
Our show method has the same problem as SS4, i.e., if an empty
|
|
802
|
+
trajectories object is created and we try to `show' it, it will generate
|
|
803
|
+
an error. Let's see it:
|
|
804
|
+
|
|
805
|
+
\begin{Shaded}
|
|
806
|
+
\begin{Highlighting}[]
|
|
807
|
+
\OtherTok{@empty\_traj} \OperatorTok{=} \DataTypeTok{Trajectories}\AttributeTok{.new}
|
|
808
|
+
\end{Highlighting}
|
|
809
|
+
\end{Shaded}
|
|
810
|
+
|
|
811
|
+
\begin{Shaded}
|
|
812
|
+
\begin{Highlighting}[]
|
|
813
|
+
\OtherTok{@empty\_traj}\AttributeTok{.show}
|
|
814
|
+
\end{Highlighting}
|
|
815
|
+
\end{Shaded}
|
|
816
|
+
|
|
817
|
+
\begin{verbatim}
|
|
818
|
+
## undefined method 'nrow' for nil
|
|
819
|
+
\end{verbatim}
|
|
820
|
+
|
|
821
|
+
\end{document}
|