galaaz 2.1.7 → 2.1.8

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +63 -58
  4. data/blogs/galaaz_ggplot/galaaz_ggplot.log +59 -68
  5. data/blogs/galaaz_ggplot/galaaz_ggplot.md +91 -84
  6. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +125 -94
  7. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
  8. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
  9. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
  10. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
  11. data/blogs/gknit/gknit.Rmd +33 -28
  12. data/blogs/gknit/gknit.md +47 -42
  13. data/blogs/gknit/gknit.tex +1368 -0
  14. data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
  15. data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
  16. data/blogs/gknit/gknit_files/figure-latex/bubble-1.png +0 -0
  17. data/blogs/gknit/gknit_files/gknit_files/figure-latex/bubble-1.png +0 -0
  18. data/blogs/manual/manual.Rmd +129 -60
  19. data/blogs/manual/manual.log +289 -545
  20. data/blogs/manual/manual.md +551 -467
  21. data/blogs/manual/manual.tex +1059 -485
  22. data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
  23. data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
  24. data/blogs/manual/manual_files/figure-markdown_github/bubble-1.png +0 -0
  25. data/blogs/manual/manual_files/figure-markdown_github/diverging_bar.png +0 -0
  26. data/blogs/manual/manual_files/manual_files/figure-latex/bubble-1.png +0 -0
  27. data/blogs/nse_dplyr/nse_dplyr.Rmd +28 -7
  28. data/blogs/nse_dplyr/nse_dplyr.log +49 -153
  29. data/blogs/nse_dplyr/nse_dplyr.md +676 -705
  30. data/blogs/nse_dplyr/nse_dplyr.tex +1589 -0
  31. data/blogs/oh_my/oh_my.Rmd +193 -55
  32. data/blogs/oh_my/oh_my.log +265 -95
  33. data/blogs/oh_my/oh_my.md +236 -95
  34. data/blogs/oh_my/oh_my.tex +1976 -68
  35. data/blogs/ruby_plot/ruby_plot.Rmd +42 -34
  36. data/blogs/ruby_plot/ruby_plot.log +101 -99
  37. data/blogs/ruby_plot/ruby_plot.md +52 -46
  38. data/blogs/ruby_plot/ruby_plot.tex +134 -102
  39. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
  40. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
  41. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
  42. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
  43. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
  44. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
  45. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
  46. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
  47. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
  48. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
  49. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
  50. data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
  51. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  52. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  53. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  54. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  55. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  56. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  57. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  58. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  59. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  60. data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  61. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/dose_len.png +0 -0
  62. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  63. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  64. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  65. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  66. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  67. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  68. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  69. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  70. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  71. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  72. data/lib/galaaz/cli.rb +51 -10
  73. data/script/omarchy/README.md +1 -1
  74. data/script/omarchy/galaaz-guide.sh +1 -1
  75. data/sty/galaaz.sty +22 -0
  76. data/version.rb +1 -1
  77. metadata +19 -1
@@ -28,66 +28,66 @@ fontsize: 11pt
28
28
 
29
29
  # Introduction
30
30
 
31
- **Galaaz is R-on-Rails:** keep **GNU R** for statistics, graphics, and the CRAN /
32
- Bioconductor ecosystem, and use **Ruby** (with **Rails** when you need a web app) for
33
- everything R was never meant to own—HTTP, auth, databases, background jobs, HTML, APIs.
34
-
35
- The primary audience is the **R scientist** who already has models, dplyr/ggplot pipelines,
36
- and domain knowledge, and wants a **one-person path to production on the web**. Learning
37
- enough Ruby and Rails to ship an app is usually easier than hiring (or becoming) a dedicated
38
- web-and-stats dual specialist. Ruby developers gain full access to R libraries as a
39
- secondary benefit; the design priority is **R workflow first, web second**.
40
-
41
- Galaaz does **not** re-implement scientific libraries in Ruby. Ruby and R run in **separate
42
- processes**; the **Galaaz bridge** sends requests to standard **GNU R** and returns typed
43
- results. You keep calling familiar ideas from Ruby (`R.c(...)`, `R.library('ggplot2')`,
44
- `~R[:mtcars]`, dplyr-style chains) while Rails (or plain Ruby) owns the application shell.
45
-
46
- **Python** remains a strong competitor for end-to-end data science stacks (NumPy, pandas,
47
- SciPy, scikit-learn, Django/Flask). Galaaz’s bet is different: if your science already lives
48
- in **R**, do not rewrite it in Python to get a website—**put R on Rails**.
49
-
50
- Ruby is a dynamic, object-oriented language that became widely known through **Ruby on Rails**
51
- (RoR). It remains a practical choice for web applications and general-purpose scripting.
52
- Until Galaaz, Ruby lacked a tight, ecosystem-complete bridge to GNU R. Library wrapping
53
- (one gem per package) does not scale; Galaaz wraps **the R language**, so thousands of R
54
- packages are available without a new handcrafted wrapper for each one.
31
+ Galaaz is a system for tightly coupling Ruby and R. Ruby is a powerful language, with a large
32
+ community, a very large set of libraries and great for web development. However, it lacks
33
+ libraries for data science, statistics, scientific plotting and machine learning. On the
34
+ other hand, R is considered one of the most powerful languages for solving all of the above
35
+ problems. **Python** is a strong competitor: NumPy, pandas, SciPy, and scikit-learn are
36
+ widely used building blocks, and **PyPI** hosts many thousands of other packages for
37
+ numerical work, machine learning, and beyond.
38
+
39
+ With Galaaz we do not intend to re-implement any of the scientific libraries in R, we allow
40
+ for very tight coupling between the two languages to the point that the Ruby developer does
41
+ not need to know that there is an R engine running.
42
+
43
+ According to Wikipedia "Ruby is a dynamic, interpreted, reflective, object-oriented,
44
+ general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro
45
+ "Matz" Matsumoto in Japan." It reached high popularity with the development of Ruby on Rails
46
+ (RoR) by David Heinemeier Hansson. RoR is a web application framework first released
47
+ around 2005. It makes extensive use of Ruby's metaprogramming features. With RoR,
48
+ Ruby became very popular. According to [Ruby’s place in the TIOBE index](https://www.tiobe.com/tiobe-index/ruby/)
49
+ it peaked in popularity around 2008, then declined until 2015 when it started picking up again.
50
+ Ruby remains a significant language in web development and general-purpose scripting.
51
+
52
+ Python, a language similar to Ruby, ranks 4th in the index. Java, C and C++ take the
53
+ first three positions. Ruby is often criticized for its focus on web applications.
54
+ But Ruby can do [much more](https://github.com/markets/awesome-ruby) than just web applications.
55
+ Yet, for scientific computing, Ruby lags behind Python and R. Python offers Django and
56
+ similar frameworks for the web, plus NumPy, pandas, and a deep catalog of science and ML libraries.
57
+ R is a free software environment for statistical computing and graphics with thousands
58
+ of libraries for data analysis.
59
+
60
+ Until recently, there was no real perspective for Ruby to bridge this gap.
61
+ Implementing a complete scientific computing infrastructure would take too long.
55
62
 
56
63
  **Galaaz 2.0** supports **JRuby** and **CRuby** equally for the same NewBridge protocol.
57
64
  Pick the Ruby that fits your app: JRuby when you want real multithreading for web and I/O;
58
65
  CRuby when you prefer MRI. R remains the same **GNU R** you use interactively—including
59
- compiled extensions and Bioconductor. Earlier GraalVM / TruffleRuby / FastR experiments
60
- are no longer the focus.
61
-
62
- The bridge handles **communication and typing** between the two worlds. Large tables can use
63
- **Apache Arrow** in two shipped modes (described later): **Stage A** copies Ruby batches into an
64
- R-side Arrow table (`R::Arrow.from_ruby_batches`); **Stage B** writes an Arrow IPC file and only
65
- the **path** crosses NewBridge (`Galaaz::ArrowIpc` + `R::Arrow.open_ipc` / `write_ipc`). Shared-heap
66
- zero-copy is **Stage C** and is not shipped.
67
-
68
- ## R-on-Rails: the one-person app for R scientists
69
-
70
- If you already think in R, the usual web options are painful: Shiny for some apps, or a full
71
- rewrite in another stack. **R-on-Rails** means:
72
-
73
- 1. **Keep your science in R** — packages, formulas, plots, Bioconductor, the same engine as RStudio.
74
- 2. **Learn enough Ruby/Rails** — routes, controllers, views, jobs, auth—not a second statistics career.
75
- 3. **Call R from the app** Galaaz loads R behind the scenes; long jobs can complete asynchronously
76
- while Rails stays responsive (see later sections on the bridge, `R::Async`, and `R::Job`).
77
- 4. **Ship alone when you need to** one developer can own both the analysis and the product UI,
78
- without waiting for a separate “stats engineer” and “Rails engineer.”
79
-
80
- Typical shape:
81
-
82
- - Interactive exploration and reports: **gstudio**, **gknit** (R Markdown with Ruby chunks).
83
- - Product: a **Rails** (or Sinatra) app that calls `R.*` for the heavy statistical steps.
84
- - Scale for many users: more **R worker processes/containers** behind the app (R is single-threaded
85
- per process); the Ruby web tier scales separately (JRuby threads or a multi-process CRuby
86
- setup). Galaaz’s instance manager is the starting point for that pattern—not a rewrite of
87
- every algorithm à la enterprise ScaleR.
88
-
89
- Rubyists are welcome: the same bridge exposes CRAN to application code. The **intended** on-ramp,
90
- though, is **R scientist → small Rails app**, not “hire a stats team to teach Rails developers R.”
66
+ compiled extensions and Bioconductor. Ruby and R run in **separate processes**; the
67
+ **Galaaz bridge** sends requests to R and returns results to Ruby. From your point of view
68
+ you still write Ruby: `R.c(...)`, `R.library('ggplot2')`, `~R[:mtcars]`, and dplyr-style
69
+ chains on R objects. You do not need to learn R syntax to get a lot done, though reading R
70
+ documentation for individual packages remains useful.
71
+
72
+ Earlier experiments with Galaaz used Oracle’s **GraalVM** with TruffleRuby and FastR so that
73
+ Ruby and R could share one runtime. That path is no longer the focus: **standard GNU R**
74
+ gives full compatibility with the R package ecosystem (including compiled extensions and
75
+ Bioconductor) while either Ruby engine talks to R over NewBridge (JRuby for mature
76
+ multithreading on the application side; CRuby when you prefer MRI).
77
+
78
+ The bridge handles **communication and typing** between the two worlds; large tables can
79
+ also flow through **Apache Arrow** on the R side when you use the optional helpers described
80
+ later in this manual.
81
+
82
+ Library wrapping is a common way to bring features from one language into another.
83
+ To improve performance, Python often wraps more efficient C libraries. For the
84
+ Python developer, the existence of such C libraries is hidden. The problem with
85
+ library wrapping is that for any new library, there is the need to handcraft a new
86
+ wrapper.
87
+
88
+ Galaaz, instead of wrapping a single C or R library, wraps the whole R language
89
+ in Ruby. Doing so, all thousands of R libraries are available immediately
90
+ to Ruby developers without any new wrapping effort.
91
91
 
92
92
  ## What does Galaaz mean
93
93
 
@@ -131,27 +131,17 @@ JRuby (`bin/galaaz_jruby_env.inc.sh` / `lib/galaaz_jruby.rb`). **`bin/galaaz-jru
131
131
  <tbody>
132
132
  <tr>
133
133
  <td style="text-align:left;"> galaaz-bootstrap </td>
134
- <td style="text-align:left;"> WSL2 helper: Docker checks; optional TinyTeX or poppler for gKnit PDF. </td>
134
+ <td style="text-align:left;"> WSL2 helper: Docker checks; optional TinyTeX/poppler. </td>
135
135
  <td style="text-align:left;"> Yes* </td>
136
136
  </tr>
137
- <tr>
138
- <td style="text-align:left;"> galaaz-ruby </td>
139
- <td style="text-align:left;"> Selected Ruby (default: ruby on PATH) with repo lib/ on LOAD_PATH; JVM flags only on JRuby. </td>
140
- <td style="text-align:left;"> Yes </td>
141
- </tr>
142
137
  <tr>
143
138
  <td style="text-align:left;"> galaaz-jruby </td>
144
- <td style="text-align:left;"> Thin wrapper that forces JRuby (same flags as galaaz-ruby under JRuby). </td>
139
+ <td style="text-align:left;"> JRuby with repo lib/ on LOAD_PATH and JVM flags. </td>
145
140
  <td style="text-align:left;"> Yes </td>
146
141
  </tr>
147
- <tr>
148
- <td style="text-align:left;"> galaaz_ruby_env.inc.sh </td>
149
- <td style="text-align:left;"> Sourced by bash wrappers; sets GALAAZ_RUBY_BIN and optional JVM args. </td>
150
- <td style="text-align:left;"> Yes† </td>
151
- </tr>
152
142
  <tr>
153
143
  <td style="text-align:left;"> galaaz_jruby_env.inc.sh </td>
154
- <td style="text-align:left;"> Sourced when the interpreter is JRuby; sets GALAAZ_REQUIRED_JRUBY_J_ARGS. </td>
144
+ <td style="text-align:left;"> Sourced by bash wrappers; sets JRUBY_J_ARGS. </td>
155
145
  <td style="text-align:left;"> Yes† </td>
156
146
  </tr>
157
147
  <tr>
@@ -166,13 +156,11 @@ JRuby (`bin/galaaz_jruby_env.inc.sh` / `lib/galaaz_jruby.rb`). **`bin/galaaz-jru
166
156
 
167
157
  † Not run directly.
168
158
 
169
- **`galaaz-ruby` / `galaaz-jruby` examples** (from repo root):
159
+ **`galaaz-jruby` examples** (from repo root):
170
160
 
171
161
  ```text
172
- bin/galaaz-ruby my_script.rb
173
- GALAAZ_RUBY=jruby bin/galaaz-ruby my_script.rb
174
162
  bin/galaaz-jruby my_script.rb
175
- bin/galaaz-ruby -S rspec
163
+ bin/galaaz-jruby -S rspec
176
164
  ```
177
165
 
178
166
  ## Interactive use, examples, and Rake
@@ -188,17 +176,17 @@ bin/galaaz-ruby -S rspec
188
176
  <tbody>
189
177
  <tr>
190
178
  <td style="text-align:left;"> gstudio </td>
191
- <td style="text-align:left;"> IRB or Pry with Galaaz preloaded (ruby on PATH; JVM flags on JRuby). </td>
179
+ <td style="text-align:left;"> IRB or Pry with Galaaz preloaded (JRuby + JVM flags). </td>
192
180
  <td style="text-align:left;"> Yes </td>
193
181
  </tr>
194
182
  <tr>
195
183
  <td style="text-align:left;"> run_example </td>
196
- <td style="text-align:left;"> Run one Ruby file using the same Ruby/JVM setup as tests. </td>
184
+ <td style="text-align:left;"> Run one Ruby file using the same JRuby/JVM setup as tests. </td>
197
185
  <td style="text-align:left;"> Yes </td>
198
186
  </tr>
199
187
  <tr>
200
188
  <td style="text-align:left;"> galaaz </td>
201
- <td style="text-align:left;"> Forward arguments to rake (needs rake; same GALAAZ_RUBY as other launchers). </td>
189
+ <td style="text-align:left;"> Forward arguments to rake (needs rake; usually JRuby). </td>
202
190
  <td style="text-align:left;"> Yes </td>
203
191
  </tr>
204
192
  </tbody>
@@ -217,18 +205,18 @@ bin/galaaz-ruby -S rspec
217
205
  <tbody>
218
206
  <tr>
219
207
  <td style="text-align:left;"> gknit </td>
220
- <td style="text-align:left;"> Knit .Rmd via ruby on PATH (JRuby or CRuby) and R Markdown render. </td>
208
+ <td style="text-align:left;"> Knit .Rmd via JRuby and R Markdown render. </td>
221
209
  <td style="text-align:left;"> Yes </td>
222
210
  </tr>
223
211
  <tr>
224
212
  <td style="text-align:left;"> gknit-draft </td>
225
- <td style="text-align:left;"> Drafts from rticles-style templates; wrapper still uses legacy polyglot ruby. </td>
213
+ <td style="text-align:left;"> Drafts from rticles templates; legacy polyglot wrapper. </td>
226
214
  <td style="text-align:left;"> Legacy </td>
227
215
  </tr>
228
216
  <tr>
229
217
  <td style="text-align:left;"> gknit-draft.rb </td>
230
- <td style="text-align:left;"> Ruby entry: GKnit.draft (use with galaaz-ruby + LOAD_PATH). </td>
231
- <td style="text-align:left;"> Yes </td>
218
+ <td style="text-align:left;"> Ruby entry: GKnit.draft (use with JRuby + LOAD_PATH). </td>
219
+ <td style="text-align:left;"> JRuby </td>
232
220
  </tr>
233
221
  <tr>
234
222
  <td style="text-align:left;"> gknit_Rscript </td>
@@ -260,7 +248,7 @@ Prefer **`galaaz-jruby`** for **`gknit-draft`** workflows until that wrapper mat
260
248
  </tr>
261
249
  <tr>
262
250
  <td style="text-align:left;"> run_all_rspec </td>
263
- <td style="text-align:left;"> Compile ext/new_bridge; run specs/ and new_bridge_specs/ together. </td>
251
+ <td style="text-align:left;"> Compile ext/new_bridge; run specs/ and new_bridge_specs/. </td>
264
252
  <td style="text-align:left;"> Yes </td>
265
253
  </tr>
266
254
  <tr>
@@ -294,7 +282,7 @@ Prefer **`galaaz-jruby`** for **`gknit-draft`** workflows until that wrapper mat
294
282
  <tbody>
295
283
  <tr>
296
284
  <td style="text-align:left;"> grun </td>
297
- <td style="text-align:left;"> Graal-era launcher: polyglot ruby with --jvm. Use galaaz-jruby -S instead. </td>
285
+ <td style="text-align:left;"> Graal-era launcher: polyglot ruby --jvm; prefer galaaz-jruby. </td>
298
286
  <td style="text-align:left;"> No </td>
299
287
  </tr>
300
288
  <tr>
@@ -337,8 +325,9 @@ The supported install is **`gem install` + compile the gatekeeper**. You do not
337
325
  4. Compile the native gatekeeper from the installed gem:
338
326
 
339
327
  ```
340
- gem_dir="$(ruby -e "puts Gem::Specification.find_by_name('galaaz').full_gem_path")"
341
- # under JRuby: gem_dir="$(jruby -e "puts Gem::Specification.find_by_name('galaaz').full_gem_path")"
328
+ gem_dir="$(ruby -e \
329
+ "puts Gem::Specification.find_by_name('galaaz').full_gem_path")"
330
+ # under JRuby: use jruby -e instead of ruby -e
342
331
  make -C "${gem_dir}/ext/new_bridge" all
343
332
  ```
344
333
 
@@ -359,9 +348,10 @@ A **table of all `bin/` scripts** (bootstrap, Ruby launcher, gstudio, gknit, tes
359
348
  wrapper that forces JRuby.
360
349
 
361
350
  A **gstudio** try image with Galaaz already installed is available for both engines:
362
- **JRuby** — `docker run --rm -it ghcr.io/rbotafogo/galaaz-try:gstudio` (or
363
- `./docker/try-gstudio/run.sh` from a checkout); **CRuby** —
364
- `docker run --rm -it ghcr.io/rbotafogo/galaaz-try:cruby` (or `./docker/try-cruby/run.sh`).
351
+ **JRuby** — `docker run --rm -it ghcr.io/rbotafogo/galaaz-try:gstudio`
352
+ (or `./docker/try-gstudio/run.sh` from a checkout); **CRuby** —
353
+ `docker run --rm -it ghcr.io/rbotafogo/galaaz-try:cruby`
354
+ (or `./docker/try-cruby/run.sh`).
365
355
  Maintainers can prove a RubyGems install on a throwaway Ubuntu machine (no repo inside
366
356
  the container) with `./docker/cold-install/run.sh published-specs` (JRuby) or
367
357
  `./docker/cold-install-cruby/run.sh published-specs` (CRuby).
@@ -401,18 +391,40 @@ WSL integration is enabled for the distro where Galaaz is installed.
401
391
  vec = R.c(1, 2, 3, 4)
402
392
  puts vec
403
393
 
404
- # R.foo(...) calls an R *function*. Datasets are objects — fetch with ~:
394
+ # R.foo(...) calls an R *function*. Datasets are objects — fetch with
395
+ # ~:
405
396
  df = ~R[:mtcars]
406
397
  puts R.summary(df)
407
398
  ```
408
399
 
409
400
  ```
410
401
  ## [1] 1 2 3 4
402
+ ## mpg cyl disp hp
403
+ ## Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0
404
+ ## 1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5
405
+ ## Median :19.20 Median :6.000 Median :196.3 Median :123.0
406
+ ## Mean :20.09 Mean :6.188 Mean :230.7 Mean :146.7
407
+ ## 3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0
408
+ ## Max. :33.90 Max. :8.000 Max. :472.0 Max. :335.0
409
+ ## drat wt qsec vs
410
+ ## Min. :2.760 Min. :1.513 Min. :14.50 Min. :0.0000
411
+ ## 1st Qu.:3.080 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:0.0000
412
+ ## Median :3.695 Median :3.325 Median :17.71 Median :0.0000
413
+ ## Mean :3.597 Mean :3.217 Mean :17.85 Mean :0.4375
414
+ ## 3rd Qu.:3.920 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:1.0000
415
+ ## Max. :4.930 Max. :5.424 Max. :22.90 Max. :1.0000
416
+ ## am gear carb
417
+ ## Min. :0.0000 Min. :3.000 Min. :1.000
418
+ ## 1st Qu.:0.0000 1st Qu.:3.000 1st Qu.:2.000
419
+ ## Median :0.0000 Median :4.000 Median :2.000
420
+ ## Mean :0.4062 Mean :3.688 Mean :2.812
421
+ ## 3rd Qu.:1.0000 3rd Qu.:4.000 3rd Qu.:4.000
422
+ ## Max. :1.0000 Max. :5.000 Max. :8.000
411
423
  ```
412
424
 
413
425
  (`R.mtcars` is wrong: it becomes `mtcars()` in R and fails. With
414
426
  `using Galaaz::SymbolDSL`, the short form `~:mtcars` also works.)
415
-
427
+
416
428
  * Run all specs
417
429
 
418
430
  > galaaz specs:all
@@ -457,15 +469,13 @@ A practical pattern is:
457
469
 
458
470
  1. Use threads (or a connection pool) to read from **multiple databases or shards** in parallel.
459
471
  2. Merge the rows in Ruby under a `Mutex` if you collect into one structure.
460
- 3. Hand the merged table to R **once**: **`R::Arrow.from_ruby_batches`** (Stage A: copy into R) or
461
- **`Galaaz::ArrowIpc.write` / `write_batches`** then **`R::Arrow.open_ipc`** (Stage B: IPC file;
462
- only the path crosses the bridge). Then run dplyr in R.
472
+ 3. Hand the merged table to R **once** (for example with `R::Arrow.from_ruby_batches` and dplyr,
473
+ or by building a data frame) so heavy statistics run in R with fewer bridge round-trips.
463
474
 
464
475
  A runnable sketch lives in
465
476
  `examples/multithread_shards_to_r/shards_to_r.rb` (simulated shard queries; swap in your DB
466
477
  driver). For concurrency tests on the bridge itself, see `specs/bridge_concurrent_spec.rb` and
467
- `specs/arrow_from_ruby_batches_spec.rb`. Stage B IPC tests: `specs/arrow_ipc_handoff_spec.rb`,
468
- `specs/arrow_ipc_export_spec.rb`.
478
+ `specs/arrow_from_ruby_batches_spec.rb`.
469
479
 
470
480
  ## Long-running R calls and a completion block
471
481
 
@@ -502,9 +512,11 @@ completion = Queue.new
502
512
 
503
513
  R.eval_r_async('({ Sys.sleep(0.3); 42L })', timeout: nil) do |result|
504
514
  if result.ok?
505
- puts "[completion] R finished; eval_r-style value: #{result.value.inspect}"
515
+ puts "[completion] R finished; value: " +
516
+ "#{result.value.inspect}"
506
517
  else
507
- puts "[completion] R/bridge error: #{result.error.class}: #{result.error.message}"
518
+ puts "[completion] R/bridge error: " +
519
+ "#{result.error.class}: #{result.error.message}"
508
520
  end
509
521
  completion.push(:done)
510
522
  end
@@ -522,7 +534,7 @@ puts "[main] R completion has run; exiting."
522
534
  ## [main] other Ruby work step 1
523
535
  ## [main] other Ruby work step 2
524
536
  ## [main] other Ruby work step 3
525
- ## [completion] R finished; eval_r-style value: "[1] 42"
537
+ ## [completion] R finished; value: "[1] 42"
526
538
  ## [main] R completion has run; exiting.
527
539
  ```
528
540
 
@@ -550,8 +562,10 @@ finishes** (default: no wall-clock limit). Optional limit: `GALAAZ_INSTALL_TIMEO
550
562
  `make`/`gcc` cannot OOM the shell. Stale `00LOCK-*` dirs are cleared before the next install.
551
563
  Only one install runs at a time (`install.lock`).
552
564
 
565
+
553
566
  ``` ruby
554
- # May take a long time the first time (e.g. caret); the bridge is not used for compile.
567
+ # May take a long time the first time (e.g. caret); the bridge is not
568
+ # used for compile.
555
569
  R.install_and_loads 'caret'
556
570
  ```
557
571
 
@@ -560,24 +574,33 @@ R.install_and_loads 'caret'
560
574
  Prefer the **block** form (like `File.open`): await the child, yield the job, return the
561
575
  block’s value. Without a block, the methods still await by default and return the `Job`.
562
576
 
577
+
563
578
  ``` ruby
564
- coef = R::Job.eval(<<~R) { |job| job.load_rds }
565
- fit <- lm(mpg ~ wt, data = mtcars)
566
- saveRDS(unname(coef(fit)), result_path)
567
- R
568
- puts coef
579
+ begin
580
+ coef = R::Job.eval(<<~R) { |job| job.load_rds }
581
+ fit <- lm(mpg ~ wt, data = mtcars)
582
+ saveRDS(unname(coef(fit)), result_path)
583
+ R
584
+ puts coef
585
+ rescue => e
586
+ puts e.class.to_s
587
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
588
+ end
569
589
  ```
570
590
 
571
591
  ```
572
592
  ## [1] 37.285126 -5.344472
573
593
  ```
574
594
 
595
+
575
596
  ``` ruby
576
- # Without a block: awaits (wait: true is the default) and returns the Job
597
+ # Without a block: awaits (wait: true is the default) and returns the
598
+ # Job
577
599
  job = R::Job.eval(code)
578
600
  job = R::Job.eval(code, wait: false) # start only; call job.wait later
579
601
 
580
- # Script file; trailing args → commandArgs(trailingOnly=TRUE) in the child
602
+ # Script file; trailing args → commandArgs(trailingOnly=TRUE) in the
603
+ # child
581
604
  res = R::Job.script('train.R', '5') { |job| job.load_rds }
582
605
  ```
583
606
 
@@ -600,10 +623,7 @@ app. The baseline we used in WSL aimed at:
600
623
 
601
624
  1. Rails boots under **JRuby or CRuby** (same bridge; see Installation).
602
625
  2. Galaaz is loaded from a local checkout (before publishing to RubyGems).
603
- 3. A request path can execute **`R.eval(...)`** (or `R.*`) and return a result.
604
-
605
- You keep statistical work in R; Rails owns HTTP, sessions, and HTML. See **R-on-Rails: the
606
- one-person app for R scientists** in the Introduction for the product framing.
626
+ 3. A request path can execute **`R.eval(...)`** and return a result.
607
627
 
608
628
  ### 1) Create the app with Ruby-friendly options
609
629
 
@@ -612,7 +632,8 @@ extension paths on JRuby, or deployment extras you do not need). A minimal app a
612
632
 
613
633
  ```bash
614
634
  cd /home/rbotafogo/desenv_linux
615
- jruby -S rails new hedi --skip-git --minimal --skip-kamal --skip-solid --skip-active-record
635
+ jruby -S rails new hedi --skip-git --minimal \
636
+ --skip-kamal --skip-solid --skip-active-record
616
637
  ```
617
638
 
618
639
  Then install gems:
@@ -650,7 +671,8 @@ A direct smoke test from Rails runner:
650
671
 
651
672
  ```bash
652
673
  cd /home/rbotafogo/desenv_linux/hedi
653
- jruby -S bundle exec rails runner "puts R.eval('sum(c(1,2,3,4,5))').inspect"
674
+ jruby -S bundle exec rails runner \
675
+ "puts R.eval('sum(c(1,2,3,4,5))').inspect"
654
676
  ```
655
677
 
656
678
  Expected output:
@@ -718,39 +740,72 @@ puts ~R[:mtcars]
718
740
  ```
719
741
 
720
742
  ```
721
- ## mpg cyl disp hp drat wt qsec vs am gear carb
722
- ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
723
- ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
724
- ## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
725
- ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
726
- ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
727
- ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
728
- ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
729
- ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
730
- ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
731
- ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
732
- ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
733
- ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
734
- ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3
735
- ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3
736
- ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4
737
- ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
738
- ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
739
- ## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
740
- ## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
741
- ## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
742
- ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
743
- ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
744
- ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
745
- ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
746
- ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
747
- ## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
748
- ## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
749
- ## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
750
- ## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
751
- ## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
752
- ## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8
753
- ## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
743
+ ## mpg cyl disp hp drat wt qsec vs am gear
744
+ ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4
745
+ ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4
746
+ ## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4
747
+ ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3
748
+ ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3
749
+ ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3
750
+ ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3
751
+ ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4
752
+ ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4
753
+ ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4
754
+ ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4
755
+ ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3
756
+ ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3
757
+ ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3
758
+ ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3
759
+ ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3
760
+ ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3
761
+ ## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4
762
+ ## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4
763
+ ## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4
764
+ ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3
765
+ ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3
766
+ ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3
767
+ ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3
768
+ ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3
769
+ ## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4
770
+ ## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5
771
+ ## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5
772
+ ## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5
773
+ ## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5
774
+ ## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5
775
+ ## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4
776
+ ## carb
777
+ ## Mazda RX4 4
778
+ ## Mazda RX4 Wag 4
779
+ ## Datsun 710 1
780
+ ## Hornet 4 Drive 1
781
+ ## Hornet Sportabout 2
782
+ ## Valiant 1
783
+ ## Duster 360 4
784
+ ## Merc 240D 2
785
+ ## Merc 230 2
786
+ ## Merc 280 4
787
+ ## Merc 280C 4
788
+ ## Merc 450SE 3
789
+ ## Merc 450SL 3
790
+ ## Merc 450SLC 3
791
+ ## Cadillac Fleetwood 4
792
+ ## Lincoln Continental 4
793
+ ## Chrysler Imperial 4
794
+ ## Fiat 128 1
795
+ ## Honda Civic 2
796
+ ## Toyota Corolla 1
797
+ ## Toyota Corona 1
798
+ ## Dodge Challenger 2
799
+ ## AMC Javelin 2
800
+ ## Camaro Z28 4
801
+ ## Pontiac Firebird 2
802
+ ## Fiat X1-9 1
803
+ ## Porsche 914-2 2
804
+ ## Lotus Europa 2
805
+ ## Ford Pantera L 4
806
+ ## Ferrari Dino 6
807
+ ## Maserati Bora 8
808
+ ## Volvo 142E 2
754
809
  ```
755
810
 
756
811
  ## Scoped symbols and lexical scoping
@@ -896,9 +951,9 @@ puts vec.map { |x| x + 2 }
896
951
 
897
952
  This manual has been formatted using gKnit. gKnit uses knitr and R Markdown to knit
898
953
  a document in Ruby or R and output it in any of the available formats for R Markdown.
899
- gKnit runs with **JRuby or CRuby**, **GNU R**, and Galaaz. In gKnit, Ruby variables are persisted between
900
- chunks, making it an ideal solution for literate programming. Also, since it is based
901
- on Galaaz, Ruby chunks can have access to R variables and combining Ruby with R in one
954
+ gKnit runs with **JRuby or CRuby**, **GNU R**, and Galaaz. In gKnit, Ruby variables are persisted between
955
+ chunks, making it an ideal solution for literate programming. Also, since it is based
956
+ on Galaaz, Ruby chunks can have access to R variables and combining Ruby with R in one
902
957
  document is natural.
903
958
 
904
959
  The idea of "literate programming" was first introduced by Donald Knuth in the
@@ -1251,7 +1306,9 @@ a linear regression line (method = "lm") for every manufacturer.
1251
1306
  library(ggplot2)
1252
1307
  data(mpg, package="ggplot2")
1253
1308
 
1254
- mpg_select <- mpg[mpg$manufacturer %in% c("audi", "ford", "honda", "hyundai"), ]
1309
+ mpg_select <- mpg[
1310
+ mpg$manufacturer %in% c("audi", "ford", "honda", "hyundai"),
1311
+ ]
1255
1312
 
1256
1313
  # Scatterplot
1257
1314
  theme_set(theme_bw()) # pre-set the bw theme.
@@ -1334,7 +1391,8 @@ with the 'rb' engine. The following chunk specification will
1334
1391
  create and inline Ruby text:
1335
1392
 
1336
1393
  ````
1337
- This is some text with inline Ruby accessing variable 'b' which has value:
1394
+ This is some text with inline Ruby accessing
1395
+ variable 'b' which has value:
1338
1396
  ```{rb puts b}
1339
1397
  ```
1340
1398
  and is followed by some other text!
@@ -2199,14 +2257,16 @@ templates for the following journals with the respective template name:
2199
2257
  In order to create a document with one of those templates, use the following command:
2200
2258
 
2201
2259
  ```
2202
- gknit-draft --filename <my_document> --template <template> --package <package>
2203
- --create_dir
2260
+ gknit-draft --filename <my_document> \
2261
+ --template <template> --package <package> \
2262
+ --create_dir
2204
2263
  ```
2205
2264
  So, in order to create a template for writing an R Journal, use:
2206
2265
 
2207
2266
  ```
2208
- gknit-draft --filename my_r_article --template rjournal_article --package rticles
2209
- --create_dir
2267
+ gknit-draft --filename my_r_article \
2268
+ --template rjournal_article --package rticles \
2269
+ --create_dir
2210
2270
  ```
2211
2271
 
2212
2272
  # Accessing R variables
@@ -2739,7 +2799,10 @@ data frame is 'data.frame', in Galaaz we use 'data\_\_frame'.
2739
2799
 
2740
2800
 
2741
2801
  ``` ruby
2742
- df = R.data__frame(typeof: vec.typeof, mode: vec.mode, storage__mode: vec.storage__mode)
2802
+ df = R.data__frame(
2803
+ typeof: vec.typeof,
2804
+ mode: vec.mode,
2805
+ storage__mode: vec.storage__mode)
2743
2806
  puts df
2744
2807
  ```
2745
2808
 
@@ -2765,7 +2828,10 @@ puts vec
2765
2828
 
2766
2829
 
2767
2830
  ``` ruby
2768
- df = R.data__frame(typeof: vec.typeof, mode: vec.mode, storage__mode: vec.storage__mode)
2831
+ df = R.data__frame(
2832
+ typeof: vec.typeof,
2833
+ mode: vec.mode,
2834
+ storage__mode: vec.storage__mode)
2769
2835
  outputs df.kable.kable_styling
2770
2836
  ```
2771
2837
 
@@ -2802,14 +2868,14 @@ vec = R.c(1, hello, 5)
2802
2868
 
2803
2869
  ```
2804
2870
  ## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:170:in 'exec_ruby'
2805
- ## org/jruby/RubyKernel.java:1268:in 'eval'
2871
+ ## org/jruby/RubyKernel.java:1459:in 'eval'
2806
2872
  ## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:169:in 'exec_ruby'
2807
2873
  ## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:777:in 'block in initialize'
2808
- ## org/jruby/RubyBasicObject.java:2695:in 'instance_eval'
2809
- ## org/jruby/RubyBasicObject.java:2723:in 'instance_eval'
2874
+ ## org/jruby/RubyBasicObject.java:2713:in 'instance_eval'
2875
+ ## org/jruby/RubyBasicObject.java:2741:in 'instance_eval'
2810
2876
  ## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:748:in 'block in initialize'
2811
- ## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/new_bridge_adapter.rb:358:in 'block in register_callback_proc_stub'
2812
- ## /home/rbotafogo/desenv_linux/galaaz/lib/new_bridge/session_client.rb:413:in 'block in handle_call'
2877
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/new_bridge_adapter.rb:371:in 'block in register_callback_proc_stub'
2878
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/new_bridge/session_client.rb:458:in 'block in handle_call'
2813
2879
  ```
2814
2880
 
2815
2881
  Here is a vector with logical values
@@ -3253,9 +3319,9 @@ puts (~R[:mtcars])[['mpg']]
3253
3319
  ```
3254
3320
 
3255
3321
  ```
3256
- ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
3257
- ## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
3258
- ## [31] 15.0 21.4
3322
+ ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3
3323
+ ## [14] 15.2 10.4 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3
3324
+ ## [27] 26.0 30.4 15.8 19.7 15.0 21.4
3259
3325
  ```
3260
3326
 
3261
3327
  A data frame column can also be accessed as if it were an instance variable of the data frame:
@@ -3266,9 +3332,9 @@ puts (~R[:mtcars]).mpg
3266
3332
  ```
3267
3333
 
3268
3334
  ```
3269
- ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
3270
- ## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
3271
- ## [31] 15.0 21.4
3335
+ ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3
3336
+ ## [14] 15.2 10.4 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3
3337
+ ## [27] 26.0 30.4 15.8 19.7 15.0 21.4
3272
3338
  ```
3273
3339
 
3274
3340
  Slicing a data frame can be done by indexing it with a vector (we use 'head' to reduce the
@@ -3311,9 +3377,9 @@ puts automatic
3311
3377
  ```
3312
3378
 
3313
3379
  ```
3314
- ## [1] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
3315
- ## [13] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE
3316
- ## [25] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
3380
+ ## [1] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
3381
+ ## [12] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE
3382
+ ## [23] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
3317
3383
  ```
3318
3384
 
3319
3385
  Using this logical vector, the data frame is indexed, returning a new data frame in
@@ -3326,26 +3392,46 @@ puts (~R[:mtcars])[automatic, :all]
3326
3392
  ```
3327
3393
 
3328
3394
  ```
3329
- ## mpg cyl disp hp drat wt qsec vs am gear carb
3330
- ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
3331
- ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
3332
- ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
3333
- ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
3334
- ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
3335
- ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
3336
- ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
3337
- ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
3338
- ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
3339
- ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3
3340
- ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3
3341
- ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4
3342
- ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
3343
- ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
3344
- ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
3345
- ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
3346
- ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
3347
- ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
3348
- ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
3395
+ ## mpg cyl disp hp drat wt qsec vs am gear
3396
+ ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3
3397
+ ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3
3398
+ ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3
3399
+ ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3
3400
+ ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4
3401
+ ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4
3402
+ ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4
3403
+ ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4
3404
+ ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3
3405
+ ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3
3406
+ ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3
3407
+ ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3
3408
+ ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3
3409
+ ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3
3410
+ ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3
3411
+ ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3
3412
+ ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3
3413
+ ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3
3414
+ ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3
3415
+ ## carb
3416
+ ## Hornet 4 Drive 1
3417
+ ## Hornet Sportabout 2
3418
+ ## Valiant 1
3419
+ ## Duster 360 4
3420
+ ## Merc 240D 2
3421
+ ## Merc 230 2
3422
+ ## Merc 280 4
3423
+ ## Merc 280C 4
3424
+ ## Merc 450SE 3
3425
+ ## Merc 450SL 3
3426
+ ## Merc 450SLC 3
3427
+ ## Cadillac Fleetwood 4
3428
+ ## Lincoln Continental 4
3429
+ ## Chrysler Imperial 4
3430
+ ## Toyota Corona 1
3431
+ ## Dodge Challenger 2
3432
+ ## AMC Javelin 2
3433
+ ## Camaro Z28 4
3434
+ ## Pontiac Firebird 2
3349
3435
  ```
3350
3436
 
3351
3437
  # Writing Expressions in Galaaz
@@ -3550,17 +3636,18 @@ puts flights.head
3550
3636
 
3551
3637
  ```
3552
3638
  ## # A tibble: 6 × 19
3553
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3554
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3555
- ## 1 2013 1 1 517 515 2 830 819
3556
- ## 2 2013 1 1 533 529 4 850 830
3557
- ## 3 2013 1 1 542 540 2 923 850
3558
- ## 4 2013 1 1 544 545 -1 1004 1022
3559
- ## 5 2013 1 1 554 600 -6 812 837
3560
- ## 6 2013 1 1 554 558 -4 740 728
3561
- ## # ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3562
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3563
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3639
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3640
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3641
+ ## 1 2013 1 1 517 515 2 830
3642
+ ## 2 2013 1 1 533 529 4 850
3643
+ ## 3 2013 1 1 542 540 2 923
3644
+ ## 4 2013 1 1 544 545 -1 1004
3645
+ ## 5 2013 1 1 554 600 -6 812
3646
+ ## 6 2013 1 1 554 558 -4 740
3647
+ ## # ℹ 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3648
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3649
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3650
+ ## # minute <dbl>, time_hour <dttm>
3564
3651
  ```
3565
3652
 
3566
3653
  ## Filtering rows with Filter
@@ -3575,17 +3662,18 @@ puts flights.filter((R[:month].eq 1), (R[:day].eq 1)).head
3575
3662
 
3576
3663
  ```
3577
3664
  ## # A tibble: 6 × 19
3578
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3579
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3580
- ## 1 2013 1 1 517 515 2 830 819
3581
- ## 2 2013 1 1 533 529 4 850 830
3582
- ## 3 2013 1 1 542 540 2 923 850
3583
- ## 4 2013 1 1 544 545 -1 1004 1022
3584
- ## 5 2013 1 1 554 600 -6 812 837
3585
- ## 6 2013 1 1 554 558 -4 740 728
3586
- ## # ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3587
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3588
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3665
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3666
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3667
+ ## 1 2013 1 1 517 515 2 830
3668
+ ## 2 2013 1 1 533 529 4 850
3669
+ ## 3 2013 1 1 542 540 2 923
3670
+ ## 4 2013 1 1 544 545 -1 1004
3671
+ ## 5 2013 1 1 554 600 -6 812
3672
+ ## 6 2013 1 1 554 558 -4 740
3673
+ ## # ℹ 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3674
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3675
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3676
+ ## # minute <dbl>, time_hour <dttm>
3589
3677
  ```
3590
3678
 
3591
3679
  ## Logical Operators
@@ -3599,17 +3687,18 @@ puts flights.filter((R[:month].eq 11) | (R[:month].eq 12)).head
3599
3687
 
3600
3688
  ```
3601
3689
  ## # A tibble: 6 × 19
3602
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3603
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3604
- ## 1 2013 11 1 5 2359 6 352 345
3605
- ## 2 2013 11 1 35 2250 105 123 2356
3606
- ## 3 2013 11 1 455 500 -5 641 651
3607
- ## 4 2013 11 1 539 545 -6 856 827
3608
- ## 5 2013 11 1 542 545 -3 831 855
3609
- ## 6 2013 11 1 549 600 -11 912 923
3610
- ## # ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3611
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3612
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3690
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3691
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3692
+ ## 1 2013 11 1 5 2359 6 352
3693
+ ## 2 2013 11 1 35 2250 105 123
3694
+ ## 3 2013 11 1 455 500 -5 641
3695
+ ## 4 2013 11 1 539 545 -6 856
3696
+ ## 5 2013 11 1 542 545 -3 831
3697
+ ## 6 2013 11 1 549 600 -11 912
3698
+ ## # ℹ 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3699
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3700
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3701
+ ## # minute <dbl>, time_hour <dttm>
3613
3702
  ```
3614
3703
 
3615
3704
  The same as above, but using the 'in' operator. In R, it is possible to define many operators
@@ -3624,17 +3713,18 @@ puts flights.filter(R[:month]._ :in, R.c(11, 12)).head
3624
3713
 
3625
3714
  ```
3626
3715
  ## # A tibble: 6 × 19
3627
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3628
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3629
- ## 1 2013 11 1 5 2359 6 352 345
3630
- ## 2 2013 11 1 35 2250 105 123 2356
3631
- ## 3 2013 11 1 455 500 -5 641 651
3632
- ## 4 2013 11 1 539 545 -6 856 827
3633
- ## 5 2013 11 1 542 545 -3 831 855
3634
- ## 6 2013 11 1 549 600 -11 912 923
3635
- ## # ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3636
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3637
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3716
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3717
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3718
+ ## 1 2013 11 1 5 2359 6 352
3719
+ ## 2 2013 11 1 35 2250 105 123
3720
+ ## 3 2013 11 1 455 500 -5 641
3721
+ ## 4 2013 11 1 539 545 -6 856
3722
+ ## 5 2013 11 1 542 545 -3 831
3723
+ ## 6 2013 11 1 549 600 -11 912
3724
+ ## # ℹ 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3725
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3726
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3727
+ ## # minute <dbl>, time_hour <dttm>
3638
3728
  ```
3639
3729
 
3640
3730
  ## Filtering with NA (Not Available)
@@ -3700,17 +3790,18 @@ puts flights.arrange(:year, :month, :day).head
3700
3790
 
3701
3791
  ```
3702
3792
  ## # A tibble: 6 × 19
3703
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3704
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3705
- ## 1 2013 1 1 517 515 2 830 819
3706
- ## 2 2013 1 1 533 529 4 850 830
3707
- ## 3 2013 1 1 542 540 2 923 850
3708
- ## 4 2013 1 1 544 545 -1 1004 1022
3709
- ## 5 2013 1 1 554 600 -6 812 837
3710
- ## 6 2013 1 1 554 558 -4 740 728
3711
- ## # ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3712
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3713
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3793
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3794
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3795
+ ## 1 2013 1 1 517 515 2 830
3796
+ ## 2 2013 1 1 533 529 4 850
3797
+ ## 3 2013 1 1 542 540 2 923
3798
+ ## 4 2013 1 1 544 545 -1 1004
3799
+ ## 5 2013 1 1 554 600 -6 812
3800
+ ## 6 2013 1 1 554 558 -4 740
3801
+ ## # ℹ 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3802
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3803
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3804
+ ## # minute <dbl>, time_hour <dttm>
3714
3805
  ```
3715
3806
 
3716
3807
  To arrange in descending order, use function 'desc'
@@ -3722,17 +3813,18 @@ puts flights.arrange(R[:dep_delay].desc).head
3722
3813
 
3723
3814
  ```
3724
3815
  ## # A tibble: 6 × 19
3725
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3726
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3727
- ## 1 2013 1 9 641 900 1301 1242 1530
3728
- ## 2 2013 6 15 1432 1935 1137 1607 2120
3729
- ## 3 2013 1 10 1121 1635 1126 1239 1810
3730
- ## 4 2013 9 20 1139 1845 1014 1457 2210
3731
- ## 5 2013 7 22 845 1600 1005 1044 1815
3732
- ## 6 2013 4 10 1100 1900 960 1342 2211
3733
- ## # ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3734
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3735
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3816
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3817
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3818
+ ## 1 2013 1 9 641 900 1301 1242
3819
+ ## 2 2013 6 15 1432 1935 1137 1607
3820
+ ## 3 2013 1 10 1121 1635 1126 1239
3821
+ ## 4 2013 9 20 1139 1845 1014 1457
3822
+ ## 5 2013 7 22 845 1600 1005 1044
3823
+ ## 6 2013 4 10 1100 1900 960 1342
3824
+ ## # ℹ 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3825
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3826
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3827
+ ## # minute <dbl>, time_hour <dttm>
3736
3828
  ```
3737
3829
 
3738
3830
  ## Selecting columns
@@ -3814,17 +3906,18 @@ puts flights.select(:year, :month, :day, E.everything).head
3814
3906
 
3815
3907
  ```
3816
3908
  ## # A tibble: 6 × 19
3817
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3818
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3819
- ## 1 2013 1 1 517 515 2 830 819
3820
- ## 2 2013 1 1 533 529 4 850 830
3821
- ## 3 2013 1 1 542 540 2 923 850
3822
- ## 4 2013 1 1 544 545 -1 1004 1022
3823
- ## 5 2013 1 1 554 600 -6 812 837
3824
- ## 6 2013 1 1 554 558 -4 740 728
3825
- ## # ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3826
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3827
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3909
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3910
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3911
+ ## 1 2013 1 1 517 515 2 830
3912
+ ## 2 2013 1 1 533 529 4 850
3913
+ ## 3 2013 1 1 542 540 2 923
3914
+ ## 4 2013 1 1 544 545 -1 1004
3915
+ ## 5 2013 1 1 554 600 -6 812
3916
+ ## 6 2013 1 1 554 558 -4 740
3917
+ ## # ℹ 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3918
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3919
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3920
+ ## # minute <dbl>, time_hour <dttm>
3828
3921
  ```
3829
3922
 
3830
3923
  ## Add variables to a dataframe with 'mutate'
@@ -3954,48 +4047,48 @@ puts R.head(flights, 12)
3954
4047
 
3955
4048
  ```
3956
4049
  ## [1] 336776 19
3957
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3958
- ## <int> <int> <int> <int> <int> <num> <int> <int>
3959
- ## 1: 2013 1 1 517 515 2 830 819
3960
- ## 2: 2013 1 1 533 529 4 850 830
3961
- ## 3: 2013 1 1 542 540 2 923 850
3962
- ## 4: 2013 1 1 544 545 -1 1004 1022
3963
- ## 5: 2013 1 1 554 600 -6 812 837
3964
- ## 6: 2013 1 1 554 558 -4 740 728
3965
- ## 7: 2013 1 1 555 600 -5 913 854
3966
- ## 8: 2013 1 1 557 600 -3 709 723
3967
- ## 9: 2013 1 1 557 600 -3 838 846
3968
- ## 10: 2013 1 1 558 600 -2 753 745
3969
- ## 11: 2013 1 1 558 600 -2 849 851
3970
- ## 12: 2013 1 1 558 600 -2 853 856
3971
- ## arr_delay carrier flight tailnum origin dest air_time distance hour
3972
- ## <num> <char> <int> <char> <char> <char> <num> <num> <num>
3973
- ## 1: 11 UA 1545 N14228 EWR IAH 227 1400 5
3974
- ## 2: 20 UA 1714 N24211 LGA IAH 227 1416 5
3975
- ## 3: 33 AA 1141 N619AA JFK MIA 160 1089 5
3976
- ## 4: -18 B6 725 N804JB JFK BQN 183 1576 5
3977
- ## 5: -25 DL 461 N668DN LGA ATL 116 762 6
3978
- ## 6: 12 UA 1696 N39463 EWR ORD 150 719 5
3979
- ## 7: 19 B6 507 N516JB EWR FLL 158 1065 6
3980
- ## 8: -14 EV 5708 N829AS LGA IAD 53 229 6
3981
- ## 9: -8 B6 79 N593JB JFK MCO 140 944 6
3982
- ## 10: 8 AA 301 N3ALAA LGA ORD 138 733 6
3983
- ## 11: -2 B6 49 N793JB JFK PBI 149 1028 6
3984
- ## 12: -3 B6 71 N657JB JFK TPA 158 1005 6
3985
- ## minute time_hour
3986
- ## <num> <POSc>
3987
- ## 1: 15 2013-01-01 05:00:00
3988
- ## 2: 29 2013-01-01 05:00:00
3989
- ## 3: 40 2013-01-01 05:00:00
3990
- ## 4: 45 2013-01-01 05:00:00
3991
- ## 5: 0 2013-01-01 06:00:00
3992
- ## 6: 58 2013-01-01 05:00:00
3993
- ## 7: 0 2013-01-01 06:00:00
3994
- ## 8: 0 2013-01-01 06:00:00
3995
- ## 9: 0 2013-01-01 06:00:00
3996
- ## 10: 0 2013-01-01 06:00:00
3997
- ## 11: 0 2013-01-01 06:00:00
3998
- ## 12: 0 2013-01-01 06:00:00
4050
+ ## year month day dep_time sched_dep_time dep_delay arr_time
4051
+ ## <int> <int> <int> <int> <int> <num> <int>
4052
+ ## 1: 2013 1 1 517 515 2 830
4053
+ ## 2: 2013 1 1 533 529 4 850
4054
+ ## 3: 2013 1 1 542 540 2 923
4055
+ ## 4: 2013 1 1 544 545 -1 1004
4056
+ ## 5: 2013 1 1 554 600 -6 812
4057
+ ## 6: 2013 1 1 554 558 -4 740
4058
+ ## 7: 2013 1 1 555 600 -5 913
4059
+ ## 8: 2013 1 1 557 600 -3 709
4060
+ ## 9: 2013 1 1 557 600 -3 838
4061
+ ## 10: 2013 1 1 558 600 -2 753
4062
+ ## 11: 2013 1 1 558 600 -2 849
4063
+ ## 12: 2013 1 1 558 600 -2 853
4064
+ ## sched_arr_time arr_delay carrier flight tailnum origin dest
4065
+ ## <int> <num> <char> <int> <char> <char> <char>
4066
+ ## 1: 819 11 UA 1545 N14228 EWR IAH
4067
+ ## 2: 830 20 UA 1714 N24211 LGA IAH
4068
+ ## 3: 850 33 AA 1141 N619AA JFK MIA
4069
+ ## 4: 1022 -18 B6 725 N804JB JFK BQN
4070
+ ## 5: 837 -25 DL 461 N668DN LGA ATL
4071
+ ## 6: 728 12 UA 1696 N39463 EWR ORD
4072
+ ## 7: 854 19 B6 507 N516JB EWR FLL
4073
+ ## 8: 723 -14 EV 5708 N829AS LGA IAD
4074
+ ## 9: 846 -8 B6 79 N593JB JFK MCO
4075
+ ## 10: 745 8 AA 301 N3ALAA LGA ORD
4076
+ ## 11: 851 -2 B6 49 N793JB JFK PBI
4077
+ ## 12: 856 -3 B6 71 N657JB JFK TPA
4078
+ ## air_time distance hour minute time_hour
4079
+ ## <num> <num> <num> <num> <POSc>
4080
+ ## 1: 227 1400 5 15 2013-01-01 05:00:00
4081
+ ## 2: 227 1416 5 29 2013-01-01 05:00:00
4082
+ ## 3: 160 1089 5 40 2013-01-01 05:00:00
4083
+ ## 4: 183 1576 5 45 2013-01-01 05:00:00
4084
+ ## 5: 116 762 6 0 2013-01-01 06:00:00
4085
+ ## 6: 150 719 5 58 2013-01-01 05:00:00
4086
+ ## 7: 158 1065 6 0 2013-01-01 06:00:00
4087
+ ## 8: 53 229 6 0 2013-01-01 06:00:00
4088
+ ## 9: 140 944 6 0 2013-01-01 06:00:00
4089
+ ## 10: 138 733 6 0 2013-01-01 06:00:00
4090
+ ## 11: 149 1028 6 0 2013-01-01 06:00:00
4091
+ ## 12: 158 1005 6 0 2013-01-01 06:00:00
3999
4092
  ```
4000
4093
 
4001
4094
 
@@ -4040,42 +4133,42 @@ puts ans
4040
4133
  ```
4041
4134
 
4042
4135
  ```
4043
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
4044
- ## <int> <int> <int> <int> <int> <num> <int> <int>
4045
- ## 1: 2013 6 1 2 2359 3 341 350
4046
- ## 2: 2013 6 1 538 545 -7 925 922
4047
- ## 3: 2013 6 1 539 540 -1 832 840
4048
- ## 4: 2013 6 1 553 600 -7 700 711
4049
- ## 5: 2013 6 1 554 600 -6 851 908
4050
- ## 6: 2013 6 1 557 600 -3 934 942
4051
- ## arr_delay carrier flight tailnum origin dest air_time distance hour
4052
- ## <num> <char> <int> <char> <char> <char> <num> <num> <num>
4053
- ## 1: -9 B6 739 N618JB JFK PSE 200 1617 23
4054
- ## 2: 3 B6 725 N806JB JFK BQN 203 1576 5
4055
- ## 3: -8 AA 701 N5EAAA JFK MIA 140 1089 5
4056
- ## 4: -11 EV 5716 N835AS JFK IAD 42 228 6
4057
- ## 5: -17 UA 1159 N33132 JFK LAX 330 2475 6
4058
- ## 6: -8 B6 715 N766JB JFK SJU 198 1598 6
4059
- ## minute time_hour
4060
- ## <num> <POSc>
4061
- ## 1: 59 2013-06-01 23:00:00
4062
- ## 2: 45 2013-06-01 05:00:00
4063
- ## 3: 40 2013-06-01 05:00:00
4064
- ## 4: 0 2013-06-01 06:00:00
4065
- ## 5: 0 2013-06-01 06:00:00
4066
- ## 6: 0 2013-06-01 06:00:00
4067
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
4068
- ## <int> <int> <int> <int> <int> <num> <int> <int>
4069
- ## 1: 2013 1 1 517 515 2 830 819
4070
- ## 2: 2013 1 1 533 529 4 850 830
4071
- ## arr_delay carrier flight tailnum origin dest air_time distance hour
4072
- ## <num> <char> <int> <char> <char> <char> <num> <num> <num>
4073
- ## 1: 11 UA 1545 N14228 EWR IAH 227 1400 5
4074
- ## 2: 20 UA 1714 N24211 LGA IAH 227 1416 5
4075
- ## minute time_hour
4076
- ## <num> <POSc>
4077
- ## 1: 15 2013-01-01 05:00:00
4078
- ## 2: 29 2013-01-01 05:00:00
4136
+ ## year month day dep_time sched_dep_time dep_delay arr_time
4137
+ ## <int> <int> <int> <int> <int> <num> <int>
4138
+ ## 1: 2013 6 1 2 2359 3 341
4139
+ ## 2: 2013 6 1 538 545 -7 925
4140
+ ## 3: 2013 6 1 539 540 -1 832
4141
+ ## 4: 2013 6 1 553 600 -7 700
4142
+ ## 5: 2013 6 1 554 600 -6 851
4143
+ ## 6: 2013 6 1 557 600 -3 934
4144
+ ## sched_arr_time arr_delay carrier flight tailnum origin dest
4145
+ ## <int> <num> <char> <int> <char> <char> <char>
4146
+ ## 1: 350 -9 B6 739 N618JB JFK PSE
4147
+ ## 2: 922 3 B6 725 N806JB JFK BQN
4148
+ ## 3: 840 -8 AA 701 N5EAAA JFK MIA
4149
+ ## 4: 711 -11 EV 5716 N835AS JFK IAD
4150
+ ## 5: 908 -17 UA 1159 N33132 JFK LAX
4151
+ ## 6: 942 -8 B6 715 N766JB JFK SJU
4152
+ ## air_time distance hour minute time_hour
4153
+ ## <num> <num> <num> <num> <POSc>
4154
+ ## 1: 200 1617 23 59 2013-06-01 23:00:00
4155
+ ## 2: 203 1576 5 45 2013-06-01 05:00:00
4156
+ ## 3: 140 1089 5 40 2013-06-01 05:00:00
4157
+ ## 4: 42 228 6 0 2013-06-01 06:00:00
4158
+ ## 5: 330 2475 6 0 2013-06-01 06:00:00
4159
+ ## 6: 198 1598 6 0 2013-06-01 06:00:00
4160
+ ## year month day dep_time sched_dep_time dep_delay arr_time
4161
+ ## <int> <int> <int> <int> <int> <num> <int>
4162
+ ## 1: 2013 1 1 517 515 2 830
4163
+ ## 2: 2013 1 1 533 529 4 850
4164
+ ## sched_arr_time arr_delay carrier flight tailnum origin dest
4165
+ ## <int> <num> <char> <int> <char> <char> <char>
4166
+ ## 1: 819 11 UA 1545 N14228 EWR IAH
4167
+ ## 2: 830 20 UA 1714 N24211 LGA IAH
4168
+ ## air_time distance hour minute time_hour
4169
+ ## <num> <num> <num> <num> <POSc>
4170
+ ## 1: 227 1400 5 15 2013-01-01 05:00:00
4171
+ ## 2: 227 1416 5 29 2013-01-01 05:00:00
4079
4172
  ```
4080
4173
 
4081
4174
 
@@ -4109,83 +4202,46 @@ ans = flights[:all, E.list(R[:arr_delay], R[:dep_delay])]
4109
4202
  # Apache Arrow
4110
4203
 
4111
4204
  [Apache Arrow](https://arrow.apache.org/) is a **columnar** in-memory format used heavily in R
4112
- and Python for analytics. GNU R still runs in a **separate process**. Ruby does **not** hold a
4113
- shared Arrow C++ table with R. Stages:
4114
-
4115
- 1. **Stage A (copy over the bridge):** Ruby row hashes **`R::Arrow.from_ruby_batches`** builds
4116
- an Arrow `Table` **inside GNU R**. You get a **proxy**.
4117
- 2. **Stage B1 (Ruby → R IPC file):** **`Galaaz::ArrowIpc.write`** / **`write_batches`** writes an
4118
- Arrow IPC file (prefer **`/dev/shm`**); **`R::Arrow.open_ipc(path)`** opens it in R. Only the
4119
- **path** crosses NewBridge. This is **mmap/IPC file handoff**, not a shared heap.
4120
- 3. **Stage B2 (R → Ruby IPC file):** **`R::Arrow.write_ipc(obj)`** writes uncompressed IPC; Ruby
4121
- reads with **`Galaaz::ArrowIpc.read`** (column hash) or **`read_batches`** (row hashes). Call
4122
- **`Galaaz::ArrowIpc.release(path)`** when finished.
4123
- 4. **Stage C (not shipped):** named shared-memory bus. Do not claim 0 ms shared RAM until then.
4124
- See **`Documentation/ROADMAP_ARROW_RUBY_R.md`**.
4125
-
4126
- After ingest, use R’s **`arrow`** / **`dplyr`** on the proxy (`group_by`, `summarise`, `collect`)
4127
- and unbox only KPIs you need in Ruby.
4128
-
4129
- **Optional Ruby backends for Stage B**
4130
-
4131
- * **CRuby:** Apache **red-arrow** — `gem install red-arrow` pinned to the same major as
4132
- `pkg-config --modversion arrow-glib`, plus system **Arrow GLib** (`libarrow-glib-dev` from the
4133
- [Apache Arrow APT](https://arrow.apache.org/install/) repo). Do **not** install the unrelated
4134
- legacy Rubygems package named `arrow`. `bundle exec` still sees a user-installed `red-arrow`
4135
- via Galaaz’s load-path helper.
4136
- * **JRuby:** Apache Arrow **Java** JARs — **`GALAAZ_ARROW_JARS`**, `~/arrow_jars`, or
4137
- `jar-dependencies`. Export **`JAVA_OPTS=--add-opens=java.base/java.nio=ALL-UNNAMED`** on the
4138
- **child** JVM (`bin/galaaz-jruby`, `mise.toml`). `jruby -J... -S bundle exec rspec` does **not**
4139
- pass `-J` to rspec.
4140
-
4141
- **R packages:** **`arrow`** and **`dplyr`**. B2 writes IPC with **`compression: 'uncompressed'`**
4142
- so JRuby Arrow Java can read without extra compression JARs.
4143
-
4144
- **Tests:** `specs/arrow_from_ruby_batches_spec.rb` (A);
4145
- `specs/arrow_ipc_handoff_spec.rb`, `specs/arrow_ipc_export_spec.rb` (B, sync);
4146
- `new_bridge_specs/arrow_ipc_async_spec.rb`, `new_bridge_specs/arrow_ipc_export_async_spec.rb` (B, async).
4147
-
4148
- ## `R::Arrow` and `Galaaz::ArrowIpc`
4149
-
4150
- * **`R::Arrow.from_ruby_batches`** — Stage A ingest.
4151
- * **`R::Arrow.open_ipc(path)`** — Stage B1: IPC file → R Table proxy.
4152
- * **`R::Arrow.write_ipc(obj, path = nil)`** — Stage B2: R Table/tibble → IPC path (scratch if omitted).
4153
- * **`Galaaz::ArrowIpc.write` / `write_batches` / `read` / `read_batches` / `allocate_path` / `release` / `available?`**
4154
- * **`R::Arrow.table_from(df)`** — wrap an R `data.frame` / tibble as an Arrow table.
4155
- * **`R::Arrow.read_feather` / `write_feather`**, **`read_parquet`**, **`dataset(path)`** — file and
4156
- dataset IO on paths visible to R.
4205
+ and Python for analytics. In Galaaz, **Ruby does not hold an Arrow C++ table itself**; instead you
4206
+ build ordinary Ruby structures (arrays of row hashes), and **`R::Arrow.from_ruby_batches`** creates
4207
+ a real **Arrow `Table` inside GNU R**. From there you use R’s **`arrow`** and **`dplyr`** packages
4208
+ as usual: **`group_by`** on the Arrow table, **`summarise`** for aggregates, then **`collect()`** to
4209
+ materialize a tibble when you need in-memory R rows.
4157
4210
 
4158
- ## Example: Stage B round-trip (IPC file)
4211
+ That pattern matches production use: **JRuby threads** or a **multi-process CRuby** app
4212
+ (or sequential code) assemble many rows in
4213
+ Ruby; you pay **one** bridge-heavy handoff to R; **dplyr** runs vectorised work on the Arrow table
4214
+ in R.
4159
4215
 
4160
- Requires `Galaaz::ArrowIpc.available?` (red-arrow or Arrow JARs) and R **`arrow`**. Not knitted
4161
- below so a machine without the optional backend still builds this manual.
4216
+ **Prerequisites:** install R packages **`arrow`** and **`dplyr`**. Run scripts with
4217
+ **`bin/galaaz-jruby`** (or the same JVM flags as in **`docs/testing.md`**) so the Arrow JNI stack is
4218
+ available.
4162
4219
 
4163
- ```ruby
4164
- path = Galaaz::ArrowIpc.write(id: [1, 2, 3], grp: %w[a a b], value: [1.0, 2.0, 3.5])
4165
- tbl = R::Arrow.open_ipc(path)
4166
- Galaaz::ArrowIpc.release(path)
4220
+ ## Other `R::Arrow` helpers
4167
4221
 
4168
- summed = R.dplyr___summarise(R.dplyr___group_by(tbl, :grp), total: E.sum(:value))
4169
- out_path = R::Arrow.write_ipc(summed)
4170
- rows = Galaaz::ArrowIpc.read_batches(out_path)
4171
- Galaaz::ArrowIpc.release(out_path)
4172
- # rows => [{:grp=>"a", :total=>3.0}, {:grp=>"b", :total=>3.5}] (illustrative)
4173
- ```
4222
+ The Ruby module **`R::Arrow`** (see `lib/R_interface/r_arrow.rb`) also includes:
4223
+
4224
+ * **`R::Arrow.table_from(df)`** — wrap an R `data.frame` / tibble as an Arrow table.
4225
+ * **`R::Arrow.read_feather` / `write_feather`**, **`read_parquet`**, **`dataset(path)`** — file and
4226
+ dataset IO on paths visible to R.
4174
4227
 
4175
4228
  ## Example: many Ruby rows → Arrow in R → grouped statistics
4176
4229
 
4177
4230
  The repository test **`slow-specs/arrow_large_pipeline_spec.rb`** builds **200k rows** in parallel
4178
- (eight threads × 25,000 rows), pushes them through **`R::Arrow.from_ruby_batches`** (Stage A), then
4179
- checks that **dplyr** group summaries match a Ruby reference calculation. The same logic appears
4180
- below at a **smaller scale** so this manual can knit quickly; increase `thread_count` and
4181
- `rows_per_thread` when experimenting locally. For the same ingest **without** copying every cell
4182
- over NewBridge, use Stage B (`write_batches` + `open_ipc`) instead of `from_ruby_batches`.
4231
+ (eight threads × 25,000 rows), pushes them through **`R::Arrow.from_ruby_batches`**, then checks that
4232
+ **dplyr** group summaries match a Ruby reference calculation. The same logic appears below at a
4233
+ **smaller scale** so this manual can knit quickly; increase `thread_count` and `rows_per_thread`
4234
+ when experimenting locally.
4183
4235
 
4184
4236
 
4185
4237
  ``` ruby
4186
4238
  # Scaled-down version of slow-specs/arrow_large_pipeline_spec.rb.
4187
- unless R::Support.eval("requireNamespace('arrow', quietly=TRUE) && requireNamespace('dplyr', quietly=TRUE)") == true
4188
- puts '(Skip: need arrow + dplyr in R; use bin/galaaz-jruby outside gKnit.)'
4239
+ arrow_ok = R::Support.eval(
4240
+ "requireNamespace('arrow', quietly=TRUE) && " +
4241
+ "requireNamespace('dplyr', quietly=TRUE)")
4242
+ unless arrow_ok == true
4243
+ puts '(Skip: need arrow + dplyr in R; ' +
4244
+ 'use bin/galaaz-jruby outside gKnit.)'
4189
4245
  else
4190
4246
  thread_count = 4
4191
4247
  rows_per_thread = 500
@@ -4228,7 +4284,9 @@ else
4228
4284
 
4229
4285
  total_n = 0
4230
4286
  (1..(out.nrow >> 0)).each { |i| total_n += (out[['n']][i] >> 0) }
4231
- puts "Sum of group counts n (should equal #{thread_count * rows_per_thread}): #{total_n}"
4287
+ puts "Sum of group counts n " +
4288
+ "(should equal #{thread_count * rows_per_thread}): " +
4289
+ "#{total_n}"
4232
4290
  end
4233
4291
  ```
4234
4292
 
@@ -4245,10 +4303,10 @@ end
4245
4303
  ```
4246
4304
 
4247
4305
  **What to notice:** (1) Ruby only sees **`Hash`** rows and Ruby **`Thread`** objects; (2) a single
4248
- **`from_ruby_batches`** call **copies** those columns into an Arrow table in R; (3) **`dplyr___group_by`** /
4306
+ **`from_ruby_batches`** call creates the Arrow table in R; (3) **`dplyr___group_by`** /
4249
4307
  **`dplyr___summarise`** / **`dplyr___collect`** mirror **`dplyr::group_by`** /
4250
4308
  **`dplyr::summarise`** / **`dplyr::collect`** on an Arrow-backed table. For a lighter test, see
4251
- **`specs/arrow_from_ruby_batches_spec.rb`**; for the full-size Stage A benchmark, run
4309
+ **`specs/arrow_from_ruby_batches_spec.rb`**; for the full-size benchmark, run
4252
4310
  **`bin/run_slow_rspec slow-specs/arrow_large_pipeline_spec.rb`**.
4253
4311
 
4254
4312
  # Bioconductor and DESeq2
@@ -4277,8 +4335,10 @@ The script **`examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb`** is
4277
4335
  version in the repository. Run it from the **Galaaz repository root** with either engine, for example:
4278
4336
 
4279
4337
  ```text
4280
- bin/galaaz-ruby examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb
4281
- # or: bin/galaaz-jruby examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb
4338
+ bin/galaaz-ruby \
4339
+ examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb
4340
+ # or: bin/galaaz-jruby \
4341
+ # examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb
4282
4342
  ```
4283
4343
 
4284
4344
  The workflow in Ruby mirrors a standard DESeq2 vignette:
@@ -4306,7 +4366,8 @@ manual is knitted, because **DESeq2** is heavy and may be absent on the build ma
4306
4366
 
4307
4367
 
4308
4368
  ``` ruby
4309
- # Canonical script: examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb
4369
+ # Canonical script:
4370
+ # examples/bioconductor_deseq2_airway/deseq2_airway_galaaz.rb
4310
4371
  # Run: bin/galaaz-ruby examples/.../deseq2_airway_galaaz.rb (repo root).
4311
4372
 
4312
4373
  require 'galaaz'
@@ -4333,7 +4394,8 @@ puts "Samples: #{R.ncol(dds)}"
4333
4394
  puts "Genes after prefilter: #{R.nrow(dds)}"
4334
4395
  puts "Result rows: #{R.nrow(res)}"
4335
4396
  puts "Result columns: #{R.colnames(res)}"
4336
- puts "Significant genes (padj < 0.05): #{R.sum(res.padj < 0.05, na__rm: true)}"
4397
+ puts "Significant genes (padj < 0.05): " +
4398
+ "#{R.sum(res.padj < 0.05, na__rm: true)}"
4337
4399
 
4338
4400
  res_ordered = res[R.order(res.padj), :all]
4339
4401
  puts R.head(R.as__data__frame(res_ordered), 10)
@@ -4349,8 +4411,12 @@ preview (it does **not** run **`DESeq`** so the manual knits quickly).
4349
4411
 
4350
4412
 
4351
4413
  ``` ruby
4352
- unless R::Support.eval("requireNamespace('DESeq2', quietly=TRUE) && requireNamespace('airway', quietly=TRUE)")
4353
- puts '(Skip: install DESeq2 and airway via BiocManager in R to run the full example.)'
4414
+ deseq_ok = R::Support.eval(
4415
+ "requireNamespace('DESeq2', quietly=TRUE) && " +
4416
+ "requireNamespace('airway', quietly=TRUE)")
4417
+ unless deseq_ok
4418
+ puts '(Skip: install DESeq2 and airway via ' +
4419
+ 'BiocManager in R for the full example.)'
4354
4420
  else
4355
4421
  R.library('DESeq2')
4356
4422
  R.library('airway')
@@ -4365,14 +4431,14 @@ end
4365
4431
  ```
4366
4432
  ## airway object (head of assay / dims via R):
4367
4433
  ## ncol(samples): [1] 8
4368
- ## SRR1039508 SRR1039509 SRR1039512 SRR1039513 SRR1039516
4369
- ## ENSG00000000003 679 448 873 408 1138
4370
- ## ENSG00000000005 0 0 0 0 0
4371
- ## ENSG00000000419 467 515 621 365 587
4372
- ## SRR1039517 SRR1039520 SRR1039521
4373
- ## ENSG00000000003 1047 770 572
4374
- ## ENSG00000000005 0 0 0
4375
- ## ENSG00000000419 799 417 508
4434
+ ## SRR1039508 SRR1039509 SRR1039512 SRR1039513
4435
+ ## ENSG00000000003 679 448 873 408
4436
+ ## ENSG00000000005 0 0 0 0
4437
+ ## ENSG00000000419 467 515 621 365
4438
+ ## SRR1039516 SRR1039517 SRR1039520 SRR1039521
4439
+ ## ENSG00000000003 1138 1047 770 572
4440
+ ## ENSG00000000005 0 0 0 0
4441
+ ## ENSG00000000419 587 799 417 508
4376
4442
  ```
4377
4443
 
4378
4444
  # Performance
@@ -4387,9 +4453,8 @@ Practical tips:
4387
4453
  glue.
4388
4454
  * **Reuse one process**: running many short scripts cold-starts Ruby, the JVM, and R each time;
4389
4455
  a long-lived process or repeated calls in one run amortize setup (see benchmarks below).
4390
- * **Batch data**: merge shards in Ruby, then **`R::Arrow.from_ruby_batches`** (Stage A) or
4391
- **`Galaaz::ArrowIpc`** + **`R::Arrow.open_ipc`** (Stage B) instead of millions of tiny R calls.
4392
- When Ruby needs a bulky result table back, **`R::Arrow.write_ipc`** + **`Galaaz::ArrowIpc.read_batches`**.
4456
+ * **Batch data**: merge shards in Ruby, then call **`R::Arrow.from_ruby_batches`** (or build one
4457
+ data frame) instead of millions of tiny R calls.
4393
4458
 
4394
4459
  For measured discussion (including DESeq2-style workloads and warm comparisons), see
4395
4460
  **`docs/performance.md`** and **`docs/deseq2_airway_benchmark.md`** in the Galaaz repository.
@@ -4426,20 +4491,20 @@ puts mtcars.head
4426
4491
  ```
4427
4492
 
4428
4493
  ```
4429
- ## mpg cyl disp hp drat wt qsec vs am gear carb
4430
- ## Cadillac Fleetwood 10.4 8 472 205 2.93 5.250 17.98 0 0 3 4
4431
- ## Lincoln Continental 10.4 8 460 215 3.00 5.424 17.82 0 0 3 4
4432
- ## Camaro Z28 13.3 8 350 245 3.73 3.840 15.41 0 0 3 4
4433
- ## Duster 360 14.3 8 360 245 3.21 3.570 15.84 0 0 3 4
4434
- ## Chrysler Imperial 14.7 8 440 230 3.23 5.345 17.42 0 0 3 4
4435
- ## Maserati Bora 15.0 8 301 335 3.54 3.570 14.60 0 1 5 8
4436
- ## car_name mpg_z mpg_type
4437
- ## Cadillac Fleetwood Cadillac Fleetwood -1.61 below
4438
- ## Lincoln Continental Lincoln Continental -1.61 below
4439
- ## Camaro Z28 Camaro Z28 -1.13 below
4440
- ## Duster 360 Duster 360 -0.96 below
4441
- ## Chrysler Imperial Chrysler Imperial -0.89 below
4442
- ## Maserati Bora Maserati Bora -0.84 below
4494
+ ## mpg cyl disp hp drat wt qsec vs am gear
4495
+ ## Cadillac Fleetwood 10.4 8 472 205 2.93 5.250 17.98 0 0 3
4496
+ ## Lincoln Continental 10.4 8 460 215 3.00 5.424 17.82 0 0 3
4497
+ ## Camaro Z28 13.3 8 350 245 3.73 3.840 15.41 0 0 3
4498
+ ## Duster 360 14.3 8 360 245 3.21 3.570 15.84 0 0 3
4499
+ ## Chrysler Imperial 14.7 8 440 230 3.23 5.345 17.42 0 0 3
4500
+ ## Maserati Bora 15.0 8 301 335 3.54 3.570 14.60 0 1 5
4501
+ ## carb car_name mpg_z mpg_type
4502
+ ## Cadillac Fleetwood 4 Cadillac Fleetwood -1.61 below
4503
+ ## Lincoln Continental 4 Lincoln Continental -1.61 below
4504
+ ## Camaro Z28 4 Camaro Z28 -1.13 below
4505
+ ## Duster 360 4 Duster 360 -0.96 below
4506
+ ## Chrysler Imperial 4 Chrysler Imperial -0.89 below
4507
+ ## Maserati Bora 8 Maserati Bora -0.84 below
4443
4508
  ```
4444
4509
  Now, let's plot the diverging bar plot. When using gKnit, you normally do **not** need to open a
4445
4510
  graphics device manually; gKnit arranges the figure device for chunk output. Galaaz
@@ -4461,13 +4526,17 @@ but in this graph we want the bars to be horizontally laid so we add 'coord\_fli
4461
4526
  ``` ruby
4462
4527
  require 'ggplot'
4463
4528
 
4464
- puts mtcars.ggplot(E.aes(x: :car_name, y: :mpg_z, label: :mpg_z)) +
4465
- R.geom_bar(E.aes(fill: :mpg_type), stat: 'identity', width: 0.5) +
4466
- R.scale_fill_manual(name: 'Mileage',
4467
- labels: R.c('Above Average', 'Below Average'),
4468
- values: R.c('above': '#00ba38', 'below': '#f8766d')) +
4529
+ puts mtcars.ggplot(
4530
+ E.aes(x: :car_name, y: :mpg_z, label: :mpg_z)) +
4531
+ R.geom_bar(E.aes(fill: :mpg_type),
4532
+ stat: 'identity', width: 0.5) +
4533
+ R.scale_fill_manual(
4534
+ name: 'Mileage',
4535
+ labels: R.c('Above Average', 'Below Average'),
4536
+ values: R.c('above': '#00ba38',
4537
+ 'below': '#f8766d')) +
4469
4538
  R.labs(subtitle: "Normalised mileage from 'mtcars'",
4470
- title: "Diverging Bars") +
4539
+ title: "Diverging Bars") +
4471
4540
  R.coord_flip
4472
4541
  ```
4473
4542
 
@@ -4590,7 +4659,8 @@ In Galaaz the method mutate_y below will work fine and will never fail silently.
4590
4659
 
4591
4660
  ``` ruby
4592
4661
  def mutate_y(df)
4593
- # Mutate column names are Ruby kwargs (y: …). Use .assign only for R `<-` expressions.
4662
+ # Column names are Ruby kwargs (y: …).
4663
+ # Use .assign only for R `<-` expressions.
4594
4664
  df.mutate(y: R[:a] + R[:x])
4595
4665
  end
4596
4666
  ```
@@ -4616,10 +4686,16 @@ definition of 'mutate\_y' above:
4616
4686
 
4617
4687
  ``` ruby
4618
4688
  a = 10
4619
- mutate_y(df1)
4689
+ begin
4690
+ mutate_y(df1)
4691
+ rescue => e
4692
+ puts e.class.to_s
4693
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
4694
+ end
4620
4695
  ```
4621
4696
 
4622
4697
  ```
4698
+ ## NewBridge::SessionClient::RProcessError
4623
4699
  ## Error: ℹ In argument: `y = a + x`.
4624
4700
  ## Caused by error:
4625
4701
  ## ! object 'a' not found
@@ -4966,16 +5042,16 @@ puts (~R[:starwars]).head
4966
5042
 
4967
5043
  ```
4968
5044
  ## # A tibble: 6 × 14
4969
- ## name height mass hair_color skin_color eye_color birth_year sex gender
4970
- ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr>
4971
- ## 1 Luke Sky… 172 77 blond fair blue 19 male mascu…
4972
- ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu…
4973
- ## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu…
4974
- ## 4 Darth Va… 202 136 none white yellow 41.9 male mascu…
4975
- ## 5 Leia Org… 150 49 brown light brown 19 fema… femin…
4976
- ## 6 Owen Lars 178 120 brown, gr… light blue 52 male mascu…
4977
- ## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>,
4978
- ## # vehicles <list>, starships <list>
5045
+ ## name height mass hair_color skin_color eye_color birth_year sex
5046
+ ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr>
5047
+ ## 1 Luke … 172 77 blond fair blue 19 male
5048
+ ## 2 C-3PO 167 75 <NA> gold yellow 112 none
5049
+ ## 3 R2-D2 96 32 <NA> white, bl… red 33 none
5050
+ ## 4 Darth… 202 136 none white yellow 41.9 male
5051
+ ## 5 Leia … 150 49 brown light brown 19 fema…
5052
+ ## 6 Owen 178 120 brown, gr… light blue 52 male
5053
+ ## # ℹ 6 more variables: gender <chr>, homeworld <chr>, species <chr>,
5054
+ ## # films <list>, vehicles <list>, starships <list>
4979
5055
  ```
4980
5056
  The grouped_mean function below will receive a grouping variable and calculate summaries for
4981
5057
  the value\_variables given:
@@ -5004,8 +5080,8 @@ gm = starwars %>%
5004
5080
  ## # Auto named with `tibble::lst()`: tibble::lst(mean, median)
5005
5081
  ##
5006
5082
  ## # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
5007
- ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
5008
- ## generated.
5083
+ ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning
5084
+ ## was generated.
5009
5085
  ```
5010
5086
 
5011
5087
  ``` r
@@ -5039,11 +5115,19 @@ def grouped_mean(data, grouping_variables, value_variables)
5039
5115
  data.
5040
5116
  group_by_at(grouping_variables).
5041
5117
  mutate(count: E.n).
5042
- summarise_at(E.c(value_variables, "count"), ~R[:mean], na__rm: true).
5043
- rename_at(value_variables, E.funs(E.paste0("mean_", value_variables)))
5118
+ summarise_at(
5119
+ E.c(value_variables, "count"),
5120
+ ~R[:mean],
5121
+ na__rm: true).
5122
+ rename_at(
5123
+ value_variables,
5124
+ E.funs(E.paste0("mean_", value_variables)))
5044
5125
  end
5045
5126
 
5046
- puts grouped_mean((~R[:starwars]), "eye_color", E.c("mass", "birth_year"))
5127
+ puts grouped_mean(
5128
+ (~R[:starwars]),
5129
+ "eye_color",
5130
+ E.c("mass", "birth_year"))
5047
5131
  ```
5048
5132
 
5049
5133
  ```
@@ -5077,7 +5161,7 @@ arguments.
5077
5161
  * Fork it
5078
5162
  * Create your feature branch (`git checkout -b my-new-feature`)
5079
5163
  * Write tests — use **`bin/run_rspec`** or **`bin/run_all_rspec`** (JRuby or CRuby via
5080
- **`GALAAZ_RUBY`**) so JVM flags and the load path match **`docs/testing.md`**
5164
+ **`GALAAZ_RUBY`**) so the load path matches **`docs/testing.md`**
5081
5165
  * Commit your changes (`git commit -am 'Add some feature'`)
5082
5166
  * Push to the branch (`git push origin my-new-feature`)
5083
5167
  * Open a pull request