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
@@ -209,6 +209,28 @@
209
209
  % Command to import an R variable to latex
210
210
  \newcommand{\RtoLatex}[2]{\newcommand{#1}{#2}}
211
211
 
212
+ % Soft-wrap Pandoc highlighted code/output boxes (Shaded + Highlighting).
213
+ % This runs after Pandoc's default \DefineVerbatimEnvironment{Highlighting}
214
+ % (header includes come later in the generated .tex). Prefer manual line
215
+ % breaks in Rmd sources; breaklines is a safety net for leftovers/output.
216
+ % Requires TinyTeX/TeX Live package: tlmgr install fvextra
217
+ \IfFileExists{fvextra.sty}{%
218
+ \usepackage{fvextra}%
219
+ \DefineVerbatimEnvironment{Highlighting}{Verbatim}{%
220
+ breaklines=true,
221
+ breakanywhere=true,
222
+ breakindent=1.5em,
223
+ fontsize=\small,
224
+ commandchars=\\\{\}%
225
+ }%
226
+ }{%
227
+ % fancyvrb is already loaded by Pandoc; shrink code so more fits per line.
228
+ \DefineVerbatimEnvironment{Highlighting}{Verbatim}{%
229
+ fontsize=\small,
230
+ commandchars=\\\{\}%
231
+ }%
232
+ }
233
+
212
234
  %
213
235
  %\newcommand{\atraso}[1]{\color{red} \textbf {Tempo desde a Assinatura do Contrato: #1 dias}}
214
236
  \usepackage{booktabs}
@@ -241,7 +263,7 @@
241
263
  \apptocmd{\@title}{\par {\large #1 \par}}{}{}
242
264
  }
243
265
  \makeatother
244
- \subtitle{Coupling Ruby (JRuby) and GNU R for data science}
266
+ \subtitle{R-on-Rails: GNU R meets Ruby for the web}
245
267
  \author{Rodrigo Botafogo}
246
268
  \date{2026}
247
269
 
@@ -295,22 +317,26 @@ Until recently, there was no real perspective for Ruby to bridge this
295
317
  gap. Implementing a complete scientific computing infrastructure would
296
318
  take too long.
297
319
 
298
- \textbf{Galaaz 2.0} couples \textbf{JRuby} (Ruby on the JVM) with
299
- \textbf{GNU R}---the same R you use for CRAN and Bioconductor. Ruby and
300
- R run in \textbf{separate processes}; the \textbf{Galaaz bridge} sends
301
- requests to R and returns results to Ruby. From your point of view you
302
- still write Ruby: \texttt{R.c(...)},
320
+ \textbf{Galaaz 2.0} supports \textbf{JRuby} and \textbf{CRuby} equally
321
+ for the same NewBridge protocol. Pick the Ruby that fits your app: JRuby
322
+ when you want real multithreading for web and I/O; CRuby when you prefer
323
+ MRI. R remains the same \textbf{GNU R} you use interactively---including
324
+ compiled extensions and Bioconductor. Ruby and R run in \textbf{separate
325
+ processes}; the \textbf{Galaaz bridge} sends requests to R and returns
326
+ results to Ruby. From your point of view you still write Ruby:
327
+ \texttt{R.c(...)},
303
328
  \texttt{R.library(\textquotesingle{}ggplot2\textquotesingle{})},
304
- \texttt{\textasciitilde{}:mtcars}, and dplyr-style chains on R objects.
305
- You do not need to learn R syntax to get a lot done, though reading R
306
- documentation for individual packages remains useful.
329
+ \texttt{\textasciitilde{}R{[}:mtcars{]}}, and dplyr-style chains on R
330
+ objects. You do not need to learn R syntax to get a lot done, though
331
+ reading R documentation for individual packages remains useful.
307
332
 
308
333
  Earlier experiments with Galaaz used Oracle's \textbf{GraalVM} with
309
334
  TruffleRuby and FastR so that Ruby and R could share one runtime. That
310
335
  path is no longer the focus: \textbf{standard GNU R} gives full
311
336
  compatibility with the R package ecosystem (including compiled
312
- extensions and Bioconductor) while JRuby gives a mature Ruby with
313
- \textbf{real multithreading} for application and I/O code.
337
+ extensions and Bioconductor) while either Ruby engine talks to R over
338
+ NewBridge (JRuby for mature multithreading on the application side;
339
+ CRuby when you prefer MRI).
314
340
 
315
341
  The bridge handles \textbf{communication and typing} between the two
316
342
  worlds; large tables can also flow through \textbf{Apache Arrow} on the
@@ -356,12 +382,15 @@ the gemspec: \textbf{\texttt{galaaz}}, \textbf{\texttt{gstudio}},
356
382
  \textbf{\texttt{gknit-draft}}); for development and CI, prefer the
357
383
  \textbf{\texttt{bin/}} copies so JVM flags and paths stay correct.
358
384
 
359
- Below, \textbf{current (Galaaz 2.0 + JRuby + GNU R)} means the tool is
360
- wired to \textbf{\texttt{jruby}} and
361
- \textbf{\texttt{bin/galaaz\_jruby\_env.inc.sh}} (or equivalent logic in
362
- Ruby via \texttt{lib/galaaz\_jruby.rb}). \textbf{Legacy} means the
363
- script still targets \textbf{GraalVM} polyglot Ruby / FastR-era
364
- invocation and is \textbf{not} expected to work on a typical JRuby-only
385
+ Below, \textbf{current (Galaaz 2.0 + JRuby or CRuby + GNU R)} means the
386
+ tool uses \textbf{\texttt{bin/galaaz-ruby}} /
387
+ \textbf{\texttt{GALAAZ\_RUBY}} (default: \texttt{ruby} on \texttt{PATH})
388
+ and applies JVM flags only when the interpreter is JRuby
389
+ (\texttt{bin/galaaz\_jruby\_env.inc.sh} /
390
+ \texttt{lib/galaaz\_jruby.rb}). \textbf{\texttt{bin/galaaz-jruby}}
391
+ forces JRuby. \textbf{Legacy} means the script still targets
392
+ \textbf{GraalVM} polyglot Ruby / FastR-era invocation and is
393
+ \textbf{not} expected to work on a typical JRuby or CRuby NewBridge
365
394
  setup.
366
395
 
367
396
  \textbf{Table layout:} names in the first column are
@@ -371,8 +400,8 @@ options and examples sit \textbf{outside} the tables so PDF columns stay
371
400
  readable.
372
401
 
373
402
  \begin{verbatim}
374
- ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
375
- ## resized.
403
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable
404
+ ## cannot be resized.
376
405
  \end{verbatim}
377
406
 
378
407
  \begingroup\fontsize{9}{11}\selectfont
@@ -381,9 +410,9 @@ readable.
381
410
  \toprule
382
411
  Script & Role & 2.0?\\
383
412
  \midrule
384
- galaaz-bootstrap & WSL2 helper: Docker checks; optional TinyTeX or poppler for gKnit PDF. & Yes*\\
385
- galaaz-jruby & JRuby with repo lib/ on LOAD\_PATH and required JVM flags (e.g. Arrow). & Yes\\
386
- galaaz\_jruby\_env.inc.sh & Sourced by bash wrappers; sets GALAAZ\_REQUIRED\_JRUBY\_J\_ARGS. & Yes†\\
413
+ galaaz-bootstrap & WSL2 helper: Docker checks; optional TinyTeX/poppler. & Yes*\\
414
+ galaaz-jruby & JRuby with repo lib/ on LOAD\_PATH and JVM flags. & Yes\\
415
+ galaaz\_jruby\_env.inc.sh & Sourced by bash wrappers; sets JRUBY\_J\_ARGS. & Yes†\\
387
416
  install-tinytex & Install TinyTeX for PDF output. & Yes\\
388
417
  \bottomrule
389
418
  \end{longtable}
@@ -409,8 +438,8 @@ install-tinytex & Install TinyTeX for PDF output. & Yes\\
409
438
  Rake}\label{interactive-use-examples-and-rake}
410
439
 
411
440
  \begin{verbatim}
412
- ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
413
- ## resized.
441
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable
442
+ ## cannot be resized.
414
443
  \end{verbatim}
415
444
 
416
445
  \begingroup\fontsize{9}{11}\selectfont
@@ -429,8 +458,8 @@ galaaz & Forward arguments to rake (needs rake; usually JRuby). & Yes\\
429
458
  \subsection{gKnit and document drafts}\label{gknit-and-document-drafts}
430
459
 
431
460
  \begin{verbatim}
432
- ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
433
- ## resized.
461
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable
462
+ ## cannot be resized.
434
463
  \end{verbatim}
435
464
 
436
465
  \begingroup\fontsize{9}{11}\selectfont
@@ -440,7 +469,7 @@ galaaz & Forward arguments to rake (needs rake; usually JRuby). & Yes\\
440
469
  Script & Role & 2.0?\\
441
470
  \midrule
442
471
  gknit & Knit .Rmd via JRuby and R Markdown render. & Yes\\
443
- gknit-draft & Drafts from rticles-style templates; wrapper still uses legacy polyglot ruby. & Legacy\\
472
+ gknit-draft & Drafts from rticles templates; legacy polyglot wrapper. & Legacy\\
444
473
  gknit-draft.rb & Ruby entry: GKnit.draft (use with JRuby + LOAD\_PATH). & JRuby\\
445
474
  gknit\_Rscript & Polyglot Rscript launcher; hard-coded LOAD\_PATH sample. & No\\
446
475
  \bottomrule
@@ -459,8 +488,8 @@ workflows until that wrapper matches the \textbf{\texttt{gknit}} stack.
459
488
  \subsection{Tests}\label{tests}
460
489
 
461
490
  \begin{verbatim}
462
- ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
463
- ## resized.
491
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable
492
+ ## cannot be resized.
464
493
  \end{verbatim}
465
494
 
466
495
  \begingroup\fontsize{9}{11}\selectfont
@@ -470,7 +499,7 @@ workflows until that wrapper matches the \textbf{\texttt{gknit}} stack.
470
499
  Script & Role & 2.0?\\
471
500
  \midrule
472
501
  run\_rspec & Top-level specs/*\_spec.rb with spec\_helper (see docs/testing.md). & Yes\\
473
- run\_all\_rspec & Compile ext/new\_bridge; run specs/ and new\_bridge\_specs/ together. & Yes\\
502
+ run\_all\_rspec & Compile ext/new\_bridge; run specs/ and new\_bridge\_specs/. & Yes\\
474
503
  run\_slow\_rspec & Suites under slow-specs/ (read script header for spec\_helper). & Yes\\
475
504
  run\_old\_rspec & Legacy suites under old\_specs/. & Yes\\
476
505
  run\_rspec\_subset & Numbered subset 1–18 (Documentation/Spec\_Subsets.md). & Yes\\
@@ -481,8 +510,8 @@ run\_rspec\_subset & Numbered subset 1–18 (Documentation/Spec\_Subsets.md). &
481
510
  \subsection{Other}\label{other}
482
511
 
483
512
  \begin{verbatim}
484
- ## Warning in styling_latex_scale(out, table_info, "down"): Longtable cannot be
485
- ## resized.
513
+ ## Warning in styling_latex_scale(out, table_info, "down"): Longtable
514
+ ## cannot be resized.
486
515
  \end{verbatim}
487
516
 
488
517
  \begingroup\fontsize{9}{11}\selectfont
@@ -491,14 +520,15 @@ run\_rspec\_subset & Numbered subset 1–18 (Documentation/Spec\_Subsets.md). &
491
520
  \toprule
492
521
  Script & Role & 2.0?\\
493
522
  \midrule
494
- grun & Graal-era launcher: polyglot ruby with --jvm. Use galaaz-jruby -S instead. & No\\
523
+ grun & Graal-era launcher: polyglot ruby --jvm; prefer galaaz-jruby. & No\\
495
524
  gstudio\_irb.rb / gstudio\_pry.rb & Loaded by gstudio; not meant to be run standalone. & Yes\\
496
525
  \bottomrule
497
526
  \end{longtable}
498
527
  \endgroup{}
499
528
 
500
529
  For day-to-day \textbf{2.0} use, rely on
501
- \textbf{\texttt{bin/galaaz-jruby}}, \textbf{\texttt{bin/gstudio}},
530
+ \textbf{\texttt{bin/galaaz-ruby}} (or \textbf{\texttt{bin/galaaz-jruby}}
531
+ when you want to force JRuby), \textbf{\texttt{bin/gstudio}},
502
532
  \textbf{\texttt{bin/gknit}}, \textbf{\texttt{bin/run\_example}},
503
533
  \textbf{\texttt{bin/run\_rspec}} /
504
534
  \textbf{\texttt{bin/run\_all\_rspec}}, and
@@ -506,7 +536,7 @@ For day-to-day \textbf{2.0} use, rely on
506
536
  Treat \textbf{\texttt{grun}}, \textbf{\texttt{gknit\_Rscript}}, and the
507
537
  polyglot \textbf{\texttt{ruby}} invocation in
508
538
  \textbf{\texttt{gknit-draft}} as \textbf{legacy} until they are ported
509
- to the same JRuby path as \textbf{\texttt{gknit}}.
539
+ to the same launcher path as \textbf{\texttt{gknit}}.
510
540
 
511
541
  \section{System Compatibility}\label{system-compatibility}
512
542
 
@@ -518,7 +548,8 @@ Typical development and CI targets:
518
548
  \textbf{Linux} --- recent Ubuntu LTS or comparable distributions
519
549
  (x86\_64).
520
550
  \item
521
- \textbf{macOS} --- recent releases with JRuby and GNU R available.
551
+ \textbf{macOS} --- recent releases with JRuby or CRuby and GNU R
552
+ available.
522
553
  \item
523
554
  \textbf{Windows} --- use \textbf{WSL2} (same Linux stack as above);
524
555
  native Windows is not the primary target.
@@ -533,16 +564,19 @@ is built with \texttt{make} and a C++ toolchain; see the project
533
564
  \begin{itemize}
534
565
  \tightlist
535
566
  \item
536
- \textbf{JRuby} --- Ruby implementation on the JVM (Galaaz 2.0 is
537
- developed and tested with JRuby).
567
+ \textbf{Ruby} --- \textbf{JRuby} or \textbf{CRuby} (both supported for
568
+ NewBridge). Tested with \textbf{JRuby 10.1.1.0} (+ \textbf{JDK 21})
569
+ and \textbf{CRuby 3.3.12}. Use \texttt{bin/galaaz-ruby} (honors
570
+ \texttt{GALAAZ\_RUBY}) or plain \texttt{gem\ install\ galaaz} under
571
+ the Ruby you choose.
538
572
  \item
539
- A \textbf{Java runtime} (JDK) compatible with your JRuby version.
573
+ \textbf{GNU R} --- \texttt{R} and \texttt{Rscript} on your
574
+ \texttt{PATH} (tested with \textbf{4.3.3}), plus a C++ toolchain
575
+ (\texttt{g++}, \texttt{make}) and the \textbf{Rcpp} package to compile
576
+ the gatekeeper.
540
577
  \item
541
- \textbf{GNU R} --- \texttt{R} on your \texttt{PATH}, with ability to
542
- install packages (CRAN / Bioconductor as needed).
543
- \item
544
- \textbf{Ruby gems} --- from the Galaaz repository,
545
- \texttt{bundle\ install} (see the \texttt{Gemfile} / gemspec).
578
+ \textbf{galaaz gem} --- runtime dependency \texttt{msgpack} is pulled
579
+ in by \texttt{gem\ install}.
546
580
  \item
547
581
  Optional: \textbf{Docker} --- if you run R in a container (common on
548
582
  WSL2); see bootstrap below.
@@ -555,43 +589,92 @@ is built with \texttt{make} and a C++ toolchain; see the project
555
589
 
556
590
  \section{Installation}\label{installation}
557
591
 
558
- From a clone of the Galaaz repository:
592
+ The supported install is \textbf{\texttt{gem\ install} + compile the
593
+ gatekeeper}. You do not need a git clone.
559
594
 
560
595
  \begin{enumerate}
561
596
  \def\labelenumi{\arabic{enumi}.}
562
- \tightlist
563
597
  \item
564
- Install \textbf{JRuby} and \textbf{GNU R} using your preferred package
565
- manager or Ruby version manager.
598
+ Install \textbf{JRuby} (and a compatible \textbf{JDK}) \textbf{or
599
+ CRuby 3.3+}, plus \textbf{GNU R} (with \texttt{Rscript} and a C++
600
+ compiler).
566
601
  \item
567
- Install \textbf{bundler} if needed, then run
568
- \textbf{\texttt{bundle\ install}} in the repository root.
602
+ In R, install \textbf{Rcpp}: \texttt{install.packages("Rcpp")}.
569
603
  \item
570
- Build the bridge native code:
571
- \textbf{\texttt{make\ -C\ ext/new\_bridge\ all}} (or
572
- \textbf{\texttt{rake\ compile\_gatekeeper}}).
604
+ Install the gem: \texttt{jruby\ -S\ gem\ install\ galaaz} (or
605
+ \texttt{gem\ install\ galaaz} under CRuby).
573
606
  \item
574
- Run Ruby scripts with the project load path and JVM flags the project
575
- expects --- the \textbf{\texttt{bin/galaaz-jruby}} wrapper sources
576
- \textbf{\texttt{bin/galaaz\_jruby\_env.inc.sh}} and adds
577
- \textbf{\texttt{-I\ lib}}. This matters especially for \textbf{Apache
578
- Arrow} integration (see \texttt{docs/testing.md}).
607
+ Compile the native gatekeeper from the installed gem:
608
+
609
+ \begin{verbatim}
610
+ gem_dir="$(ruby -e "puts Gem::Specification.find_by_name('galaaz').full_gem_path")"
611
+ # under JRuby: gem_dir="$(jruby -e "puts Gem::Specification.find_by_name('galaaz').full_gem_path")"
612
+ make -C "${gem_dir}/ext/new_bridge" all
613
+ \end{verbatim}
579
614
  \item
580
615
  Ensure \textbf{\texttt{R}} starts GNU R and can install packages
581
- (network access to CRAN mirrors when you first call
582
- \texttt{R.install\_and\_loads}).
616
+ (network access to CRAN when you first call
617
+ \texttt{R.install\_and\_loads}). For \textbf{Apache Arrow} on
618
+ \textbf{JRuby} (Java 9+), the child JVM needs
619
+ \texttt{-\/-add-opens=java.base/java.nio=ALL-UNNAMED} via
620
+ \textbf{\texttt{JAVA\_OPTS}} (from a checkout,
621
+ \texttt{bin/galaaz-jruby} and \texttt{mise.toml} set this; a leading
622
+ \texttt{jruby\ -J...\ -S\ bundle\ exec} does \textbf{not} pass
623
+ \texttt{-J} to rspec). On \textbf{CRuby}, install Apache Arrow GLib
624
+ (\texttt{libarrow-glib-dev} from the
625
+ \href{https://arrow.apache.org/install/}{Apache Arrow APT} repo) and
626
+ \texttt{gem\ install\ red-arrow} matching
627
+ \texttt{pkg-config\ -\/-modversion\ arrow-glib}. Do not install the
628
+ unrelated Rubygems package named \texttt{arrow}.
583
629
  \end{enumerate}
584
630
 
585
631
  For \textbf{gKnit}, \textbf{knitr}, \textbf{rmarkdown}, and LaTeX (PDF
586
- output), install the corresponding R packages and a TeX distribution if
587
- you need PDF; the repository includes helpers such as
588
- \textbf{\texttt{bin/install-tinytex}} where appropriate.
632
+ output), install the corresponding R packages, \textbf{Pandoc}, and a
633
+ TeX distribution if you need PDF; the repository includes helpers such
634
+ as \textbf{\texttt{bin/install-tinytex}} where appropriate.
589
635
 
590
- A \textbf{table of all \texttt{bin/} scripts} (bootstrap, JRuby wrapper,
636
+ A \textbf{table of all \texttt{bin/} scripts} (bootstrap, Ruby launcher,
591
637
  gstudio, gknit, test runners, and which ones are legacy) is in the
592
638
  section \textbf{Command-line tools (\texttt{bin/})} earlier in this
593
639
  manual.
594
640
 
641
+ \subsubsection{From a repository checkout
642
+ (contributors)}\label{from-a-repository-checkout-contributors}
643
+
644
+ \begin{enumerate}
645
+ \def\labelenumi{\arabic{enumi}.}
646
+ \tightlist
647
+ \item
648
+ Install \textbf{bundler} if needed, then run
649
+ \textbf{\texttt{bundle\ install}} with your chosen Ruby
650
+ (\texttt{jruby\ -S\ bundle\ install} or CRuby
651
+ \texttt{bundle\ install}) in the repository root.
652
+ \item
653
+ Build the bridge native code:
654
+ \textbf{\texttt{make\ -C\ ext/new\_bridge\ all}} (or
655
+ \textbf{\texttt{rake\ compile\_gatekeeper}}).
656
+ \item
657
+ Run scripts with \textbf{\texttt{bin/galaaz-ruby}} (uses \texttt{ruby}
658
+ on \texttt{PATH}; set \textbf{\texttt{GALAAZ\_RUBY=jruby}} or
659
+ \textbf{\texttt{GALAAZ\_RUBY=ruby}} to force an engine). Spec runners:
660
+ \textbf{\texttt{bin/run\_rspec}} /
661
+ \textbf{\texttt{bin/run\_all\_rspec}} (same \texttt{GALAAZ\_RUBY}
662
+ rule). \textbf{\texttt{bin/galaaz-jruby}} remains a thin wrapper that
663
+ forces JRuby.
664
+ \end{enumerate}
665
+
666
+ A \textbf{gstudio} try image with Galaaz already installed is available
667
+ for both engines: \textbf{JRuby} ---
668
+ \texttt{docker\ run\ -\/-rm\ -it\ ghcr.io/rbotafogo/galaaz-try:gstudio}
669
+ (or \texttt{./docker/try-gstudio/run.sh} from a checkout);
670
+ \textbf{CRuby} ---
671
+ \texttt{docker\ run\ -\/-rm\ -it\ ghcr.io/rbotafogo/galaaz-try:cruby}
672
+ (or \texttt{./docker/try-cruby/run.sh}). Maintainers can prove a
673
+ RubyGems install on a throwaway Ubuntu machine (no repo inside the
674
+ container) with \texttt{./docker/cold-install/run.sh\ published-specs}
675
+ (JRuby) or \texttt{./docker/cold-install-cruby/run.sh\ published-specs}
676
+ (CRuby).
677
+
595
678
  \subsection{Windows + WSL2 (optional: Docker / R in a
596
679
  container)}\label{windows-wsl2-optional-docker-r-in-a-container}
597
680
 
@@ -651,12 +734,42 @@ installed.
651
734
  \begin{Highlighting}[]
652
735
  \NormalTok{ vec }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{)}
653
736
  \FunctionTok{puts}\NormalTok{ vec}
737
+
738
+ \CommentTok{\# R.foo(...) calls an R *function*. Datasets are objects — fetch with}
739
+ \CommentTok{\# \textasciitilde{}:}
740
+ \NormalTok{ df }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}
741
+ \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.summary}\NormalTok{(df)}
654
742
  \end{Highlighting}
655
743
  \end{Shaded}
656
744
 
657
745
  \begin{verbatim}
658
746
  ## [1] 1 2 3 4
659
- \end{verbatim}
747
+ ## mpg cyl disp hp
748
+ ## Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0
749
+ ## 1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5
750
+ ## Median :19.20 Median :6.000 Median :196.3 Median :123.0
751
+ ## Mean :20.09 Mean :6.188 Mean :230.7 Mean :146.7
752
+ ## 3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0
753
+ ## Max. :33.90 Max. :8.000 Max. :472.0 Max. :335.0
754
+ ## drat wt qsec vs
755
+ ## Min. :2.760 Min. :1.513 Min. :14.50 Min. :0.0000
756
+ ## 1st Qu.:3.080 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:0.0000
757
+ ## Median :3.695 Median :3.325 Median :17.71 Median :0.0000
758
+ ## Mean :3.597 Mean :3.217 Mean :17.85 Mean :0.4375
759
+ ## 3rd Qu.:3.920 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:1.0000
760
+ ## Max. :4.930 Max. :5.424 Max. :22.90 Max. :1.0000
761
+ ## am gear carb
762
+ ## Min. :0.0000 Min. :3.000 Min. :1.000
763
+ ## 1st Qu.:0.0000 1st Qu.:3.000 1st Qu.:2.000
764
+ ## Median :0.0000 Median :4.000 Median :2.000
765
+ ## Mean :0.4062 Mean :3.688 Mean :2.812
766
+ ## 3rd Qu.:1.0000 3rd Qu.:4.000 3rd Qu.:4.000
767
+ ## Max. :1.0000 Max. :5.000 Max. :8.000
768
+ \end{verbatim}
769
+
770
+ (\texttt{R.mtcars} is wrong: it becomes \texttt{mtcars()} in R and
771
+ fails. With \texttt{using\ Galaaz::SymbolDSL}, the short form
772
+ \texttt{\textasciitilde{}:mtcars} also works.)
660
773
 
661
774
  \begin{itemize}
662
775
  \item
@@ -697,13 +810,16 @@ installed.
697
810
  \end{quote}
698
811
  \end{itemize}
699
812
 
700
- \section{JRuby, multithreading, and the R
701
- bridge}\label{jruby-multithreading-and-the-r-bridge}
813
+ \section{JRuby, CRuby, multithreading, and the R
814
+ bridge}\label{jruby-cruby-multithreading-and-the-r-bridge}
702
815
 
703
- Galaaz 2.0 runs Ruby on \textbf{JRuby}, so your application can use
704
- \textbf{real parallel threads} for I/O-bound work (HTTP clients,
705
- database connections, message consumers, and so on). R itself is still
706
- executed in a \textbf{single GNU R process} behind the Galaaz bridge.
816
+ Galaaz 2.0 supports \textbf{JRuby} and \textbf{CRuby} equally for
817
+ NewBridge. On \textbf{JRuby}, your application can use \textbf{real
818
+ parallel threads} for I/O-bound work (HTTP clients, database
819
+ connections, message consumers, and so on). On \textbf{CRuby}, prefer
820
+ multi-process scaling for CPU-bound concurrency. R itself is still
821
+ executed in a \textbf{single GNU R process} behind the Galaaz bridge
822
+ (use multiple R workers when you need more R throughput).
707
823
 
708
824
  When several Ruby threads call into R at the same time, the bridge
709
825
  \textbf{serializes} those calls: each request is matched to a reply
@@ -739,9 +855,15 @@ bridge itself, see \texttt{specs/bridge\_concurrent\_spec.rb} and
739
855
  \subsection{Long-running R calls and a completion
740
856
  block}\label{long-running-r-calls-and-a-completion-block}
741
857
 
742
- For R work that can take a long time, the bridge can avoid a Ruby-side
743
- \textbf{wait timeout} by scheduling the call and resuming in a
744
- \textbf{block} when the \texttt{RET} arrives.
858
+ For R work that can take a long time \textbf{on the bridge}, the bridge
859
+ can avoid a Ruby-side \textbf{wait timeout} by scheduling the call and
860
+ resuming in a \textbf{block} when the \texttt{RET} arrives.
861
+
862
+ \textbf{Important distinction:} this keeps the \textbf{same} GNU R
863
+ process busy. Other sync \texttt{eval\_r} / gknit chunks still wait on
864
+ that R. For CRAN installs and other work that must \textbf{not}
865
+ monopolize the bridge (or that can OOM a small VM if abandoned
866
+ mid-compile), use \textbf{\texttt{R::Job}} in the next section instead.
745
867
 
746
868
  \begin{itemize}
747
869
  \tightlist
@@ -789,9 +911,11 @@ error.)
789
911
 
790
912
  \ConstantTok{R}\AttributeTok{.eval\_r\_async}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}(\{ Sys.sleep(0.3); 42L \})\textquotesingle{}}\NormalTok{, }\WarningTok{timeout:} \DecValTok{nil}\NormalTok{) }\ControlFlowTok{do} \OperatorTok{|}\NormalTok{result}\OperatorTok{|}
791
913
  \ControlFlowTok{if}\NormalTok{ result}\AttributeTok{.ok?}
792
- \FunctionTok{puts} \StringTok{"[completion] R finished; eval\_r{-}style value: }\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.value.inspect}\SpecialCharTok{\}}\StringTok{"}
914
+ \FunctionTok{puts} \StringTok{"[completion] R finished; value: "} \OperatorTok{+}
915
+ \StringTok{"}\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.value.inspect}\SpecialCharTok{\}}\StringTok{"}
793
916
  \ControlFlowTok{else}
794
- \FunctionTok{puts} \StringTok{"[completion] R/bridge error: }\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.error.class}\SpecialCharTok{\}}\StringTok{: }\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.error.message}\SpecialCharTok{\}}\StringTok{"}
917
+ \FunctionTok{puts} \StringTok{"[completion] R/bridge error: "} \OperatorTok{+}
918
+ \StringTok{"}\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.error.class}\SpecialCharTok{\}}\StringTok{: }\SpecialCharTok{\#\{}\NormalTok{result}\AttributeTok{.error.message}\SpecialCharTok{\}}\StringTok{"}
795
919
  \ControlFlowTok{end}
796
920
  \NormalTok{ completion}\AttributeTok{.push}\NormalTok{(}\WarningTok{:done}\NormalTok{)}
797
921
  \ControlFlowTok{end}
@@ -810,7 +934,7 @@ error.)
810
934
  ## [main] other Ruby work step 1
811
935
  ## [main] other Ruby work step 2
812
936
  ## [main] other Ruby work step 3
813
- ## [completion] R finished; eval_r-style value: "[1] 42"
937
+ ## [completion] R finished; value: "[1] 42"
814
938
  ## [main] R completion has run; exiting.
815
939
  \end{verbatim}
816
940
 
@@ -823,56 +947,419 @@ exists (inside the block, or after data written there is observed
823
947
  elsewhere). Runnable specs live in
824
948
  \textbf{\texttt{new\_bridge\_specs/eval\_r\_async\_spec.rb}}.
825
949
 
950
+ \subsection{\texorpdfstring{Background R jobs
951
+ (\texttt{R::Job})}{Background R jobs (R::Job)}}\label{background-r-jobs-rjob}
952
+
953
+ \texttt{R::Async} / \texttt{R.eval\_r\_async} free the \textbf{Ruby}
954
+ thread while the \textbf{same} bridge R process runs your code. That is
955
+ enough for Rails-style ``don't block the request thread,'' but not
956
+ enough for heavy \texttt{install.packages} or multi-minute model fits:
957
+ the gatekeeper R is still busy, other chunks time out, and abandoning
958
+ the wait can leave compile work burning RAM.
959
+
960
+ \textbf{\texttt{R::Job}} runs that work in a \textbf{child
961
+ \texttt{Rscript} process}. The bridge stays free. Logs and metadata live
962
+ under \texttt{\textasciitilde{}/.local/share/galaaz/jobs/} (override
963
+ with \texttt{GALAAZ\_JOBS\_DIR}).
964
+
965
+ \subsubsection{Package installs}\label{package-installs}
966
+
967
+ \texttt{R.install\_and\_loads} / \texttt{R.install\_rlibs} use
968
+ \texttt{R::Job.install} and \textbf{await until the child finishes}
969
+ (default: no wall-clock limit). Optional limit:
970
+ \texttt{GALAAZ\_INSTALL\_TIMEOUT\_SEC} or
971
+ \texttt{install\_timeout\_sec:}. On timeout the child process group is
972
+ killed so leftover \texttt{make}/\texttt{gcc} cannot OOM the shell.
973
+ Stale \texttt{00LOCK-*} dirs are cleared before the next install. Only
974
+ one install runs at a time (\texttt{install.lock}).
975
+
976
+ \begin{Shaded}
977
+ \begin{Highlighting}[]
978
+ \CommentTok{\# May take a long time the first time (e.g. caret); the bridge is not}
979
+ \CommentTok{\# used for compile.}
980
+ \ConstantTok{R}\AttributeTok{.install\_and\_loads} \VerbatimStringTok{\textquotesingle{}caret\textquotesingle{}}
981
+ \end{Highlighting}
982
+ \end{Shaded}
983
+
984
+ \subsubsection{\texorpdfstring{Long arbitrary R (\texttt{eval} /
985
+ \texttt{script})}{Long arbitrary R (eval / script)}}\label{long-arbitrary-r-eval-script}
986
+
987
+ Prefer the \textbf{block} form (like \texttt{File.open}): await the
988
+ child, yield the job, return the block's value. Without a block, the
989
+ methods still await by default and return the \texttt{Job}.
990
+
991
+ \begin{Shaded}
992
+ \begin{Highlighting}[]
993
+ \NormalTok{coef }\OperatorTok{=} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Job}\AttributeTok{.eval}\NormalTok{(}\OperatorTok{\textless{}\textless{}\textasciitilde{}}\ControlFlowTok{R}\DocumentationTok{) \{ |job| job.load\_rds \}}
994
+ \DocumentationTok{ fit \textless{}{-} lm(mpg \textasciitilde{} wt, data = mtcars)}
995
+ \DocumentationTok{ saveRDS(unname(coef(fit)), result\_path)}
996
+ \ControlFlowTok{R}
997
+ \FunctionTok{puts}\NormalTok{ coef}
998
+ \end{Highlighting}
999
+ \end{Shaded}
1000
+
1001
+ \begin{verbatim}
1002
+ ## Permission denied - /home/rbotafogo/.local/share/galaaz/jobs/eval-20260908T145009-4153-db9080
1003
+ \end{verbatim}
1004
+
1005
+ \begin{verbatim}
1006
+ ## org/jruby/RubyDir.java:693:in 'mkdir'
1007
+ ## /home/rbotafogo/.asdf/installs/ruby/jruby-10.1.1.0/lib/ruby/stdlib/fileutils.rb:403:in 'fu_mkdir'
1008
+ ## /home/rbotafogo/.asdf/installs/ruby/jruby-10.1.1.0/lib/ruby/stdlib/fileutils.rb:381:in 'block in mkdir_p'
1009
+ ## org/jruby/RubyArrayNative.java:1807:in 'reverse_each'
1010
+ ## /home/rbotafogo/.asdf/installs/ruby/jruby-10.1.1.0/lib/ruby/stdlib/fileutils.rb:379:in 'block in mkdir_p'
1011
+ ## org/jruby/RubyArrayNative.java:1729:in 'each'
1012
+ ## /home/rbotafogo/.asdf/installs/ruby/jruby-10.1.1.0/lib/ruby/stdlib/fileutils.rb:371:in 'mkdir_p'
1013
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/r_job.rb:140:in 'initialize'
1014
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/r_job.rb:94:in 'eval'
1015
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:170:in 'exec_ruby'
1016
+ ## org/jruby/RubyKernel.java:1459:in 'eval'
1017
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:169:in 'exec_ruby'
1018
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:777:in 'block in initialize'
1019
+ ## org/jruby/RubyBasicObject.java:2713:in 'instance_eval'
1020
+ ## org/jruby/RubyBasicObject.java:2741:in 'instance_eval'
1021
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:748:in 'block in initialize'
1022
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/new_bridge_adapter.rb:371:in 'block in register_callback_proc_stub'
1023
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/new_bridge/session_client.rb:458:in 'block in handle_call'
1024
+ \end{verbatim}
1025
+
1026
+ \begin{Shaded}
1027
+ \begin{Highlighting}[]
1028
+ \CommentTok{\# Without a block: awaits (wait: true is the default) and returns the}
1029
+ \CommentTok{\# Job}
1030
+ \NormalTok{job }\OperatorTok{=} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Job}\AttributeTok{.eval}\NormalTok{(code)}
1031
+ \NormalTok{job }\OperatorTok{=} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Job}\AttributeTok{.eval}\NormalTok{(code, }\WarningTok{wait:} \DecValTok{false}\NormalTok{) }\CommentTok{\# start only; call job.wait later}
1032
+
1033
+ \CommentTok{\# Script file; trailing args → commandArgs(trailingOnly=TRUE) in the}
1034
+ \CommentTok{\# child}
1035
+ \NormalTok{res }\OperatorTok{=} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Job}\AttributeTok{.script}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}train.R\textquotesingle{}}\NormalTok{, }\CharTok{\textquotesingle{}5\textquotesingle{}}\NormalTok{) }\OperatorTok{\{} \OperatorTok{|}\NormalTok{job}\OperatorTok{|}\NormalTok{ job}\AttributeTok{.load\_rds} \OperatorTok{\}}
1036
+ \end{Highlighting}
1037
+ \end{Shaded}
1038
+
1039
+ In the child: \texttt{setwd(job.dir)}, \texttt{.libPaths} includes the
1040
+ Galaaz user library, \texttt{GALAAZ\_JOB\_DIR} is set, and
1041
+ \textbf{\texttt{result\_path}} defaults to
1042
+ \texttt{file.path(GALAAZ\_JOB\_DIR,\ "result.rds")}. Persist with
1043
+ \texttt{saveRDS(...,\ result\_path)}, then load on the bridge with
1044
+ \textbf{\texttt{job.load\_rds}} (short sync \texttt{readRDS} → a normal
1045
+ Galaaz R object).
1046
+
1047
+ \subsubsection{Choosing async vs Job}\label{choosing-async-vs-job}
1048
+
1049
+ {\def\LTcaptype{none} % do not increment counter
1050
+ \begin{longtable}[]{@{}
1051
+ >{\raggedright\arraybackslash}p{(\linewidth - 2\tabcolsep) * \real{0.5455}}
1052
+ >{\raggedright\arraybackslash}p{(\linewidth - 2\tabcolsep) * \real{0.4545}}@{}}
1053
+ \toprule\noalign{}
1054
+ \begin{minipage}[b]{\linewidth}\raggedright
1055
+ Need
1056
+ \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
1057
+ Use
1058
+ \end{minipage} \\
1059
+ \midrule\noalign{}
1060
+ \endhead
1061
+ \bottomrule\noalign{}
1062
+ \endlastfoot
1063
+ Don't freeze a Ruby thread; short/medium R on the bridge is OK &
1064
+ \texttt{R::Async} / \texttt{R.eval\_r\_async} \\
1065
+ Install CRAN packages, or long R that must not block the bridge &
1066
+ \texttt{R::Job} / \texttt{R.install\_and\_loads} \\
1067
+ \end{longtable}
1068
+ }
1069
+
1070
+ \subsection{Galaaz + Rails (R-on-Rails) integration
1071
+ baseline}\label{galaaz-rails-r-on-rails-integration-baseline}
1072
+
1073
+ This is the practical \textbf{R-on-Rails} starter: an R scientist's
1074
+ analysis behind a small Rails app. The baseline we used in WSL aimed at:
1075
+
1076
+ \begin{enumerate}
1077
+ \def\labelenumi{\arabic{enumi}.}
1078
+ \tightlist
1079
+ \item
1080
+ Rails boots under \textbf{JRuby or CRuby} (same bridge; see
1081
+ Installation).
1082
+ \item
1083
+ Galaaz is loaded from a local checkout (before publishing to
1084
+ RubyGems).
1085
+ \item
1086
+ A request path can execute \textbf{\texttt{R.eval(...)}} and return a
1087
+ result.
1088
+ \end{enumerate}
1089
+
1090
+ \subsubsection{1) Create the app with Ruby-friendly
1091
+ options}\label{create-the-app-with-ruby-friendly-options}
1092
+
1093
+ Rails defaults can pull gems that are awkward on some setups (for
1094
+ example sqlite native extension paths on JRuby, or deployment extras you
1095
+ do not need). A minimal app avoids early friction:
1096
+
1097
+ \begin{Shaded}
1098
+ \begin{Highlighting}[]
1099
+ \BuiltInTok{cd}\NormalTok{ /home/rbotafogo/desenv\_linux}
1100
+ \ExtensionTok{jruby} \AttributeTok{{-}S}\NormalTok{ rails new hedi }\AttributeTok{{-}{-}skip{-}git} \AttributeTok{{-}{-}minimal} \DataTypeTok{\textbackslash{}}
1101
+ \AttributeTok{{-}{-}skip{-}kamal} \AttributeTok{{-}{-}skip{-}solid} \AttributeTok{{-}{-}skip{-}active{-}record}
1102
+ \end{Highlighting}
1103
+ \end{Shaded}
1104
+
1105
+ Then install gems:
1106
+
1107
+ \begin{Shaded}
1108
+ \begin{Highlighting}[]
1109
+ \BuiltInTok{cd}\NormalTok{ /home/rbotafogo/desenv\_linux/hedi}
1110
+ \ExtensionTok{jruby} \AttributeTok{{-}S}\NormalTok{ bundle install}
1111
+ \end{Highlighting}
1112
+ \end{Shaded}
1113
+
1114
+ \subsubsection{2) Use Galaaz as a local path
1115
+ gem}\label{use-galaaz-as-a-local-path-gem}
1116
+
1117
+ For local development we keep a stable path:
1118
+
1119
+ \begin{itemize}
1120
+ \tightlist
1121
+ \item
1122
+ \texttt{\textasciitilde{}/gems/galaaz} -\textgreater{} symlink to your
1123
+ Galaaz checkout
1124
+ \item
1125
+ optional built gem archive in \texttt{\textasciitilde{}/gems/pkg/}
1126
+ \end{itemize}
1127
+
1128
+ In Rails \texttt{Gemfile}:
1129
+
1130
+ \begin{Shaded}
1131
+ \begin{Highlighting}[]
1132
+ \NormalTok{gem }\StringTok{"galaaz"}\NormalTok{, }\WarningTok{path:} \StringTok{"/home/rbotafogo/gems/galaaz"}\NormalTok{, }\WarningTok{require:} \DecValTok{false}
1133
+ \end{Highlighting}
1134
+ \end{Shaded}
1135
+
1136
+ And load after Rails boot in \texttt{config/application.rb}:
1137
+
1138
+ \begin{Shaded}
1139
+ \begin{Highlighting}[]
1140
+ \NormalTok{config}\AttributeTok{.after\_initialize} \OperatorTok{\{} \FunctionTok{require} \StringTok{"galaaz"} \OperatorTok{\}}
1141
+ \end{Highlighting}
1142
+ \end{Shaded}
1143
+
1144
+ Why \texttt{require:\ false} + \texttt{after\_initialize}? In this
1145
+ integration, loading Galaaz too early via \texttt{Bundler.require}
1146
+ triggered Rails/JRuby initialization failures.
1147
+
1148
+ \subsubsection{3) Simple request-path smoke
1149
+ test}\label{simple-request-path-smoke-test}
1150
+
1151
+ A direct smoke test from Rails runner:
1152
+
1153
+ \begin{Shaded}
1154
+ \begin{Highlighting}[]
1155
+ \BuiltInTok{cd}\NormalTok{ /home/rbotafogo/desenv\_linux/hedi}
1156
+ \ExtensionTok{jruby} \AttributeTok{{-}S}\NormalTok{ bundle exec rails runner }\DataTypeTok{\textbackslash{}}
1157
+ \StringTok{"puts R.eval(\textquotesingle{}sum(c(1,2,3,4,5))\textquotesingle{}).inspect"}
1158
+ \end{Highlighting}
1159
+ \end{Shaded}
1160
+
1161
+ Expected output:
1162
+
1163
+ \begin{Shaded}
1164
+ \begin{Highlighting}[]
1165
+ \NormalTok{15.0}
1166
+ \end{Highlighting}
1167
+ \end{Shaded}
1168
+
1169
+ \subsubsection{4) HTTP endpoint pattern}\label{http-endpoint-pattern}
1170
+
1171
+ For this baseline, a small Rack endpoint was the most stable first step
1172
+ to prove request-time R evaluation. (A full ActionController stack can
1173
+ be enabled later as the app evolves.)
1174
+
1175
+ Minimal pattern:
1176
+
1177
+ \begin{enumerate}
1178
+ \def\labelenumi{\arabic{enumi}.}
1179
+ \tightlist
1180
+ \item
1181
+ Define a Rack app class under \texttt{lib/} that runs
1182
+ \texttt{R.eval(...)} and returns HTML/JSON.
1183
+ \item
1184
+ Point a route to that Rack app (\texttt{root\ to:\ MyRackApp}).
1185
+ \item
1186
+ Verify with browser/curl.
1187
+ \end{enumerate}
1188
+
1189
+ \subsubsection{5) Running from WSL and opening from
1190
+ Windows}\label{running-from-wsl-and-opening-from-windows}
1191
+
1192
+ Recommended bind:
1193
+
1194
+ \begin{Shaded}
1195
+ \begin{Highlighting}[]
1196
+ \ExtensionTok{jruby} \AttributeTok{{-}S}\NormalTok{ bundle exec rails server }\AttributeTok{{-}b}\NormalTok{ 0.0.0.0 }\AttributeTok{{-}p}\NormalTok{ 3000}
1197
+ \end{Highlighting}
1198
+ \end{Shaded}
1199
+
1200
+ Then open from Windows:
1201
+
1202
+ \begin{itemize}
1203
+ \tightlist
1204
+ \item
1205
+ \texttt{http://localhost:3000} (usually works with WSL localhost
1206
+ forwarding), or
1207
+ \item
1208
+ \texttt{http://\textless{}wsl-ip\textgreater{}:3000} if needed.
1209
+ \end{itemize}
1210
+
1211
+ In development, if Host Authorization blocks requests with unexpected
1212
+ Host headers, use:
1213
+
1214
+ \begin{Shaded}
1215
+ \begin{Highlighting}[]
1216
+ \CommentTok{\# config/environments/development.rb}
1217
+ \NormalTok{config}\AttributeTok{.hosts.clear}
1218
+ \end{Highlighting}
1219
+ \end{Shaded}
1220
+
1221
+ \subsubsection{6) Troubleshooting
1222
+ checklist}\label{troubleshooting-checklist}
1223
+
1224
+ \begin{itemize}
1225
+ \tightlist
1226
+ \item
1227
+ \texttt{Could\ not\ find\ ...\ in\ locally\ installed\ gems}: run
1228
+ \texttt{jruby\ -S\ bundle\ install} in the Rails app directory.
1229
+ \item
1230
+ Stale PID after crash: remove \texttt{tmp/pids/server.pid}.
1231
+ \item
1232
+ Local Galaaz path changed: verify \texttt{Gemfile} path target exists
1233
+ and rerun bundler.
1234
+ \item
1235
+ R runtime issues: confirm GNU R is installed and on \texttt{PATH} in
1236
+ the same shell where Rails runs.
1237
+ \end{itemize}
1238
+
1239
+ As new Rails features are added (controllers, jobs, websockets,
1240
+ background rendering, plot generation), extend this section with
1241
+ concrete, runnable snippets and the associated operational checks.
1242
+
826
1243
  \section{Accessing R from Ruby}\label{accessing-r-from-ruby}
827
1244
 
828
1245
  One of the nice aspects of Galaaz is that variables and functions
829
1246
  defined in R can be easily accessed from Ruby. For instance, to access
830
1247
  the \texttt{mtcars} data frame from R in Ruby, we use the symbol
831
1248
  \texttt{:mtcars} preceded by the \texttt{\textasciitilde{}} operator:
832
- \texttt{\textasciitilde{}:mtcars} retrieves the value of the
1249
+ \texttt{\textasciitilde{}R{[}:mtcars{]}} retrieves the value of the
833
1250
  \texttt{mtcars} object in R.
834
1251
 
835
1252
  \begin{Shaded}
836
1253
  \begin{Highlighting}[]
837
- \FunctionTok{puts} \OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}
838
- \end{Highlighting}
839
- \end{Shaded}
840
-
841
- \begin{verbatim}
842
- ## mpg cyl disp hp drat wt qsec vs am gear carb
843
- ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
844
- ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
845
- ## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
846
- ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
847
- ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
848
- ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
849
- ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
850
- ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
851
- ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
852
- ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
853
- ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
854
- ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
855
- ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3
856
- ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3
857
- ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4
858
- ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
859
- ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
860
- ## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
861
- ## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
862
- ## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
863
- ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
864
- ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
865
- ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
866
- ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
867
- ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
868
- ## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
869
- ## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
870
- ## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
871
- ## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
872
- ## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
873
- ## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8
874
- ## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
875
- \end{verbatim}
1254
+ \FunctionTok{puts} \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}
1255
+ \end{Highlighting}
1256
+ \end{Shaded}
1257
+
1258
+ \begin{verbatim}
1259
+ ## mpg cyl disp hp drat wt qsec vs am gear
1260
+ ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4
1261
+ ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4
1262
+ ## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4
1263
+ ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3
1264
+ ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3
1265
+ ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3
1266
+ ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3
1267
+ ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4
1268
+ ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4
1269
+ ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4
1270
+ ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4
1271
+ ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3
1272
+ ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3
1273
+ ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3
1274
+ ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3
1275
+ ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3
1276
+ ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3
1277
+ ## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4
1278
+ ## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4
1279
+ ## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4
1280
+ ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3
1281
+ ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3
1282
+ ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3
1283
+ ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3
1284
+ ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3
1285
+ ## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4
1286
+ ## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5
1287
+ ## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5
1288
+ ## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5
1289
+ ## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5
1290
+ ## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5
1291
+ ## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4
1292
+ ## carb
1293
+ ## Mazda RX4 4
1294
+ ## Mazda RX4 Wag 4
1295
+ ## Datsun 710 1
1296
+ ## Hornet 4 Drive 1
1297
+ ## Hornet Sportabout 2
1298
+ ## Valiant 1
1299
+ ## Duster 360 4
1300
+ ## Merc 240D 2
1301
+ ## Merc 230 2
1302
+ ## Merc 280 4
1303
+ ## Merc 280C 4
1304
+ ## Merc 450SE 3
1305
+ ## Merc 450SL 3
1306
+ ## Merc 450SLC 3
1307
+ ## Cadillac Fleetwood 4
1308
+ ## Lincoln Continental 4
1309
+ ## Chrysler Imperial 4
1310
+ ## Fiat 128 1
1311
+ ## Honda Civic 2
1312
+ ## Toyota Corolla 1
1313
+ ## Toyota Corona 1
1314
+ ## Dodge Challenger 2
1315
+ ## AMC Javelin 2
1316
+ ## Camaro Z28 4
1317
+ ## Pontiac Firebird 2
1318
+ ## Fiat X1-9 1
1319
+ ## Porsche 914-2 2
1320
+ ## Lotus Europa 2
1321
+ ## Ford Pantera L 4
1322
+ ## Ferrari Dino 6
1323
+ ## Maserati Bora 8
1324
+ ## Volvo 142E 2
1325
+ \end{verbatim}
1326
+
1327
+ \subsection{Scoped symbols and lexical
1328
+ scoping}\label{scoped-symbols-and-lexical-scoping}
1329
+
1330
+ Galaaz 2.0 uses \textbf{scoped symbols} by default. The canonical style
1331
+ is \texttt{R{[}:name{]}}:
1332
+
1333
+ \begin{itemize}
1334
+ \tightlist
1335
+ \item
1336
+ \texttt{\textasciitilde{}R{[}:mtcars{]}} fetches an R object by name.
1337
+ \item
1338
+ \texttt{R{[}:a{]}\ +\ R{[}:b{]}} builds an expression.
1339
+ \item
1340
+ \texttt{R{[}:year{]}.up\_to(R{[}:day{]})} builds range expressions.
1341
+ \end{itemize}
1342
+
1343
+ If you prefer the terse \texttt{:x} syntax, you can opt in with lexical
1344
+ scoping using a Ruby refinement:
1345
+
1346
+ \begin{Shaded}
1347
+ \begin{Highlighting}[]
1348
+ \ControlFlowTok{module} \DataTypeTok{MyScript}
1349
+ \FunctionTok{using} \DataTypeTok{Galaaz}\OperatorTok{::}\DataTypeTok{SymbolDSL}
1350
+
1351
+ \ControlFlowTok{def} \DecValTok{self}\AttributeTok{.run}
1352
+ \NormalTok{ expr }\OperatorTok{=} \WarningTok{:a} \OperatorTok{+} \WarningTok{:b}
1353
+ \FunctionTok{puts}\NormalTok{ expr}
1354
+ \FunctionTok{puts} \OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}
1355
+ \ControlFlowTok{end}
1356
+ \ControlFlowTok{end}
1357
+ \end{Highlighting}
1358
+ \end{Shaded}
1359
+
1360
+ \texttt{using\ Galaaz::SymbolDSL} is \textbf{lexically scoped}: only
1361
+ code in that module/file scope gets \texttt{:x} DSL behavior. Outside
1362
+ that scope, plain Ruby \texttt{Symbol} behavior is unchanged.
876
1363
 
877
1364
  To access an R function from Ruby, the R function needs to be preceded
878
1365
  by \texttt{R.} scoping. Below we see an example of creating a R::Vector
@@ -1012,11 +1499,12 @@ element of our previously created vector:
1012
1499
 
1013
1500
  This manual has been formatted using gKnit. gKnit uses knitr and R
1014
1501
  Markdown to knit a document in Ruby or R and output it in any of the
1015
- available formats for R Markdown. gKnit runs with \textbf{JRuby},
1016
- \textbf{GNU R}, and Galaaz. In gKnit, Ruby variables are persisted
1017
- between chunks, making it an ideal solution for literate programming.
1018
- Also, since it is based on Galaaz, Ruby chunks can have access to R
1019
- variables and combining Ruby with R in one document is natural.
1502
+ available formats for R Markdown. gKnit runs with \textbf{JRuby or
1503
+ CRuby}, \textbf{GNU R}, and Galaaz. In gKnit, Ruby variables are
1504
+ persisted between chunks, making it an ideal solution for literate
1505
+ programming. Also, since it is based on Galaaz, Ruby chunks can have
1506
+ access to R variables and combining Ruby with R in one document is
1507
+ natural.
1020
1508
 
1021
1509
  The idea of ``literate programming'' was first introduced by Donald
1022
1510
  Knuth in the 1980's (Knuth 1984). The main intention of this approach
@@ -1150,7 +1638,7 @@ in a single document, text and code.
1150
1638
  In gKnit, Ruby variables are persisted between chunks, making it an
1151
1639
  ideal solution for literate programming in this language. Also, since it
1152
1640
  is based on Galaaz, Ruby chunks can access R variables
1153
- (\texttt{\textasciitilde{}:name}, \texttt{R.*}) through the
1641
+ (\texttt{\textasciitilde{}R{[}:name{]}}, \texttt{R.*}) through the
1154
1642
  \textbf{Galaaz bridge} while knitr drives \textbf{GNU R}---no GraalVM
1155
1643
  polyglot runtime is required.
1156
1644
 
@@ -1452,7 +1940,9 @@ linear regression line (method = ``lm'') for every manufacturer.
1452
1940
  \FunctionTok{library}\NormalTok{(ggplot2)}
1453
1941
  \FunctionTok{data}\NormalTok{(mpg, }\AttributeTok{package=}\StringTok{"ggplot2"}\NormalTok{)}
1454
1942
 
1455
- \NormalTok{mpg\_select }\OtherTok{\textless{}{-}}\NormalTok{ mpg[mpg}\SpecialCharTok{$}\NormalTok{manufacturer }\SpecialCharTok{\%in\%} \FunctionTok{c}\NormalTok{(}\StringTok{"audi"}\NormalTok{, }\StringTok{"ford"}\NormalTok{, }\StringTok{"honda"}\NormalTok{, }\StringTok{"hyundai"}\NormalTok{), ]}
1943
+ \NormalTok{mpg\_select }\OtherTok{\textless{}{-}}\NormalTok{ mpg[}
1944
+ \NormalTok{ mpg}\SpecialCharTok{$}\NormalTok{manufacturer }\SpecialCharTok{\%in\%} \FunctionTok{c}\NormalTok{(}\StringTok{"audi"}\NormalTok{, }\StringTok{"ford"}\NormalTok{, }\StringTok{"honda"}\NormalTok{, }\StringTok{"hyundai"}\NormalTok{),}
1945
+ \NormalTok{]}
1456
1946
 
1457
1947
  \CommentTok{\# Scatterplot}
1458
1948
  \FunctionTok{theme\_set}\NormalTok{(}\FunctionTok{theme\_bw}\NormalTok{()) }\CommentTok{\# pre{-}set the bw theme.}
@@ -1469,7 +1959,7 @@ linear regression line (method = ``lm'') for every manufacturer.
1469
1959
  ## `geom_smooth()` using formula = 'y ~ x'
1470
1960
  \end{verbatim}
1471
1961
 
1472
- \pandocbounded{\includegraphics[keepaspectratio]{manual_files/figure-latex/bubble-1.png}}
1962
+ \pandocbounded{\includegraphics[keepaspectratio]{manual_files/manual_files/figure-latex/bubble-1.png}}
1473
1963
 
1474
1964
  \subsection{Ruby chunks}\label{ruby-chunks}
1475
1965
 
@@ -1539,7 +2029,8 @@ phrase. gKnit allows adding inline Ruby code with the `rb' engine. The
1539
2029
  following chunk specification will create and inline Ruby text:
1540
2030
 
1541
2031
  \begin{verbatim}
1542
- This is some text with inline Ruby accessing variable 'b' which has value:
2032
+ This is some text with inline Ruby accessing
2033
+ variable 'b' which has value:
1543
2034
  ```{rb puts b}
1544
2035
  ```
1545
2036
  and is followed by some other text!
@@ -1638,12 +2129,12 @@ library is a great library for creating beautiful tables. Take a look at
1638
2129
 
1639
2130
  In the next chunk, we output the `mtcars' dataframe from R in a nicely
1640
2131
  formatted table. Note that we retrieve the mtcars dataframe by using
1641
- `\textasciitilde:mtcars'.
2132
+ `\textasciitilde R{[}:mtcars{]}'.
1642
2133
 
1643
2134
  \begin{Shaded}
1644
2135
  \begin{Highlighting}[]
1645
2136
  \ConstantTok{R}\AttributeTok{.install\_and\_loads}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}kableExtra\textquotesingle{}}\NormalTok{)}
1646
- \NormalTok{outputs (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.kable.kable\_styling}
2137
+ \NormalTok{outputs (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\AttributeTok{.kable.kable\_styling}
1647
2138
  \end{Highlighting}
1648
2139
  \end{Shaded}
1649
2140
 
@@ -1733,7 +2224,8 @@ is trivial with Galaaz.
1733
2224
  A word of advice: the `caret' package has lots of dependencies and
1734
2225
  installing it in a Linux system is a time consuming operation. Method
1735
2226
  `R.install\_and\_loads' will install the package if it is not already
1736
- installed and can take a while.
2227
+ installed (via \textbf{\texttt{R::Job}}: a child \texttt{Rscript}, so
2228
+ the bridge stays free) and can take a while.
1737
2229
 
1738
2230
  \begin{verbatim}
1739
2231
  ```{include model}
@@ -1786,7 +2278,7 @@ installed and can take a while.
1786
2278
 
1787
2279
  \begin{Shaded}
1788
2280
  \begin{Highlighting}[]
1789
- \NormalTok{mtcars }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}
2281
+ \NormalTok{mtcars }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}
1790
2282
  \NormalTok{model }\OperatorTok{=} \DataTypeTok{Model}\AttributeTok{.new}\NormalTok{(mtcars, }\WarningTok{percent\_train:} \FloatTok{0.8}\NormalTok{)}
1791
2283
  \NormalTok{model}\AttributeTok{.partition}\NormalTok{(}\WarningTok{:mpg}\NormalTok{)}
1792
2284
  \FunctionTok{puts}\NormalTok{ model}\AttributeTok{.train.head}
@@ -2023,15 +2515,17 @@ In order to create a document with one of those templates, use the
2023
2515
  following command:
2024
2516
 
2025
2517
  \begin{verbatim}
2026
- gknit-draft --filename <my_document> --template <template> --package <package>
2027
- --create_dir
2518
+ gknit-draft --filename <my_document> \
2519
+ --template <template> --package <package> \
2520
+ --create_dir
2028
2521
  \end{verbatim}
2029
2522
 
2030
2523
  So, in order to create a template for writing an R Journal, use:
2031
2524
 
2032
2525
  \begin{verbatim}
2033
- gknit-draft --filename my_r_article --template rjournal_article --package rticles
2034
- --create_dir
2526
+ gknit-draft --filename my_r_article \
2527
+ --template rjournal_article --package rticles \
2528
+ --create_dir
2035
2529
  \end{verbatim}
2036
2530
 
2037
2531
  \section{Accessing R variables}\label{accessing-r-variables}
@@ -2046,7 +2540,7 @@ Method \texttt{outputs} is only available when used with gKnit.
2046
2540
 
2047
2541
  \begin{Shaded}
2048
2542
  \begin{Highlighting}[]
2049
- \NormalTok{outputs (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.kable.kable\_styling}
2543
+ \NormalTok{outputs (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\AttributeTok{.kable.kable\_styling}
2050
2544
  \end{Highlighting}
2051
2545
  \end{Shaded}
2052
2546
 
@@ -2157,7 +2651,10 @@ used to create a data frame is `data.frame', in Galaaz we use
2157
2651
 
2158
2652
  \begin{Shaded}
2159
2653
  \begin{Highlighting}[]
2160
- \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}\WarningTok{typeof:}\NormalTok{ vec}\AttributeTok{.typeof}\NormalTok{, }\WarningTok{mode:}\NormalTok{ vec}\AttributeTok{.mode}\NormalTok{, }\WarningTok{storage\_\_mode:}\NormalTok{ vec}\AttributeTok{.storage\_\_mode}\NormalTok{)}
2654
+ \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}
2655
+ \WarningTok{typeof:}\NormalTok{ vec}\AttributeTok{.typeof}\NormalTok{,}
2656
+ \WarningTok{mode:}\NormalTok{ vec}\AttributeTok{.mode}\NormalTok{,}
2657
+ \WarningTok{storage\_\_mode:}\NormalTok{ vec}\AttributeTok{.storage\_\_mode}\NormalTok{)}
2161
2658
  \FunctionTok{puts}\NormalTok{ df}
2162
2659
  \end{Highlighting}
2163
2660
  \end{Shaded}
@@ -2186,7 +2683,10 @@ normal Ruby rules and the number 1 is an integer and 1.0 is a float.
2186
2683
 
2187
2684
  \begin{Shaded}
2188
2685
  \begin{Highlighting}[]
2189
- \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}\WarningTok{typeof:}\NormalTok{ vec}\AttributeTok{.typeof}\NormalTok{, }\WarningTok{mode:}\NormalTok{ vec}\AttributeTok{.mode}\NormalTok{, }\WarningTok{storage\_\_mode:}\NormalTok{ vec}\AttributeTok{.storage\_\_mode}\NormalTok{)}
2686
+ \NormalTok{df }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.data\_\_frame}\NormalTok{(}
2687
+ \WarningTok{typeof:}\NormalTok{ vec}\AttributeTok{.typeof}\NormalTok{,}
2688
+ \WarningTok{mode:}\NormalTok{ vec}\AttributeTok{.mode}\NormalTok{,}
2689
+ \WarningTok{storage\_\_mode:}\NormalTok{ vec}\AttributeTok{.storage\_\_mode}\NormalTok{)}
2190
2690
  \NormalTok{outputs df}\AttributeTok{.kable.kable\_styling}
2191
2691
  \end{Highlighting}
2192
2692
  \end{Shaded}
@@ -2217,14 +2717,14 @@ error.
2217
2717
 
2218
2718
  \begin{verbatim}
2219
2719
  ## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:170:in 'exec_ruby'
2220
- ## org/jruby/RubyKernel.java:1268:in 'eval'
2720
+ ## org/jruby/RubyKernel.java:1459:in 'eval'
2221
2721
  ## /home/rbotafogo/desenv_linux/galaaz/lib/util/exec_ruby.rb:169:in 'exec_ruby'
2222
2722
  ## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:777:in 'block in initialize'
2223
- ## org/jruby/RubyBasicObject.java:2695:in 'instance_eval'
2224
- ## org/jruby/RubyBasicObject.java:2723:in 'instance_eval'
2723
+ ## org/jruby/RubyBasicObject.java:2713:in 'instance_eval'
2724
+ ## org/jruby/RubyBasicObject.java:2741:in 'instance_eval'
2225
2725
  ## /home/rbotafogo/desenv_linux/galaaz/lib/gknit/knitr_engine.rb:748:in 'block in initialize'
2226
- ## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/new_bridge_adapter.rb:358:in 'block in register_callback_proc_stub'
2227
- ## /home/rbotafogo/desenv_linux/galaaz/lib/new_bridge/session_client.rb:413:in 'block in handle_call'
2726
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/R_interface/new_bridge_adapter.rb:371:in 'block in register_callback_proc_stub'
2727
+ ## /home/rbotafogo/desenv_linux/galaaz/lib/new_bridge/session_client.rb:458:in 'block in handle_call'
2228
2728
  \end{verbatim}
2229
2729
 
2230
2730
  Here is a vector with logical values
@@ -2659,8 +3159,8 @@ native Ruby type.
2659
3159
  A data frame is a table like structure in which each column has the same
2660
3160
  number of rows. Data frames are the basic structure for storing data for
2661
3161
  data analysis. We have already seen a data frame previously when we
2662
- accessed variable `\textasciitilde:mtcars'. In order to create a data
2663
- frame, function 'data\_\_frame' is used:
3162
+ accessed variable `\textasciitilde R{[}:mtcars{]}'. In order to create a
3163
+ data frame, function 'data\_\_frame' is used:
2664
3164
 
2665
3165
  \begin{Shaded}
2666
3166
  \begin{Highlighting}[]
@@ -2687,9 +3187,9 @@ the row or column
2687
3187
 
2688
3188
  \begin{Shaded}
2689
3189
  \begin{Highlighting}[]
2690
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.head}
2691
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\DecValTok{1}\NormalTok{, }\DecValTok{2}\KeywordTok{]}
2692
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\VerbatimStringTok{\textquotesingle{}Datsun 710\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\KeywordTok{]}
3190
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\AttributeTok{.head}
3191
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\KeywordTok{[}\DecValTok{1}\NormalTok{, }\DecValTok{2}\KeywordTok{]}
3192
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\KeywordTok{[}\VerbatimStringTok{\textquotesingle{}Datsun 710\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\KeywordTok{]}
2693
3193
  \end{Highlighting}
2694
3194
  \end{Shaded}
2695
3195
 
@@ -2710,14 +3210,14 @@ the double square bracket operator:
2710
3210
 
2711
3211
  \begin{Shaded}
2712
3212
  \begin{Highlighting}[]
2713
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[[}\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\KeywordTok{]]}
3213
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\KeywordTok{[[}\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\KeywordTok{]]}
2714
3214
  \end{Highlighting}
2715
3215
  \end{Shaded}
2716
3216
 
2717
3217
  \begin{verbatim}
2718
- ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
2719
- ## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
2720
- ## [31] 15.0 21.4
3218
+ ## [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
3219
+ ## [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
3220
+ ## [27] 26.0 30.4 15.8 19.7 15.0 21.4
2721
3221
  \end{verbatim}
2722
3222
 
2723
3223
  A data frame column can also be accessed as if it were an instance
@@ -2725,14 +3225,14 @@ variable of the data frame:
2725
3225
 
2726
3226
  \begin{Shaded}
2727
3227
  \begin{Highlighting}[]
2728
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.mpg}
3228
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\AttributeTok{.mpg}
2729
3229
  \end{Highlighting}
2730
3230
  \end{Shaded}
2731
3231
 
2732
3232
  \begin{verbatim}
2733
- ## [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
2734
- ## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
2735
- ## [31] 15.0 21.4
3233
+ ## [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
3234
+ ## [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
3235
+ ## [27] 26.0 30.4 15.8 19.7 15.0 21.4
2736
3236
  \end{verbatim}
2737
3237
 
2738
3238
  Slicing a data frame can be done by indexing it with a vector (we use
@@ -2740,7 +3240,7 @@ Slicing a data frame can be done by indexing it with a vector (we use
2740
3240
 
2741
3241
  \begin{Shaded}
2742
3242
  \begin{Highlighting}[]
2743
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}hp\textquotesingle{}}\NormalTok{)}\KeywordTok{]}\AttributeTok{.head}
3243
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}mpg\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}hp\textquotesingle{}}\NormalTok{)}\KeywordTok{]}\AttributeTok{.head}
2744
3244
  \end{Highlighting}
2745
3245
  \end{Shaded}
2746
3246
 
@@ -2755,7 +3255,7 @@ keyword for the column:
2755
3255
 
2756
3256
  \begin{Shaded}
2757
3257
  \begin{Highlighting}[]
2758
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}Datsun 710\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}Camaro Z28\textquotesingle{}}\NormalTok{), }\WarningTok{:all}\KeywordTok{]}
3258
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}Datsun 710\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}Camaro Z28\textquotesingle{}}\NormalTok{), }\WarningTok{:all}\KeywordTok{]}
2759
3259
  \end{Highlighting}
2760
3260
  \end{Shaded}
2761
3261
 
@@ -2768,21 +3268,21 @@ keyword for the column:
2768
3268
  Finally, a data frame can also be indexed with a logical vector. In this
2769
3269
  next example, the `am' column of :mtcars is compared with 0 (with method
2770
3270
  `eq'). When `am' is equal to 0 the car is automatic. So, by doing
2771
- `(\textasciitilde:mtcars).am.eq 0' a logical vector is created with
2772
- `true' whenever `am' is 0 and `false' otherwise.
3271
+ `(\textasciitilde R{[}:mtcars{]}).am.eq 0' a logical vector is created
3272
+ with `true' whenever `am' is 0 and `false' otherwise.
2773
3273
 
2774
3274
  \begin{Shaded}
2775
3275
  \begin{Highlighting}[]
2776
3276
  \CommentTok{\# obtain a vector with \textquotesingle{}true\textquotesingle{} for cars with automatic transmission}
2777
- \NormalTok{automatic }\OperatorTok{=}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\AttributeTok{.am.eq} \DecValTok{0}
3277
+ \NormalTok{automatic }\OperatorTok{=}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\AttributeTok{.am.eq} \DecValTok{0}
2778
3278
  \FunctionTok{puts}\NormalTok{ automatic}
2779
3279
  \end{Highlighting}
2780
3280
  \end{Shaded}
2781
3281
 
2782
3282
  \begin{verbatim}
2783
- ## [1] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
2784
- ## [13] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE
2785
- ## [25] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
3283
+ ## [1] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
3284
+ ## [12] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE
3285
+ ## [23] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
2786
3286
  \end{verbatim}
2787
3287
 
2788
3288
  Using this logical vector, the data frame is indexed, returning a new
@@ -2791,31 +3291,51 @@ data frame in which all cars have automatic transmission.
2791
3291
  \begin{Shaded}
2792
3292
  \begin{Highlighting}[]
2793
3293
  \CommentTok{\# slice the data frame by using this vector}
2794
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}\NormalTok{)}\KeywordTok{[}\NormalTok{automatic, }\WarningTok{:all}\KeywordTok{]}
2795
- \end{Highlighting}
2796
- \end{Shaded}
2797
-
2798
- \begin{verbatim}
2799
- ## mpg cyl disp hp drat wt qsec vs am gear carb
2800
- ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
2801
- ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
2802
- ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
2803
- ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
2804
- ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
2805
- ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
2806
- ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
2807
- ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
2808
- ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
2809
- ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3
2810
- ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3
2811
- ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4
2812
- ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
2813
- ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
2814
- ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
2815
- ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
2816
- ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
2817
- ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
2818
- ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
3294
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}\KeywordTok{[}\NormalTok{automatic, }\WarningTok{:all}\KeywordTok{]}
3295
+ \end{Highlighting}
3296
+ \end{Shaded}
3297
+
3298
+ \begin{verbatim}
3299
+ ## mpg cyl disp hp drat wt qsec vs am gear
3300
+ ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3
3301
+ ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3
3302
+ ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3
3303
+ ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3
3304
+ ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4
3305
+ ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4
3306
+ ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4
3307
+ ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4
3308
+ ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3
3309
+ ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3
3310
+ ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3
3311
+ ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3
3312
+ ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3
3313
+ ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3
3314
+ ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3
3315
+ ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3
3316
+ ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3
3317
+ ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3
3318
+ ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3
3319
+ ## carb
3320
+ ## Hornet 4 Drive 1
3321
+ ## Hornet Sportabout 2
3322
+ ## Valiant 1
3323
+ ## Duster 360 4
3324
+ ## Merc 240D 2
3325
+ ## Merc 230 2
3326
+ ## Merc 280 4
3327
+ ## Merc 280C 4
3328
+ ## Merc 450SE 3
3329
+ ## Merc 450SL 3
3330
+ ## Merc 450SLC 3
3331
+ ## Cadillac Fleetwood 4
3332
+ ## Lincoln Continental 4
3333
+ ## Chrysler Imperial 4
3334
+ ## Toyota Corona 1
3335
+ ## Dodge Challenger 2
3336
+ ## AMC Javelin 2
3337
+ ## Camaro Z28 4
3338
+ ## Pontiac Firebird 2
2819
3339
  \end{verbatim}
2820
3340
 
2821
3341
  \section{Writing Expressions in
@@ -2832,7 +3352,7 @@ The code below creates an expression summing two symbols
2832
3352
 
2833
3353
  \begin{Shaded}
2834
3354
  \begin{Highlighting}[]
2835
- \NormalTok{exp1 }\OperatorTok{=} \WarningTok{:a} \OperatorTok{+} \WarningTok{:b}
3355
+ \NormalTok{exp1 }\OperatorTok{=} \ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}
2836
3356
  \FunctionTok{puts}\NormalTok{ exp1}
2837
3357
  \end{Highlighting}
2838
3358
  \end{Shaded}
@@ -2845,7 +3365,7 @@ We can build any complex mathematical expression
2845
3365
 
2846
3366
  \begin{Shaded}
2847
3367
  \begin{Highlighting}[]
2848
- \NormalTok{exp2 }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{) }\OperatorTok{*} \FloatTok{2.0} \OperatorTok{+} \WarningTok{:c} \OperatorTok{**} \DecValTok{2} \OperatorTok{/} \WarningTok{:z}
3368
+ \NormalTok{exp2 }\OperatorTok{=}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}\NormalTok{) }\OperatorTok{*} \FloatTok{2.0} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:c}\KeywordTok{]} \OperatorTok{**} \DecValTok{2} \OperatorTok{/} \ConstantTok{R}\KeywordTok{[}\WarningTok{:z}\KeywordTok{]}
2849
3369
  \FunctionTok{puts}\NormalTok{ exp2}
2850
3370
  \end{Highlighting}
2851
3371
  \end{Shaded}
@@ -2858,7 +3378,7 @@ It is also possible to use inequality operators in building expressions
2858
3378
 
2859
3379
  \begin{Shaded}
2860
3380
  \begin{Highlighting}[]
2861
- \NormalTok{exp3 }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{) }\OperatorTok{\textgreater{}=} \WarningTok{:z}
3381
+ \NormalTok{exp3 }\OperatorTok{=}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}\NormalTok{) }\OperatorTok{\textgreater{}=} \WarningTok{:z}
2862
3382
  \FunctionTok{puts}\NormalTok{ exp3}
2863
3383
  \end{Highlighting}
2864
3384
  \end{Shaded}
@@ -2874,7 +3394,7 @@ be written as
2874
3394
 
2875
3395
  \begin{Shaded}
2876
3396
  \begin{Highlighting}[]
2877
- \NormalTok{exp4 }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{)}\AttributeTok{.ge} \OperatorTok{:}\NormalTok{z}
3397
+ \NormalTok{exp4 }\OperatorTok{=}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}\NormalTok{)}\AttributeTok{.ge} \OperatorTok{:}\NormalTok{z}
2878
3398
  \FunctionTok{puts}\NormalTok{ exp4}
2879
3399
  \end{Highlighting}
2880
3400
  \end{Shaded}
@@ -2890,7 +3410,7 @@ the method `.eq' and for `=' we need the function `.assign'
2890
3410
 
2891
3411
  \begin{Shaded}
2892
3412
  \begin{Highlighting}[]
2893
- \NormalTok{exp5 }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{)}\AttributeTok{.eq} \OperatorTok{:}\NormalTok{z}
3413
+ \NormalTok{exp5 }\OperatorTok{=}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}\NormalTok{)}\AttributeTok{.eq} \OperatorTok{:}\NormalTok{z}
2894
3414
  \FunctionTok{puts}\NormalTok{ exp5}
2895
3415
  \end{Highlighting}
2896
3416
  \end{Shaded}
@@ -2901,7 +3421,7 @@ the method `.eq' and for `=' we need the function `.assign'
2901
3421
 
2902
3422
  \begin{Shaded}
2903
3423
  \begin{Highlighting}[]
2904
- \NormalTok{exp6 }\OperatorTok{=} \WarningTok{:y}\AttributeTok{.assign} \OperatorTok{:}\NormalTok{a }\OperatorTok{+} \WarningTok{:b}
3424
+ \NormalTok{exp6 }\OperatorTok{=} \ConstantTok{R}\KeywordTok{[}\WarningTok{:y}\KeywordTok{]}\AttributeTok{.assign} \ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}
2905
3425
  \FunctionTok{puts}\NormalTok{ exp6}
2906
3426
  \end{Highlighting}
2907
3427
  \end{Shaded}
@@ -2916,18 +3436,18 @@ expressions such as
2916
3436
 
2917
3437
  \begin{Shaded}
2918
3438
  \begin{Highlighting}[]
2919
- \NormalTok{exp\_wrong }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{) }\OperatorTok{==} \WarningTok{:z}
3439
+ \NormalTok{exp\_wrong }\OperatorTok{=}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}\NormalTok{) }\OperatorTok{==} \WarningTok{:z}
2920
3440
  \FunctionTok{puts}\NormalTok{ exp\_wrong}
2921
3441
  \end{Highlighting}
2922
3442
  \end{Shaded}
2923
3443
 
2924
3444
  and it might be difficult to understand what is going on here. The
2925
3445
  problem lies with the fact that when using `==' we are comparing
2926
- expression (:a + :b) to expression :z with `=='. When the comparison is
2927
- executed, the system tries to evaluate :a, :b and :z, and those symbols
2928
- at this time are not bound to anything and we get a ``object `a' not
2929
- found'' message. If we only use functional notation, this type of error
2930
- will not occur.
3446
+ expression (R{[}:a{]} + R{[}:b{]}) to expression :z with `=='. When the
3447
+ comparison is executed, the system tries to evaluate :a, :b and :z, and
3448
+ those symbols at this time are not bound to anything and we get a
3449
+ ``object `a' not found'' message. If we only use functional notation,
3450
+ this type of error will not occur.
2931
3451
 
2932
3452
  \subsection{Expressions with R
2933
3453
  methods}\label{expressions-with-r-methods}
@@ -2943,7 +3463,7 @@ such as `E.sin(x)'
2943
3463
 
2944
3464
  \begin{Shaded}
2945
3465
  \begin{Highlighting}[]
2946
- \NormalTok{exp7 }\OperatorTok{=} \WarningTok{:y}\AttributeTok{.assign} \ConstantTok{E}\AttributeTok{.sin}\NormalTok{(}\WarningTok{:x}\NormalTok{)}
3466
+ \NormalTok{exp7 }\OperatorTok{=} \ConstantTok{R}\KeywordTok{[}\WarningTok{:y}\KeywordTok{]}\AttributeTok{.assign} \ConstantTok{E}\AttributeTok{.sin}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]}\NormalTok{)}
2947
3467
  \FunctionTok{puts}\NormalTok{ exp7}
2948
3468
  \end{Highlighting}
2949
3469
  \end{Shaded}
@@ -2956,7 +3476,7 @@ Expressions can also be written using `.' notation:
2956
3476
 
2957
3477
  \begin{Shaded}
2958
3478
  \begin{Highlighting}[]
2959
- \NormalTok{exp8 }\OperatorTok{=} \WarningTok{:y}\AttributeTok{.assign} \OperatorTok{:}\NormalTok{x}\AttributeTok{.sin}
3479
+ \NormalTok{exp8 }\OperatorTok{=} \ConstantTok{R}\KeywordTok{[}\WarningTok{:y}\KeywordTok{]}\AttributeTok{.assign} \ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]}\AttributeTok{.sin}
2960
3480
  \FunctionTok{puts}\NormalTok{ exp8}
2961
3481
  \end{Highlighting}
2962
3482
  \end{Shaded}
@@ -2970,7 +3490,7 @@ the `.':
2970
3490
 
2971
3491
  \begin{Shaded}
2972
3492
  \begin{Highlighting}[]
2973
- \NormalTok{exp9 }\OperatorTok{=} \WarningTok{:x}\AttributeTok{.c}\NormalTok{(}\WarningTok{:y}\NormalTok{)}
3493
+ \NormalTok{exp9 }\OperatorTok{=} \ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]}\AttributeTok{.c}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:y}\KeywordTok{]}\NormalTok{)}
2974
3494
  \FunctionTok{puts}\NormalTok{ exp9}
2975
3495
  \end{Highlighting}
2976
3496
  \end{Shaded}
@@ -2986,7 +3506,7 @@ A binding can be provided with a list:
2986
3506
 
2987
3507
  \begin{Shaded}
2988
3508
  \begin{Highlighting}[]
2989
- \NormalTok{exp }\OperatorTok{=}\NormalTok{ (}\WarningTok{:a} \OperatorTok{+} \WarningTok{:b}\NormalTok{) }\OperatorTok{*} \FloatTok{2.0} \OperatorTok{+} \WarningTok{:c} \OperatorTok{**} \DecValTok{2} \OperatorTok{/} \WarningTok{:z}
3509
+ \NormalTok{exp }\OperatorTok{=}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}\NormalTok{) }\OperatorTok{*} \FloatTok{2.0} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:c}\KeywordTok{]} \OperatorTok{**} \DecValTok{2} \OperatorTok{/} \ConstantTok{R}\KeywordTok{[}\WarningTok{:z}\KeywordTok{]}
2990
3510
  \FunctionTok{puts}\NormalTok{ exp}\AttributeTok{.eval}\NormalTok{(}\ConstantTok{R}\AttributeTok{.list}\NormalTok{(}\WarningTok{a:} \DecValTok{10}\NormalTok{, }\WarningTok{b:} \DecValTok{20}\NormalTok{, }\WarningTok{c:} \DecValTok{30}\NormalTok{, }\WarningTok{z:} \DecValTok{40}\NormalTok{))}
2991
3511
  \end{Highlighting}
2992
3512
  \end{Shaded}
@@ -3043,51 +3563,53 @@ use \texttt{head} / \texttt{str} in R via \texttt{R} calls).
3043
3563
 
3044
3564
  \begin{Shaded}
3045
3565
  \begin{Highlighting}[]
3046
- \NormalTok{flights }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:flights}
3566
+ \NormalTok{flights }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:flights}\KeywordTok{]}
3047
3567
  \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.head}
3048
3568
  \end{Highlighting}
3049
3569
  \end{Shaded}
3050
3570
 
3051
3571
  \begin{verbatim}
3052
3572
  ## # A tibble: 6 x 19
3053
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3054
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3055
- ## 1 2013 1 1 517 515 2 830 819
3056
- ## 2 2013 1 1 533 529 4 850 830
3057
- ## 3 2013 1 1 542 540 2 923 850
3058
- ## 4 2013 1 1 544 545 -1 1004 1022
3059
- ## 5 2013 1 1 554 600 -6 812 837
3060
- ## 6 2013 1 1 554 558 -4 740 728
3061
- ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3062
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3063
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3573
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3574
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3575
+ ## 1 2013 1 1 517 515 2 830
3576
+ ## 2 2013 1 1 533 529 4 850
3577
+ ## 3 2013 1 1 542 540 2 923
3578
+ ## 4 2013 1 1 544 545 -1 1004
3579
+ ## 5 2013 1 1 554 600 -6 812
3580
+ ## 6 2013 1 1 554 558 -4 740
3581
+ ## # i 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3582
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3583
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3584
+ ## # minute <dbl>, time_hour <dttm>
3064
3585
  \end{verbatim}
3065
3586
 
3066
3587
  \subsection{Filtering rows with
3067
3588
  Filter}\label{filtering-rows-with-filter}
3068
3589
 
3069
3590
  In this example we filter the flights data set by giving to the filter
3070
- function two expressions: the first :month.eq 1
3591
+ function two expressions: the first R{[}:month{]}.eq 1
3071
3592
 
3072
3593
  \begin{Shaded}
3073
3594
  \begin{Highlighting}[]
3074
- \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{((}\WarningTok{:month}\AttributeTok{.eq} \DecValTok{1}\NormalTok{), (}\WarningTok{:day}\AttributeTok{.eq} \DecValTok{1}\NormalTok{))}\AttributeTok{.head}
3595
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{((}\ConstantTok{R}\KeywordTok{[}\WarningTok{:month}\KeywordTok{]}\AttributeTok{.eq} \DecValTok{1}\NormalTok{), (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:day}\KeywordTok{]}\AttributeTok{.eq} \DecValTok{1}\NormalTok{))}\AttributeTok{.head}
3075
3596
  \end{Highlighting}
3076
3597
  \end{Shaded}
3077
3598
 
3078
3599
  \begin{verbatim}
3079
3600
  ## # A tibble: 6 x 19
3080
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3081
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3082
- ## 1 2013 1 1 517 515 2 830 819
3083
- ## 2 2013 1 1 533 529 4 850 830
3084
- ## 3 2013 1 1 542 540 2 923 850
3085
- ## 4 2013 1 1 544 545 -1 1004 1022
3086
- ## 5 2013 1 1 554 600 -6 812 837
3087
- ## 6 2013 1 1 554 558 -4 740 728
3088
- ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3089
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3090
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3601
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3602
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3603
+ ## 1 2013 1 1 517 515 2 830
3604
+ ## 2 2013 1 1 533 529 4 850
3605
+ ## 3 2013 1 1 542 540 2 923
3606
+ ## 4 2013 1 1 544 545 -1 1004
3607
+ ## 5 2013 1 1 554 600 -6 812
3608
+ ## 6 2013 1 1 554 558 -4 740
3609
+ ## # i 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3610
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3611
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3612
+ ## # minute <dbl>, time_hour <dttm>
3091
3613
  \end{verbatim}
3092
3614
 
3093
3615
  \subsection{Logical Operators}\label{logical-operators}
@@ -3096,23 +3618,24 @@ All flights that departed in November of December
3096
3618
 
3097
3619
  \begin{Shaded}
3098
3620
  \begin{Highlighting}[]
3099
- \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{((}\WarningTok{:month}\AttributeTok{.eq} \DecValTok{11}\NormalTok{) }\OperatorTok{|}\NormalTok{ (}\WarningTok{:month}\AttributeTok{.eq} \DecValTok{12}\NormalTok{))}\AttributeTok{.head}
3621
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{((}\ConstantTok{R}\KeywordTok{[}\WarningTok{:month}\KeywordTok{]}\AttributeTok{.eq} \DecValTok{11}\NormalTok{) }\OperatorTok{|}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:month}\KeywordTok{]}\AttributeTok{.eq} \DecValTok{12}\NormalTok{))}\AttributeTok{.head}
3100
3622
  \end{Highlighting}
3101
3623
  \end{Shaded}
3102
3624
 
3103
3625
  \begin{verbatim}
3104
3626
  ## # A tibble: 6 x 19
3105
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3106
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3107
- ## 1 2013 11 1 5 2359 6 352 345
3108
- ## 2 2013 11 1 35 2250 105 123 2356
3109
- ## 3 2013 11 1 455 500 -5 641 651
3110
- ## 4 2013 11 1 539 545 -6 856 827
3111
- ## 5 2013 11 1 542 545 -3 831 855
3112
- ## 6 2013 11 1 549 600 -11 912 923
3113
- ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3114
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3115
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3627
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3628
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3629
+ ## 1 2013 11 1 5 2359 6 352
3630
+ ## 2 2013 11 1 35 2250 105 123
3631
+ ## 3 2013 11 1 455 500 -5 641
3632
+ ## 4 2013 11 1 539 545 -6 856
3633
+ ## 5 2013 11 1 542 545 -3 831
3634
+ ## 6 2013 11 1 549 600 -11 912
3635
+ ## # i 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3636
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3637
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3638
+ ## # minute <dbl>, time_hour <dttm>
3116
3639
  \end{verbatim}
3117
3640
 
3118
3641
  The same as above, but using the `in' operator. In R, it is possible to
@@ -3123,23 +3646,24 @@ in this case `:in' and the second argument is the vector:
3123
3646
 
3124
3647
  \begin{Shaded}
3125
3648
  \begin{Highlighting}[]
3126
- \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{(}\WarningTok{:month}\AttributeTok{.\_} \OperatorTok{:}\ControlFlowTok{in}\NormalTok{, }\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{11}\NormalTok{, }\DecValTok{12}\NormalTok{))}\AttributeTok{.head}
3649
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.filter}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:month}\KeywordTok{]}\AttributeTok{.\_} \OperatorTok{:}\ControlFlowTok{in}\NormalTok{, }\ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\DecValTok{11}\NormalTok{, }\DecValTok{12}\NormalTok{))}\AttributeTok{.head}
3127
3650
  \end{Highlighting}
3128
3651
  \end{Shaded}
3129
3652
 
3130
3653
  \begin{verbatim}
3131
3654
  ## # A tibble: 6 x 19
3132
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3133
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3134
- ## 1 2013 11 1 5 2359 6 352 345
3135
- ## 2 2013 11 1 35 2250 105 123 2356
3136
- ## 3 2013 11 1 455 500 -5 641 651
3137
- ## 4 2013 11 1 539 545 -6 856 827
3138
- ## 5 2013 11 1 542 545 -3 831 855
3139
- ## 6 2013 11 1 549 600 -11 912 923
3140
- ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3141
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3142
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3655
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3656
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3657
+ ## 1 2013 11 1 5 2359 6 352
3658
+ ## 2 2013 11 1 35 2250 105 123
3659
+ ## 3 2013 11 1 455 500 -5 641
3660
+ ## 4 2013 11 1 539 545 -6 856
3661
+ ## 5 2013 11 1 542 545 -3 831
3662
+ ## 6 2013 11 1 549 600 -11 912
3663
+ ## # i 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3664
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3665
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3666
+ ## # minute <dbl>, time_hour <dttm>
3143
3667
  \end{verbatim}
3144
3668
 
3145
3669
  \subsection{Filtering with NA (Not
@@ -3172,7 +3696,7 @@ condition, where the row with R:NA does not.
3172
3696
 
3173
3697
  \begin{Shaded}
3174
3698
  \begin{Highlighting}[]
3175
- \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\WarningTok{:x} \OperatorTok{\textgreater{}} \DecValTok{1}\NormalTok{)}
3699
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]} \OperatorTok{\textgreater{}} \DecValTok{1}\NormalTok{)}
3176
3700
  \end{Highlighting}
3177
3701
  \end{Shaded}
3178
3702
 
@@ -3187,7 +3711,7 @@ To match an NA use method 'is\_\_na'
3187
3711
 
3188
3712
  \begin{Shaded}
3189
3713
  \begin{Highlighting}[]
3190
- \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{((}\WarningTok{:x}\AttributeTok{.is\_\_na}\NormalTok{) }\OperatorTok{|}\NormalTok{ (}\WarningTok{:x} \OperatorTok{\textgreater{}} \DecValTok{1}\NormalTok{))}
3714
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{((}\ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]}\AttributeTok{.is\_\_na}\NormalTok{) }\OperatorTok{|}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]} \OperatorTok{\textgreater{}} \DecValTok{1}\NormalTok{))}
3191
3715
  \end{Highlighting}
3192
3716
  \end{Shaded}
3193
3717
 
@@ -3211,40 +3735,42 @@ Arrange reorders the rows of a data frame by the given arguments.
3211
3735
 
3212
3736
  \begin{verbatim}
3213
3737
  ## # A tibble: 6 x 19
3214
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3215
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3216
- ## 1 2013 1 1 517 515 2 830 819
3217
- ## 2 2013 1 1 533 529 4 850 830
3218
- ## 3 2013 1 1 542 540 2 923 850
3219
- ## 4 2013 1 1 544 545 -1 1004 1022
3220
- ## 5 2013 1 1 554 600 -6 812 837
3221
- ## 6 2013 1 1 554 558 -4 740 728
3222
- ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3223
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3224
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3738
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3739
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3740
+ ## 1 2013 1 1 517 515 2 830
3741
+ ## 2 2013 1 1 533 529 4 850
3742
+ ## 3 2013 1 1 542 540 2 923
3743
+ ## 4 2013 1 1 544 545 -1 1004
3744
+ ## 5 2013 1 1 554 600 -6 812
3745
+ ## 6 2013 1 1 554 558 -4 740
3746
+ ## # i 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3747
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3748
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3749
+ ## # minute <dbl>, time_hour <dttm>
3225
3750
  \end{verbatim}
3226
3751
 
3227
3752
  To arrange in descending order, use function `desc'
3228
3753
 
3229
3754
  \begin{Shaded}
3230
3755
  \begin{Highlighting}[]
3231
- \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.arrange}\NormalTok{(}\WarningTok{:dep\_delay}\AttributeTok{.desc}\NormalTok{)}\AttributeTok{.head}
3756
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.arrange}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:dep\_delay}\KeywordTok{]}\AttributeTok{.desc}\NormalTok{)}\AttributeTok{.head}
3232
3757
  \end{Highlighting}
3233
3758
  \end{Shaded}
3234
3759
 
3235
3760
  \begin{verbatim}
3236
3761
  ## # A tibble: 6 x 19
3237
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3238
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3239
- ## 1 2013 1 9 641 900 1301 1242 1530
3240
- ## 2 2013 6 15 1432 1935 1137 1607 2120
3241
- ## 3 2013 1 10 1121 1635 1126 1239 1810
3242
- ## 4 2013 9 20 1139 1845 1014 1457 2210
3243
- ## 5 2013 7 22 845 1600 1005 1044 1815
3244
- ## 6 2013 4 10 1100 1900 960 1342 2211
3245
- ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3246
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3247
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3762
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3763
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3764
+ ## 1 2013 1 9 641 900 1301 1242
3765
+ ## 2 2013 6 15 1432 1935 1137 1607
3766
+ ## 3 2013 1 10 1121 1635 1126 1239
3767
+ ## 4 2013 9 20 1139 1845 1014 1457
3768
+ ## 5 2013 7 22 845 1600 1005 1044
3769
+ ## 6 2013 4 10 1100 1900 960 1342
3770
+ ## # i 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3771
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3772
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3773
+ ## # minute <dbl>, time_hour <dttm>
3248
3774
  \end{verbatim}
3249
3775
 
3250
3776
  \subsection{Selecting columns}\label{selecting-columns}
@@ -3273,7 +3799,7 @@ It is also possible to select column in a given range
3273
3799
 
3274
3800
  \begin{Shaded}
3275
3801
  \begin{Highlighting}[]
3276
- \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.select}\NormalTok{(}\WarningTok{:year}\AttributeTok{.up\_to} \OperatorTok{:}\NormalTok{day)}\AttributeTok{.head}
3802
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.select}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:year}\KeywordTok{]}\AttributeTok{.up\_to}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:day}\KeywordTok{]}\NormalTok{))}\AttributeTok{.head}
3277
3803
  \end{Highlighting}
3278
3804
  \end{Shaded}
3279
3805
 
@@ -3335,17 +3861,18 @@ column order is `Everything':
3335
3861
 
3336
3862
  \begin{verbatim}
3337
3863
  ## # A tibble: 6 x 19
3338
- ## year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time
3339
- ## <int> <int> <int> <int> <int> <dbl> <int> <int>
3340
- ## 1 2013 1 1 517 515 2 830 819
3341
- ## 2 2013 1 1 533 529 4 850 830
3342
- ## 3 2013 1 1 542 540 2 923 850
3343
- ## 4 2013 1 1 544 545 -1 1004 1022
3344
- ## 5 2013 1 1 554 600 -6 812 837
3345
- ## 6 2013 1 1 554 558 -4 740 728
3346
- ## # i 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
3347
- ## # tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
3348
- ## # hour <dbl>, minute <dbl>, time_hour <dttm>
3864
+ ## year month day dep_time sched_dep_time dep_delay arr_time
3865
+ ## <int> <int> <int> <int> <int> <dbl> <int>
3866
+ ## 1 2013 1 1 517 515 2 830
3867
+ ## 2 2013 1 1 533 529 4 850
3868
+ ## 3 2013 1 1 542 540 2 923
3869
+ ## 4 2013 1 1 544 545 -1 1004
3870
+ ## 5 2013 1 1 554 600 -6 812
3871
+ ## 6 2013 1 1 554 558 -4 740
3872
+ ## # i 12 more variables: sched_arr_time <int>, arr_delay <dbl>,
3873
+ ## # carrier <chr>, flight <int>, tailnum <chr>, origin <chr>,
3874
+ ## # dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
3875
+ ## # minute <dbl>, time_hour <dttm>
3349
3876
  \end{verbatim}
3350
3877
 
3351
3878
  \subsection{Add variables to a dataframe with
@@ -3354,7 +3881,7 @@ column order is `Everything':
3354
3881
  \begin{Shaded}
3355
3882
  \begin{Highlighting}[]
3356
3883
  \NormalTok{flights\_sm }\OperatorTok{=}\NormalTok{ flights}\AttributeTok{.}
3357
- \AttributeTok{select}\NormalTok{((}\WarningTok{:year}\AttributeTok{.up\_to} \OperatorTok{:}\NormalTok{day),}
3884
+ \AttributeTok{select}\NormalTok{((}\ConstantTok{R}\KeywordTok{[}\WarningTok{:year}\KeywordTok{]}\AttributeTok{.up\_to}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:day}\KeywordTok{]}\NormalTok{)),}
3358
3885
  \ConstantTok{E}\AttributeTok{.ends\_with}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}delay\textquotesingle{}}\NormalTok{),}
3359
3886
  \WarningTok{:distance}\NormalTok{,}
3360
3887
  \WarningTok{:air\_time}\NormalTok{)}
@@ -3378,8 +3905,8 @@ column order is `Everything':
3378
3905
  \begin{Shaded}
3379
3906
  \begin{Highlighting}[]
3380
3907
  \NormalTok{flights\_sm }\OperatorTok{=}\NormalTok{ flights\_sm}\AttributeTok{.}
3381
- \AttributeTok{mutate}\NormalTok{(}\WarningTok{gain:} \WarningTok{:dep\_delay} \OperatorTok{{-}} \WarningTok{:arr\_delay}\NormalTok{,}
3382
- \WarningTok{speed:} \WarningTok{:distance} \OperatorTok{/} \WarningTok{:air\_time} \OperatorTok{*} \DecValTok{60}\NormalTok{)}
3908
+ \AttributeTok{mutate}\NormalTok{(}\WarningTok{gain:} \ConstantTok{R}\KeywordTok{[}\WarningTok{:dep\_delay}\KeywordTok{]} \OperatorTok{{-}} \ConstantTok{R}\KeywordTok{[}\WarningTok{:arr\_delay}\KeywordTok{]}\NormalTok{,}
3909
+ \WarningTok{speed:} \ConstantTok{R}\KeywordTok{[}\WarningTok{:distance}\KeywordTok{]} \OperatorTok{/} \ConstantTok{R}\KeywordTok{[}\WarningTok{:air\_time}\KeywordTok{]} \OperatorTok{*} \DecValTok{60}\NormalTok{)}
3383
3910
  \FunctionTok{puts}\NormalTok{ flights\_sm}\AttributeTok{.head}
3384
3911
  \end{Highlighting}
3385
3912
  \end{Shaded}
@@ -3420,7 +3947,7 @@ given group:
3420
3947
  \begin{Shaded}
3421
3948
  \begin{Highlighting}[]
3422
3949
  \NormalTok{by\_day }\OperatorTok{=}\NormalTok{ flights}\AttributeTok{.group\_by}\NormalTok{(}\WarningTok{:year}\NormalTok{, }\WarningTok{:month}\NormalTok{, }\WarningTok{:day}\NormalTok{)}
3423
- \FunctionTok{puts}\NormalTok{ by\_day}\AttributeTok{.summarise}\NormalTok{(}\WarningTok{delay:} \WarningTok{:dep\_delay}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{))}\AttributeTok{.head}
3950
+ \FunctionTok{puts}\NormalTok{ by\_day}\AttributeTok{.summarise}\NormalTok{(}\WarningTok{delay:} \ConstantTok{R}\KeywordTok{[}\WarningTok{:dep\_delay}\KeywordTok{]}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{))}\AttributeTok{.head}
3424
3951
  \end{Highlighting}
3425
3952
  \end{Shaded}
3426
3953
 
@@ -3446,9 +3973,9 @@ other:
3446
3973
  \AttributeTok{group\_by}\NormalTok{(}\WarningTok{:dest}\NormalTok{)}\AttributeTok{.}
3447
3974
  \AttributeTok{summarise}\NormalTok{(}
3448
3975
  \WarningTok{count:} \ConstantTok{E}\AttributeTok{.n}\NormalTok{,}
3449
- \WarningTok{dist:} \WarningTok{:distance}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{),}
3450
- \WarningTok{delay:} \WarningTok{:arr\_delay}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{))}\AttributeTok{.}
3451
- \AttributeTok{filter}\NormalTok{(}\WarningTok{:count} \OperatorTok{\textgreater{}} \DecValTok{20}\NormalTok{, }\WarningTok{:dest} \OperatorTok{!=} \StringTok{"NHL"}\NormalTok{)}
3976
+ \WarningTok{dist:} \ConstantTok{R}\KeywordTok{[}\WarningTok{:distance}\KeywordTok{]}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{),}
3977
+ \WarningTok{delay:} \ConstantTok{R}\KeywordTok{[}\WarningTok{:arr\_delay}\KeywordTok{]}\AttributeTok{.mean}\NormalTok{(}\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{))}\AttributeTok{.}
3978
+ \AttributeTok{filter}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:count}\KeywordTok{]} \OperatorTok{\textgreater{}} \DecValTok{20}\NormalTok{, }\ConstantTok{R}\KeywordTok{[}\WarningTok{:dest}\KeywordTok{]} \OperatorTok{!=} \StringTok{"NHL"}\NormalTok{)}
3452
3979
 
3453
3980
  \FunctionTok{puts}\NormalTok{ delays}\AttributeTok{.head}
3454
3981
  \end{Highlighting}
@@ -3468,77 +3995,66 @@ other:
3468
3995
 
3469
3996
  \section{Using Data Table}\label{using-data-table}
3470
3997
 
3471
- The next chunk reads the \textbf{flights14} sample (same file as the
3472
- data.table vignette). Prefer \textbf{downloading in Ruby} and
3473
- \textbf{\texttt{R.fread} on a local path}:
3474
- \texttt{data.table::fread("https://…")} runs the HTTP transfer
3475
- \textbf{inside R} while the Galaaz bridge waits on a \textbf{single}
3476
- eval; if the remote server stalls, that looks like an intermittent
3477
- ``hang'' and eventually hits the \textbf{per-eval} bridge timeout.
3478
- Ruby's \textbf{\texttt{Net::HTTP}} \texttt{open\_timeout} /
3479
- \texttt{read\_timeout} fail fast with a clear error instead. The chunk
3480
- passes \textbf{\texttt{nrows:}} to \textbf{\texttt{fread}} so a single
3481
- bridge eval does not have to materialize the full
3482
- \textasciitilde1.2M-row table during a gknit run.
3998
+ The next chunk converts the \textbf{nycflights13} \texttt{flights}
3999
+ tibble already loaded above into a \textbf{\texttt{data.table}}. That
4000
+ keeps the manual offline and avoids downloading a remote CSV during
4001
+ gknit (network stalls look like bridge hangs when the transfer runs
4002
+ inside a single R eval).
3483
4003
 
3484
4004
  \begin{Shaded}
3485
4005
  \begin{Highlighting}[]
3486
- \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}net/http\textquotesingle{}}
3487
- \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}uri\textquotesingle{}}
3488
- \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}tmpdir\textquotesingle{}}
3489
-
3490
4006
  \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}data.table\textquotesingle{}}\NormalTok{)}
3491
4007
 
3492
- \NormalTok{url }\OperatorTok{=} \ConstantTok{URI}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}https://raw.githubusercontent.com/Rdatatable/data.table/master/vignettes/flights14.csv\textquotesingle{}}\NormalTok{)}
3493
- \NormalTok{csv }\OperatorTok{=} \DataTypeTok{File}\AttributeTok{.join}\NormalTok{(}\DataTypeTok{Dir}\AttributeTok{.tmpdir}\NormalTok{, }\StringTok{"galaaz\_manual\_flights14\_}\SpecialCharTok{\#\{}\DataTypeTok{Process}\AttributeTok{.pid}\SpecialCharTok{\}}\StringTok{.csv"}\NormalTok{)}
3494
- \ControlFlowTok{begin}
3495
- \DataTypeTok{Net}\OperatorTok{::}\ConstantTok{HTTP}\AttributeTok{.start}\NormalTok{(url}\AttributeTok{.host}\NormalTok{, url}\AttributeTok{.port}\NormalTok{, }\WarningTok{use\_ssl:} \DecValTok{true}\NormalTok{, }\WarningTok{open\_timeout:} \DecValTok{25}\NormalTok{, }\WarningTok{read\_timeout:} \DecValTok{120}\NormalTok{) }\ControlFlowTok{do} \OperatorTok{|}\NormalTok{http}\OperatorTok{|}
3496
- \NormalTok{ resp }\OperatorTok{=}\NormalTok{ http}\AttributeTok{.request\_get}\NormalTok{(url}\AttributeTok{.request\_uri}\NormalTok{)}
3497
- \FunctionTok{raise} \StringTok{"HTTP }\SpecialCharTok{\#\{}\NormalTok{resp}\AttributeTok{.code}\SpecialCharTok{\}}\StringTok{"} \ControlFlowTok{unless}\NormalTok{ resp}\AttributeTok{.is\_a?}\NormalTok{(}\DataTypeTok{Net}\OperatorTok{::}\DataTypeTok{HTTPSuccess}\NormalTok{)}
3498
-
3499
- \DataTypeTok{File}\AttributeTok{.binwrite}\NormalTok{(csv, resp}\AttributeTok{.body}\NormalTok{)}
3500
- \ControlFlowTok{end}
3501
-
3502
- \CommentTok{\# Cap rows so one bridge eval stays short on slow disks (full file is \textasciitilde{}1.2M rows).}
3503
- \NormalTok{ flights }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.fread}\NormalTok{(csv, }\WarningTok{nrows:} \DecValTok{120\_000}\NormalTok{)}
3504
- \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.dim}
3505
- \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.head}\NormalTok{(flights, }\DecValTok{12}\NormalTok{)}
3506
- \ControlFlowTok{ensure}
3507
- \DataTypeTok{File}\AttributeTok{.unlink}\NormalTok{(csv) }\ControlFlowTok{if}\NormalTok{ csv }\OperatorTok{\&\&} \DataTypeTok{File}\AttributeTok{.exist?}\NormalTok{(csv)}
3508
- \ControlFlowTok{end}
3509
- \end{Highlighting}
3510
- \end{Shaded}
3511
-
3512
- \begin{verbatim}
3513
- ## [1] 120000 11
3514
- ## year month day dep_delay arr_delay carrier origin dest air_time
3515
- ## <int> <int> <int> <int> <int> <char> <char> <char> <int>
3516
- ## 1: 2014 1 1 14 13 AA JFK LAX 359
3517
- ## 2: 2014 1 1 -3 13 AA JFK LAX 363
3518
- ## 3: 2014 1 1 2 9 AA JFK LAX 351
3519
- ## 4: 2014 1 1 -8 -26 AA LGA PBI 157
3520
- ## 5: 2014 1 1 2 1 AA JFK LAX 350
3521
- ## 6: 2014 1 1 4 0 AA EWR LAX 339
3522
- ## 7: 2014 1 1 -2 -18 AA JFK LAX 338
3523
- ## 8: 2014 1 1 -3 -14 AA JFK LAX 356
3524
- ## 9: 2014 1 1 -1 -17 AA JFK MIA 161
3525
- ## 10: 2014 1 1 -2 -14 AA JFK SEA 349
3526
- ## 11: 2014 1 1 -5 -17 AA EWR MIA 161
3527
- ## 12: 2014 1 1 7 -5 AA JFK SFO 365
3528
- ## distance hour
3529
- ## <int> <int>
3530
- ## 1: 2475 9
3531
- ## 2: 2475 11
3532
- ## 3: 2475 19
3533
- ## 4: 1035 7
3534
- ## 5: 2475 13
3535
- ## 6: 2454 18
3536
- ## 7: 2475 21
3537
- ## 8: 2475 15
3538
- ## 9: 1089 15
3539
- ## 10: 2422 18
3540
- ## 11: 1085 16
3541
- ## 12: 2586 17
4008
+ \NormalTok{flights }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.as\_\_data\_\_table}\NormalTok{(}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:flights}\KeywordTok{]}\NormalTok{)}
4009
+ \FunctionTok{puts}\NormalTok{ flights}\AttributeTok{.dim}
4010
+ \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.head}\NormalTok{(flights, }\DecValTok{12}\NormalTok{)}
4011
+ \end{Highlighting}
4012
+ \end{Shaded}
4013
+
4014
+ \begin{verbatim}
4015
+ ## [1] 336776 19
4016
+ ## year month day dep_time sched_dep_time dep_delay arr_time
4017
+ ## <int> <int> <int> <int> <int> <num> <int>
4018
+ ## 1: 2013 1 1 517 515 2 830
4019
+ ## 2: 2013 1 1 533 529 4 850
4020
+ ## 3: 2013 1 1 542 540 2 923
4021
+ ## 4: 2013 1 1 544 545 -1 1004
4022
+ ## 5: 2013 1 1 554 600 -6 812
4023
+ ## 6: 2013 1 1 554 558 -4 740
4024
+ ## 7: 2013 1 1 555 600 -5 913
4025
+ ## 8: 2013 1 1 557 600 -3 709
4026
+ ## 9: 2013 1 1 557 600 -3 838
4027
+ ## 10: 2013 1 1 558 600 -2 753
4028
+ ## 11: 2013 1 1 558 600 -2 849
4029
+ ## 12: 2013 1 1 558 600 -2 853
4030
+ ## sched_arr_time arr_delay carrier flight tailnum origin dest
4031
+ ## <int> <num> <char> <int> <char> <char> <char>
4032
+ ## 1: 819 11 UA 1545 N14228 EWR IAH
4033
+ ## 2: 830 20 UA 1714 N24211 LGA IAH
4034
+ ## 3: 850 33 AA 1141 N619AA JFK MIA
4035
+ ## 4: 1022 -18 B6 725 N804JB JFK BQN
4036
+ ## 5: 837 -25 DL 461 N668DN LGA ATL
4037
+ ## 6: 728 12 UA 1696 N39463 EWR ORD
4038
+ ## 7: 854 19 B6 507 N516JB EWR FLL
4039
+ ## 8: 723 -14 EV 5708 N829AS LGA IAD
4040
+ ## 9: 846 -8 B6 79 N593JB JFK MCO
4041
+ ## 10: 745 8 AA 301 N3ALAA LGA ORD
4042
+ ## 11: 851 -2 B6 49 N793JB JFK PBI
4043
+ ## 12: 856 -3 B6 71 N657JB JFK TPA
4044
+ ## air_time distance hour minute time_hour
4045
+ ## <num> <num> <num> <num> <POSc>
4046
+ ## 1: 227 1400 5 15 2013-01-01 05:00:00
4047
+ ## 2: 227 1416 5 29 2013-01-01 05:00:00
4048
+ ## 3: 160 1089 5 40 2013-01-01 05:00:00
4049
+ ## 4: 183 1576 5 45 2013-01-01 05:00:00
4050
+ ## 5: 116 762 6 0 2013-01-01 06:00:00
4051
+ ## 6: 150 719 5 58 2013-01-01 05:00:00
4052
+ ## 7: 158 1065 6 0 2013-01-01 06:00:00
4053
+ ## 8: 53 229 6 0 2013-01-01 06:00:00
4054
+ ## 9: 140 944 6 0 2013-01-01 06:00:00
4055
+ ## 10: 138 733 6 0 2013-01-01 06:00:00
4056
+ ## 11: 149 1028 6 0 2013-01-01 06:00:00
4057
+ ## 12: 158 1005 6 0 2013-01-01 06:00:00
3542
4058
  \end{verbatim}
3543
4059
 
3544
4060
  \begin{Shaded}
@@ -3570,7 +4086,7 @@ bridge eval does not have to materialize the full
3570
4086
  \begin{Shaded}
3571
4087
  \begin{Highlighting}[]
3572
4088
  \CommentTok{\# subset rows in i}
3573
- \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\NormalTok{(}\WarningTok{:origin}\AttributeTok{.eq} \StringTok{"JFK"}\NormalTok{) }\OperatorTok{\&}\NormalTok{ (}\WarningTok{:month}\AttributeTok{.eq} \DecValTok{6}\NormalTok{)}\KeywordTok{]}
4089
+ \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:origin}\KeywordTok{]}\AttributeTok{.eq} \StringTok{"JFK"}\NormalTok{) }\OperatorTok{\&}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:month}\KeywordTok{]}\AttributeTok{.eq} \DecValTok{6}\NormalTok{)}\KeywordTok{]}
3574
4090
  \FunctionTok{puts}\NormalTok{ ans}\AttributeTok{.head}
3575
4091
 
3576
4092
  \CommentTok{\# Get the first two rows from flights.}
@@ -3585,15 +4101,42 @@ bridge eval does not have to materialize the full
3585
4101
  \end{Shaded}
3586
4102
 
3587
4103
  \begin{verbatim}
3588
- ## Empty data.table (0 rows and 11 cols): year,month,day,dep_delay,arr_delay,carrier...
3589
- ## year month day dep_delay arr_delay carrier origin dest air_time
3590
- ## <int> <int> <int> <int> <int> <char> <char> <char> <int>
3591
- ## 1: 2014 1 1 14 13 AA JFK LAX 359
3592
- ## 2: 2014 1 1 -3 13 AA JFK LAX 363
3593
- ## distance hour
3594
- ## <int> <int>
3595
- ## 1: 2475 9
3596
- ## 2: 2475 11
4104
+ ## year month day dep_time sched_dep_time dep_delay arr_time
4105
+ ## <int> <int> <int> <int> <int> <num> <int>
4106
+ ## 1: 2013 6 1 2 2359 3 341
4107
+ ## 2: 2013 6 1 538 545 -7 925
4108
+ ## 3: 2013 6 1 539 540 -1 832
4109
+ ## 4: 2013 6 1 553 600 -7 700
4110
+ ## 5: 2013 6 1 554 600 -6 851
4111
+ ## 6: 2013 6 1 557 600 -3 934
4112
+ ## sched_arr_time arr_delay carrier flight tailnum origin dest
4113
+ ## <int> <num> <char> <int> <char> <char> <char>
4114
+ ## 1: 350 -9 B6 739 N618JB JFK PSE
4115
+ ## 2: 922 3 B6 725 N806JB JFK BQN
4116
+ ## 3: 840 -8 AA 701 N5EAAA JFK MIA
4117
+ ## 4: 711 -11 EV 5716 N835AS JFK IAD
4118
+ ## 5: 908 -17 UA 1159 N33132 JFK LAX
4119
+ ## 6: 942 -8 B6 715 N766JB JFK SJU
4120
+ ## air_time distance hour minute time_hour
4121
+ ## <num> <num> <num> <num> <POSc>
4122
+ ## 1: 200 1617 23 59 2013-06-01 23:00:00
4123
+ ## 2: 203 1576 5 45 2013-06-01 05:00:00
4124
+ ## 3: 140 1089 5 40 2013-06-01 05:00:00
4125
+ ## 4: 42 228 6 0 2013-06-01 06:00:00
4126
+ ## 5: 330 2475 6 0 2013-06-01 06:00:00
4127
+ ## 6: 198 1598 6 0 2013-06-01 06:00:00
4128
+ ## year month day dep_time sched_dep_time dep_delay arr_time
4129
+ ## <int> <int> <int> <int> <int> <num> <int>
4130
+ ## 1: 2013 1 1 517 515 2 830
4131
+ ## 2: 2013 1 1 533 529 4 850
4132
+ ## sched_arr_time arr_delay carrier flight tailnum origin dest
4133
+ ## <int> <num> <char> <int> <char> <char> <char>
4134
+ ## 1: 819 11 UA 1545 N14228 EWR IAH
4135
+ ## 2: 830 20 UA 1714 N24211 LGA IAH
4136
+ ## air_time distance hour minute time_hour
4137
+ ## <num> <num> <num> <num> <POSc>
4138
+ ## 1: 227 1400 5 15 2013-01-01 05:00:00
4139
+ ## 2: 227 1416 5 29 2013-01-01 05:00:00
3597
4140
  \end{verbatim}
3598
4141
 
3599
4142
  \begin{Shaded}
@@ -3606,23 +4149,23 @@ bridge eval does not have to materialize the full
3606
4149
 
3607
4150
  \CommentTok{\# arr\_delay as data.table (not plain vector).}
3608
4151
 
3609
- \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\WarningTok{:all}\NormalTok{, }\WarningTok{:arr\_delay}\AttributeTok{.list}\KeywordTok{]}
4152
+ \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\WarningTok{:all}\NormalTok{, }\ConstantTok{R}\KeywordTok{[}\WarningTok{:arr\_delay}\KeywordTok{]}\AttributeTok{.list}\KeywordTok{]}
3610
4153
  \FunctionTok{puts}\NormalTok{ ans}\AttributeTok{.head}
3611
4154
 
3612
- \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\WarningTok{:all}\NormalTok{, }\ConstantTok{E}\AttributeTok{.list}\NormalTok{(}\WarningTok{:arr\_delay}\NormalTok{, }\WarningTok{:dep\_delay}\NormalTok{)}\KeywordTok{]}
4155
+ \NormalTok{ans }\OperatorTok{=}\NormalTok{ flights}\KeywordTok{[}\WarningTok{:all}\NormalTok{, }\ConstantTok{E}\AttributeTok{.list}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:arr\_delay}\KeywordTok{]}\NormalTok{, }\ConstantTok{R}\KeywordTok{[}\WarningTok{:dep\_delay}\KeywordTok{]}\NormalTok{)}\KeywordTok{]}
3613
4156
  \end{Highlighting}
3614
4157
  \end{Shaded}
3615
4158
 
3616
4159
  \begin{verbatim}
3617
- ## [1] 13 13 9 -26 1 0
4160
+ ## [1] 11 20 33 -18 -25 12
3618
4161
  ## arr_delay
3619
- ## <int>
3620
- ## 1: 13
3621
- ## 2: 13
3622
- ## 3: 9
3623
- ## 4: -26
3624
- ## 5: 1
3625
- ## 6: 0
4162
+ ## <num>
4163
+ ## 1: 11
4164
+ ## 2: 20
4165
+ ## 3: 33
4166
+ ## 4: -18
4167
+ ## 5: -25
4168
+ ## 6: 12
3626
4169
  \end{verbatim}
3627
4170
 
3628
4171
  \section{Apache Arrow}\label{apache-arrow}
@@ -3639,10 +4182,10 @@ ordinary Ruby structures (arrays of row hashes), and
3639
4182
  \textbf{\texttt{collect()}} to materialize a tibble when you need
3640
4183
  in-memory R rows.
3641
4184
 
3642
- That pattern matches production use: \textbf{JRuby threads} (or
3643
- sequential code) assemble many rows in Ruby; you pay \textbf{one}
3644
- bridge-heavy handoff to R; \textbf{dplyr} runs vectorised work on the
3645
- Arrow table in R.
4185
+ That pattern matches production use: \textbf{JRuby threads} or a
4186
+ \textbf{multi-process CRuby} app (or sequential code) assemble many rows
4187
+ in Ruby; you pay \textbf{one} bridge-heavy handoff to R; \textbf{dplyr}
4188
+ runs vectorised work on the Arrow table in R.
3646
4189
 
3647
4190
  \textbf{Prerequisites:} install R packages \textbf{\texttt{arrow}} and
3648
4191
  \textbf{\texttt{dplyr}}. Run scripts with
@@ -3681,8 +4224,12 @@ can knit quickly; increase \texttt{thread\_count} and
3681
4224
  \begin{Shaded}
3682
4225
  \begin{Highlighting}[]
3683
4226
  \CommentTok{\# Scaled{-}down version of slow{-}specs/arrow\_large\_pipeline\_spec.rb.}
3684
- \ControlFlowTok{unless} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Support}\AttributeTok{.eval}\NormalTok{(}\StringTok{"requireNamespace(\textquotesingle{}arrow\textquotesingle{}, quietly=TRUE) \&\& requireNamespace(\textquotesingle{}dplyr\textquotesingle{}, quietly=TRUE)"}\NormalTok{) }\OperatorTok{==} \DecValTok{true}
3685
- \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}(Skip: need arrow + dplyr in R; use bin/galaaz{-}jruby outside gKnit.)\textquotesingle{}}
4227
+ \NormalTok{arrow\_ok }\OperatorTok{=} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Support}\AttributeTok{.eval}\NormalTok{(}
4228
+ \StringTok{"requireNamespace(\textquotesingle{}arrow\textquotesingle{}, quietly=TRUE) \&\& "} \OperatorTok{+}
4229
+ \StringTok{"requireNamespace(\textquotesingle{}dplyr\textquotesingle{}, quietly=TRUE)"}\NormalTok{)}
4230
+ \ControlFlowTok{unless}\NormalTok{ arrow\_ok }\OperatorTok{==} \DecValTok{true}
4231
+ \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}(Skip: need arrow + dplyr in R; \textquotesingle{}} \OperatorTok{+}
4232
+ \VerbatimStringTok{\textquotesingle{}use bin/galaaz{-}jruby outside gKnit.)\textquotesingle{}}
3686
4233
  \ControlFlowTok{else}
3687
4234
  \NormalTok{ thread\_count }\OperatorTok{=} \DecValTok{4}
3688
4235
  \NormalTok{ rows\_per\_thread }\OperatorTok{=} \DecValTok{500}
@@ -3716,7 +4263,7 @@ can knit quickly; increase \texttt{thread\_count} and
3716
4263
  \NormalTok{ grouped,}
3717
4264
  \WarningTok{n:} \ConstantTok{E}\AttributeTok{.n}\NormalTok{(),}
3718
4265
  \WarningTok{total:} \ConstantTok{E}\AttributeTok{.sum}\NormalTok{(}\WarningTok{:value}\NormalTok{),}
3719
- \WarningTok{wsum:} \ConstantTok{E}\AttributeTok{.sum}\NormalTok{(}\WarningTok{:value} \OperatorTok{*} \WarningTok{:weight}\NormalTok{)}
4266
+ \WarningTok{wsum:} \ConstantTok{E}\AttributeTok{.sum}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:value}\KeywordTok{]} \OperatorTok{*} \ConstantTok{R}\KeywordTok{[}\WarningTok{:weight}\KeywordTok{]}\NormalTok{)}
3720
4267
  \NormalTok{ )}
3721
4268
  \NormalTok{ out }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.dplyr\_\_\_collect}\NormalTok{(summarised)}
3722
4269
 
@@ -3725,7 +4272,9 @@ can knit quickly; increase \texttt{thread\_count} and
3725
4272
 
3726
4273
  \NormalTok{ total\_n }\OperatorTok{=} \DecValTok{0}
3727
4274
  \NormalTok{ (}\DecValTok{1}\OperatorTok{..}\NormalTok{(out}\AttributeTok{.nrow} \OperatorTok{\textgreater{}\textgreater{}} \DecValTok{0}\NormalTok{))}\AttributeTok{.each} \OperatorTok{\{} \OperatorTok{|}\NormalTok{i}\OperatorTok{|}\NormalTok{ total\_n }\OperatorTok{+=}\NormalTok{ (out}\KeywordTok{[[}\CharTok{\textquotesingle{}n\textquotesingle{}}\KeywordTok{]][}\NormalTok{i}\KeywordTok{]} \OperatorTok{\textgreater{}\textgreater{}} \DecValTok{0}\NormalTok{) }\OperatorTok{\}}
3728
- \FunctionTok{puts} \StringTok{"Sum of group counts n (should equal }\SpecialCharTok{\#\{}\NormalTok{thread\_count }\OperatorTok{*}\NormalTok{ rows\_per\_thread}\SpecialCharTok{\}}\StringTok{): }\SpecialCharTok{\#\{}\NormalTok{total\_n}\SpecialCharTok{\}}\StringTok{"}
4275
+ \FunctionTok{puts} \StringTok{"Sum of group counts n "} \OperatorTok{+}
4276
+ \StringTok{"(should equal }\SpecialCharTok{\#\{}\NormalTok{thread\_count }\OperatorTok{*}\NormalTok{ rows\_per\_thread}\SpecialCharTok{\}}\StringTok{): "} \OperatorTok{+}
4277
+ \StringTok{"}\SpecialCharTok{\#\{}\NormalTok{total\_n}\SpecialCharTok{\}}\StringTok{"}
3729
4278
  \ControlFlowTok{end}
3730
4279
  \end{Highlighting}
3731
4280
  \end{Shaded}
@@ -3788,11 +4337,14 @@ dataset}\label{example-deseq2-on-the-airway-dataset}
3788
4337
  The script
3789
4338
  \textbf{\texttt{examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}}
3790
4339
  is the canonical version in the repository. Run it from the
3791
- \textbf{Galaaz repository root} with JRuby, for example:
4340
+ \textbf{Galaaz repository root} with either engine, for example:
3792
4341
 
3793
4342
  \begin{Shaded}
3794
4343
  \begin{Highlighting}[]
3795
- \NormalTok{bin/galaaz{-}jruby examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}
4344
+ \NormalTok{bin/galaaz{-}ruby \textbackslash{}}
4345
+ \NormalTok{ examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}
4346
+ \NormalTok{\# or: bin/galaaz{-}jruby \textbackslash{}}
4347
+ \NormalTok{\# examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}
3796
4348
  \end{Highlighting}
3797
4349
  \end{Shaded}
3798
4350
 
@@ -3809,14 +4361,14 @@ The workflow in Ruby mirrors a standard DESeq2 vignette:
3809
4361
  \textbf{\texttt{R.data(\textquotesingle{}airway\textquotesingle{})}}
3810
4362
  so the object exists in R's global environment.
3811
4363
  \item
3812
- \textbf{\texttt{airway\ =\ \textasciitilde{}:airway}} pulls the
4364
+ \textbf{\texttt{airway\ =\ \textasciitilde{}R{[}:airway{]}}} pulls the
3813
4365
  experiment into a Galaaz wrapper so you can pass it to R functions as
3814
4366
  a Ruby value.
3815
4367
  \item
3816
- \textbf{\texttt{R.DESeqDataSet(...,\ design:\ (:all.til\ :cell\ +\ :dex))}}
4368
+ \textbf{\texttt{R.DESeqDataSet(...,\ design:\ (R{[}:all{]}.til\ R{[}:cell{]}\ +\ R{[}:dex{]}))}}
3817
4369
  builds the \textbf{\texttt{DESeqDataSet}}. The
3818
- \textbf{\texttt{(:all.til\ :cell\ +\ :dex)}} form is Galaaz's way of
3819
- passing the one-sided formula
4370
+ \textbf{\texttt{(R{[}:all{]}.til\ R{[}:cell{]}\ +\ R{[}:dex{]})}} form
4371
+ is Galaaz's way of passing the one-sided formula
3820
4372
  \textbf{\texttt{\textasciitilde{}\ cell\ +\ dex}} (adjust for the
3821
4373
  design you need).
3822
4374
  \item
@@ -3848,8 +4400,9 @@ Below is the full listing (same as the file in the repository). It is
3848
4400
 
3849
4401
  \begin{Shaded}
3850
4402
  \begin{Highlighting}[]
3851
- \CommentTok{\# Canonical script: examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}
3852
- \CommentTok{\# Run: bin/galaaz{-}jruby examples/.../deseq2\_airway\_galaaz.rb (repo root).}
4403
+ \CommentTok{\# Canonical script:}
4404
+ \CommentTok{\# examples/bioconductor\_deseq2\_airway/deseq2\_airway\_galaaz.rb}
4405
+ \CommentTok{\# Run: bin/galaaz{-}ruby examples/.../deseq2\_airway\_galaaz.rb (repo root).}
3853
4406
 
3854
4407
  \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}galaaz\textquotesingle{}}
3855
4408
 
@@ -3857,10 +4410,10 @@ Below is the full listing (same as the file in the repository). It is
3857
4410
  \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}airway\textquotesingle{}}\NormalTok{)}
3858
4411
  \ConstantTok{R}\AttributeTok{.data}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}airway\textquotesingle{}}\NormalTok{)}
3859
4412
 
3860
- \NormalTok{airway }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:airway}
4413
+ \NormalTok{airway }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:airway}\KeywordTok{]}
3861
4414
 
3862
4415
  \CommentTok{\# Build DESeq2 dataset with one{-}sided formula: \textasciitilde{} cell + dex.}
3863
- \NormalTok{dds }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.}\DataTypeTok{DESeqDataSet}\NormalTok{(airway, }\WarningTok{design:}\NormalTok{ (}\WarningTok{:all}\AttributeTok{.til} \OperatorTok{:}\NormalTok{cell }\OperatorTok{+} \WarningTok{:dex}\NormalTok{))}
4416
+ \NormalTok{dds }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.}\DataTypeTok{DESeqDataSet}\NormalTok{(airway, }\WarningTok{design:}\NormalTok{ (}\ConstantTok{R}\KeywordTok{[}\WarningTok{:all}\KeywordTok{]}\AttributeTok{.til} \ConstantTok{R}\KeywordTok{[}\WarningTok{:cell}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:dex}\KeywordTok{]}\NormalTok{))}
3864
4417
 
3865
4418
  \CommentTok{\# Prefilter genes with almost no counts.}
3866
4419
  \NormalTok{keep }\OperatorTok{=} \ConstantTok{R}\AttributeTok{.rowSums}\NormalTok{(}\ConstantTok{R}\AttributeTok{.counts}\NormalTok{(dds)) }\OperatorTok{\textgreater{}=} \DecValTok{10}
@@ -3875,7 +4428,8 @@ Below is the full listing (same as the file in the repository). It is
3875
4428
  \FunctionTok{puts} \StringTok{"Genes after prefilter: }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.nrow}\NormalTok{(dds)}\SpecialCharTok{\}}\StringTok{"}
3876
4429
  \FunctionTok{puts} \StringTok{"Result rows: }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.nrow}\NormalTok{(res)}\SpecialCharTok{\}}\StringTok{"}
3877
4430
  \FunctionTok{puts} \StringTok{"Result columns: }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.colnames}\NormalTok{(res)}\SpecialCharTok{\}}\StringTok{"}
3878
- \FunctionTok{puts} \StringTok{"Significant genes (padj \textless{} 0.05): }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.sum}\NormalTok{(res}\AttributeTok{.padj} \OperatorTok{\textless{}} \FloatTok{0.05}\NormalTok{, }\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{)}\SpecialCharTok{\}}\StringTok{"}
4431
+ \FunctionTok{puts} \StringTok{"Significant genes (padj \textless{} 0.05): "} \OperatorTok{+}
4432
+ \StringTok{"}\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.sum}\NormalTok{(res}\AttributeTok{.padj} \OperatorTok{\textless{}} \FloatTok{0.05}\NormalTok{, }\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{)}\SpecialCharTok{\}}\StringTok{"}
3879
4433
 
3880
4434
  \NormalTok{res\_ordered }\OperatorTok{=}\NormalTok{ res}\KeywordTok{[}\ConstantTok{R}\AttributeTok{.order}\NormalTok{(res}\AttributeTok{.padj}\NormalTok{), }\WarningTok{:all}\KeywordTok{]}
3881
4435
  \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.head}\NormalTok{(}\ConstantTok{R}\AttributeTok{.as\_\_data\_\_frame}\NormalTok{(res\_ordered), }\DecValTok{10}\NormalTok{)}
@@ -3893,13 +4447,17 @@ loads the data and prints a short preview (it does \textbf{not} run
3893
4447
 
3894
4448
  \begin{Shaded}
3895
4449
  \begin{Highlighting}[]
3896
- \ControlFlowTok{unless} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Support}\AttributeTok{.eval}\NormalTok{(}\StringTok{"requireNamespace(\textquotesingle{}DESeq2\textquotesingle{}, quietly=TRUE) \&\& requireNamespace(\textquotesingle{}airway\textquotesingle{}, quietly=TRUE)"}\NormalTok{)}
3897
- \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}(Skip: install DESeq2 and airway via BiocManager in R to run the full example.)\textquotesingle{}}
4450
+ \NormalTok{deseq\_ok }\OperatorTok{=} \ConstantTok{R}\OperatorTok{::}\DataTypeTok{Support}\AttributeTok{.eval}\NormalTok{(}
4451
+ \StringTok{"requireNamespace(\textquotesingle{}DESeq2\textquotesingle{}, quietly=TRUE) \&\& "} \OperatorTok{+}
4452
+ \StringTok{"requireNamespace(\textquotesingle{}airway\textquotesingle{}, quietly=TRUE)"}\NormalTok{)}
4453
+ \ControlFlowTok{unless}\NormalTok{ deseq\_ok}
4454
+ \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}(Skip: install DESeq2 and airway via \textquotesingle{}} \OperatorTok{+}
4455
+ \VerbatimStringTok{\textquotesingle{}BiocManager in R for the full example.)\textquotesingle{}}
3898
4456
  \ControlFlowTok{else}
3899
4457
  \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}DESeq2\textquotesingle{}}\NormalTok{)}
3900
4458
  \ConstantTok{R}\AttributeTok{.library}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}airway\textquotesingle{}}\NormalTok{)}
3901
4459
  \ConstantTok{R}\AttributeTok{.data}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}airway\textquotesingle{}}\NormalTok{)}
3902
- \NormalTok{ airway }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:airway}
4460
+ \NormalTok{ airway }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:airway}\KeywordTok{]}
3903
4461
  \FunctionTok{puts} \VerbatimStringTok{\textquotesingle{}airway object (head of assay / dims via R):\textquotesingle{}}
3904
4462
  \FunctionTok{puts} \StringTok{"ncol(samples): }\SpecialCharTok{\#\{}\ConstantTok{R}\AttributeTok{.ncol}\NormalTok{(airway)}\SpecialCharTok{\}}\StringTok{"}
3905
4463
  \FunctionTok{puts} \ConstantTok{R}\AttributeTok{.head}\NormalTok{(}\ConstantTok{R}\AttributeTok{.assay}\NormalTok{(airway), }\DecValTok{3}\NormalTok{)}
@@ -3910,14 +4468,14 @@ loads the data and prints a short preview (it does \textbf{not} run
3910
4468
  \begin{verbatim}
3911
4469
  ## airway object (head of assay / dims via R):
3912
4470
  ## ncol(samples): [1] 8
3913
- ## SRR1039508 SRR1039509 SRR1039512 SRR1039513 SRR1039516
3914
- ## ENSG00000000003 679 448 873 408 1138
3915
- ## ENSG00000000005 0 0 0 0 0
3916
- ## ENSG00000000419 467 515 621 365 587
3917
- ## SRR1039517 SRR1039520 SRR1039521
3918
- ## ENSG00000000003 1047 770 572
3919
- ## ENSG00000000005 0 0 0
3920
- ## ENSG00000000419 799 417 508
4471
+ ## SRR1039508 SRR1039509 SRR1039512 SRR1039513
4472
+ ## ENSG00000000003 679 448 873 408
4473
+ ## ENSG00000000005 0 0 0 0
4474
+ ## ENSG00000000419 467 515 621 365
4475
+ ## SRR1039516 SRR1039517 SRR1039520 SRR1039521
4476
+ ## ENSG00000000003 1138 1047 770 572
4477
+ ## ENSG00000000005 0 0 0 0
4478
+ ## ENSG00000000419 587 799 417 508
3921
4479
  \end{verbatim}
3922
4480
 
3923
4481
  \section{Performance}\label{performance}
@@ -3962,10 +4520,10 @@ first prepare the data frame with the necessary data:
3962
4520
  \begin{Shaded}
3963
4521
  \begin{Highlighting}[]
3964
4522
  \CommentTok{\# :mtcars {-}\textgreater{} Ruby handle}
3965
- \NormalTok{mtcars }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\WarningTok{:mtcars}
4523
+ \NormalTok{mtcars }\OperatorTok{=} \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}
3966
4524
 
3967
4525
  \CommentTok{\# Row labels are not a plot column; copy them to car\_name.}
3968
- \NormalTok{mtcars}\AttributeTok{.car\_name} \OperatorTok{=} \ConstantTok{R}\AttributeTok{.rownames}\NormalTok{(}\WarningTok{:mtcars}\NormalTok{)}
4526
+ \NormalTok{mtcars}\AttributeTok{.car\_name} \OperatorTok{=} \ConstantTok{R}\AttributeTok{.rownames}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mtcars}\KeywordTok{]}\NormalTok{)}
3969
4527
 
3970
4528
  \CommentTok{\# Z{-}score mpg (mean/sd on mtcars.mpg); round to 2 decimals.}
3971
4529
  \NormalTok{mtcars}\AttributeTok{.mpg\_z} \OperatorTok{=}\NormalTok{ ((mtcars}\AttributeTok{.mpg} \OperatorTok{{-}}\NormalTok{ mtcars}\AttributeTok{.mpg.mean}\NormalTok{)}\OperatorTok{/}\NormalTok{mtcars}\AttributeTok{.mpg.sd}\NormalTok{)}\AttributeTok{.round} \DecValTok{2}
@@ -3984,20 +4542,20 @@ first prepare the data frame with the necessary data:
3984
4542
  \end{Shaded}
3985
4543
 
3986
4544
  \begin{verbatim}
3987
- ## mpg cyl disp hp drat wt qsec vs am gear carb
3988
- ## Cadillac Fleetwood 10.4 8 472 205 2.93 5.250 17.98 0 0 3 4
3989
- ## Lincoln Continental 10.4 8 460 215 3.00 5.424 17.82 0 0 3 4
3990
- ## Camaro Z28 13.3 8 350 245 3.73 3.840 15.41 0 0 3 4
3991
- ## Duster 360 14.3 8 360 245 3.21 3.570 15.84 0 0 3 4
3992
- ## Chrysler Imperial 14.7 8 440 230 3.23 5.345 17.42 0 0 3 4
3993
- ## Maserati Bora 15.0 8 301 335 3.54 3.570 14.60 0 1 5 8
3994
- ## car_name mpg_z mpg_type
3995
- ## Cadillac Fleetwood Cadillac Fleetwood -1.61 below
3996
- ## Lincoln Continental Lincoln Continental -1.61 below
3997
- ## Camaro Z28 Camaro Z28 -1.13 below
3998
- ## Duster 360 Duster 360 -0.96 below
3999
- ## Chrysler Imperial Chrysler Imperial -0.89 below
4000
- ## Maserati Bora Maserati Bora -0.84 below
4545
+ ## mpg cyl disp hp drat wt qsec vs am gear
4546
+ ## Cadillac Fleetwood 10.4 8 472 205 2.93 5.250 17.98 0 0 3
4547
+ ## Lincoln Continental 10.4 8 460 215 3.00 5.424 17.82 0 0 3
4548
+ ## Camaro Z28 13.3 8 350 245 3.73 3.840 15.41 0 0 3
4549
+ ## Duster 360 14.3 8 360 245 3.21 3.570 15.84 0 0 3
4550
+ ## Chrysler Imperial 14.7 8 440 230 3.23 5.345 17.42 0 0 3
4551
+ ## Maserati Bora 15.0 8 301 335 3.54 3.570 14.60 0 1 5
4552
+ ## carb car_name mpg_z mpg_type
4553
+ ## Cadillac Fleetwood 4 Cadillac Fleetwood -1.61 below
4554
+ ## Lincoln Continental 4 Lincoln Continental -1.61 below
4555
+ ## Camaro Z28 4 Camaro Z28 -1.13 below
4556
+ ## Duster 360 4 Duster 360 -0.96 below
4557
+ ## Chrysler Imperial 4 Chrysler Imperial -0.89 below
4558
+ ## Maserati Bora 8 Maserati Bora -0.84 below
4001
4559
  \end{verbatim}
4002
4560
 
4003
4561
  Now, let's plot the diverging bar plot. When using gKnit, you normally
@@ -4024,18 +4582,22 @@ we add `coord\_flip'.
4024
4582
  \begin{Highlighting}[]
4025
4583
  \FunctionTok{require} \VerbatimStringTok{\textquotesingle{}ggplot\textquotesingle{}}
4026
4584
 
4027
- \FunctionTok{puts}\NormalTok{ mtcars}\AttributeTok{.ggplot}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{x:} \WarningTok{:car\_name}\NormalTok{, }\WarningTok{y:} \WarningTok{:mpg\_z}\NormalTok{, }\WarningTok{label:} \WarningTok{:mpg\_z}\NormalTok{)) }\OperatorTok{+}
4028
- \ConstantTok{R}\AttributeTok{.geom\_bar}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{fill:} \WarningTok{:mpg\_type}\NormalTok{), }\WarningTok{stat:} \VerbatimStringTok{\textquotesingle{}identity\textquotesingle{}}\NormalTok{, }\WarningTok{width:} \FloatTok{0.5}\NormalTok{) }\OperatorTok{+}
4029
- \ConstantTok{R}\AttributeTok{.scale\_fill\_manual}\NormalTok{(}\WarningTok{name:} \VerbatimStringTok{\textquotesingle{}Mileage\textquotesingle{}}\NormalTok{,}
4030
- \WarningTok{labels:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}Above Average\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}Below Average\textquotesingle{}}\NormalTok{),}
4031
- \WarningTok{values:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}above\textquotesingle{}}\WarningTok{:} \VerbatimStringTok{\textquotesingle{}\#00ba38\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}below\textquotesingle{}}\WarningTok{:} \VerbatimStringTok{\textquotesingle{}\#f8766d\textquotesingle{}}\NormalTok{)) }\OperatorTok{+}
4585
+ \FunctionTok{puts}\NormalTok{ mtcars}\AttributeTok{.ggplot}\NormalTok{(}
4586
+ \ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{x:} \WarningTok{:car\_name}\NormalTok{, }\WarningTok{y:} \WarningTok{:mpg\_z}\NormalTok{, }\WarningTok{label:} \WarningTok{:mpg\_z}\NormalTok{)) }\OperatorTok{+}
4587
+ \ConstantTok{R}\AttributeTok{.geom\_bar}\NormalTok{(}\ConstantTok{E}\AttributeTok{.aes}\NormalTok{(}\WarningTok{fill:} \WarningTok{:mpg\_type}\NormalTok{),}
4588
+ \WarningTok{stat:} \VerbatimStringTok{\textquotesingle{}identity\textquotesingle{}}\NormalTok{, }\WarningTok{width:} \FloatTok{0.5}\NormalTok{) }\OperatorTok{+}
4589
+ \ConstantTok{R}\AttributeTok{.scale\_fill\_manual}\NormalTok{(}
4590
+ \WarningTok{name:} \VerbatimStringTok{\textquotesingle{}Mileage\textquotesingle{}}\NormalTok{,}
4591
+ \WarningTok{labels:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}Above Average\textquotesingle{}}\NormalTok{, }\VerbatimStringTok{\textquotesingle{}Below Average\textquotesingle{}}\NormalTok{),}
4592
+ \WarningTok{values:} \ConstantTok{R}\AttributeTok{.c}\NormalTok{(}\VerbatimStringTok{\textquotesingle{}above\textquotesingle{}}\WarningTok{:} \VerbatimStringTok{\textquotesingle{}\#00ba38\textquotesingle{}}\NormalTok{,}
4593
+ \VerbatimStringTok{\textquotesingle{}below\textquotesingle{}}\WarningTok{:} \VerbatimStringTok{\textquotesingle{}\#f8766d\textquotesingle{}}\NormalTok{)) }\OperatorTok{+}
4032
4594
  \ConstantTok{R}\AttributeTok{.labs}\NormalTok{(}\WarningTok{subtitle:} \StringTok{"Normalised mileage from \textquotesingle{}mtcars\textquotesingle{}"}\NormalTok{,}
4033
- \WarningTok{title:} \StringTok{"Diverging Bars"}\NormalTok{) }\OperatorTok{+}
4595
+ \WarningTok{title:} \StringTok{"Diverging Bars"}\NormalTok{) }\OperatorTok{+}
4034
4596
  \ConstantTok{R}\AttributeTok{.coord\_flip}
4035
4597
  \end{Highlighting}
4036
4598
  \end{Shaded}
4037
4599
 
4038
- \pandocbounded{\includegraphics[keepaspectratio]{manual_files/figure-latex/diverging_bar.pdf}}
4600
+ \pandocbounded{\includegraphics[keepaspectratio]{manual_files/manual_files/figure-latex/diverging_bar.pdf}}
4039
4601
 
4040
4602
  \section{Coding with Tidyverse}\label{coding-with-tidyverse}
4041
4603
 
@@ -4070,15 +4632,15 @@ and now, let's look at this code:
4070
4632
  It generates the following error: ``object `x' not found.
4071
4633
 
4072
4634
  However, in Galaaz, arguments are referentially transparent as can be
4073
- seen by the code below. Note initially that `my\_var = :x' will not give
4074
- the error ``object `x' not found'' since `:x' is treated as an
4635
+ seen by the code below. Note initially that `my\_var = R{[}:x{]}' will
4636
+ not give the error ``object `x' not found'' since `:x' is treated as an
4075
4637
  expression and assigned to my\_var. Then when doing (my\_var.eq 1),
4076
4638
  my\_var is a variable that resolves to `:x' and it becomes equivalent to
4077
- (:x.eq 1) which is what we want.
4639
+ (R{[}:x{]}.eq 1) which is what we want.
4078
4640
 
4079
4641
  \begin{Shaded}
4080
4642
  \begin{Highlighting}[]
4081
- \NormalTok{my\_var }\OperatorTok{=} \WarningTok{:x}
4643
+ \NormalTok{my\_var }\OperatorTok{=} \ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]}
4082
4644
  \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(my\_var}\AttributeTok{.eq} \DecValTok{1}\NormalTok{)}
4083
4645
  \end{Highlighting}
4084
4646
  \end{Shaded}
@@ -4104,11 +4666,11 @@ df[x == y, ]
4104
4666
 
4105
4667
  In galaaz this ambiguity does not exist, filter(df, x.eq y) is not a
4106
4668
  valid expression as expressions are build with symbols. In doing
4107
- filter(df, :x.eq y) we are looking for elements of the `x' column that
4108
- are equal to a previously defined y variable. Finally in filter(df,
4109
- :x.eq :y) we are looking for elements in which the `x' column value is
4110
- equal to the `y' column value. This can be seen in the following two
4111
- chunks of code:
4669
+ filter(df, R{[}:x{]}.eq y) we are looking for elements of the `x' column
4670
+ that are equal to a previously defined y variable. Finally in filter(df,
4671
+ R{[}:x{]}.eq R{[}:y{]}) we are looking for elements in which the `x'
4672
+ column value is equal to the `y' column value. This can be seen in the
4673
+ following two chunks of code:
4112
4674
 
4113
4675
  \begin{Shaded}
4114
4676
  \begin{Highlighting}[]
@@ -4116,7 +4678,7 @@ chunks of code:
4116
4678
  \NormalTok{x }\OperatorTok{=} \DecValTok{2}
4117
4679
 
4118
4680
  \CommentTok{\# looking for values where the \textquotesingle{}x\textquotesingle{} column is equal to the \textquotesingle{}y\textquotesingle{} column}
4119
- \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\WarningTok{:x}\AttributeTok{.eq} \OperatorTok{:}\NormalTok{y)}
4681
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]}\AttributeTok{.eq} \ConstantTok{R}\KeywordTok{[}\WarningTok{:y}\KeywordTok{]}\NormalTok{)}
4120
4682
  \end{Highlighting}
4121
4683
  \end{Shaded}
4122
4684
 
@@ -4129,7 +4691,7 @@ chunks of code:
4129
4691
  \begin{Highlighting}[]
4130
4692
  \CommentTok{\# looking for values where the \textquotesingle{}x\textquotesingle{} column is equal to the \textquotesingle{}y\textquotesingle{} variable}
4131
4693
  \CommentTok{\# in this case, the number 1}
4132
- \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\WarningTok{:x}\AttributeTok{.eq}\NormalTok{ y)}
4694
+ \FunctionTok{puts}\NormalTok{ df}\AttributeTok{.filter}\NormalTok{(}\ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]}\AttributeTok{.eq}\NormalTok{ y)}
4133
4695
  \end{Highlighting}
4134
4696
  \end{Shaded}
4135
4697
 
@@ -4173,7 +4735,9 @@ silently.
4173
4735
  \begin{Shaded}
4174
4736
  \begin{Highlighting}[]
4175
4737
  \ControlFlowTok{def}\NormalTok{ mutate\_y(df)}
4176
- \NormalTok{ df}\AttributeTok{.mutate}\NormalTok{(}\WarningTok{:y}\AttributeTok{.assign} \OperatorTok{:}\NormalTok{a }\OperatorTok{+} \WarningTok{:x}\NormalTok{)}
4738
+ \CommentTok{\# Column names are Ruby kwargs (y: …).}
4739
+ \CommentTok{\# Use .assign only for R \textasciigrave{}\textless{}{-}\textasciigrave{} expressions.}
4740
+ \NormalTok{ df}\AttributeTok{.mutate}\NormalTok{(}\WarningTok{y:} \ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{+} \ConstantTok{R}\KeywordTok{[}\WarningTok{:x}\KeywordTok{]}\NormalTok{)}
4177
4741
  \ControlFlowTok{end}
4178
4742
  \end{Highlighting}
4179
4743
  \end{Shaded}
@@ -4196,8 +4760,8 @@ Here we create a data frame that has only one column named `x':
4196
4760
 
4197
4761
  Note that method mutate\_y will fail independently from the fact that
4198
4762
  variable `a' is defined and in the scope of the method. Variable `a' has
4199
- no relationship with the symbol `:a' used in the definition of
4200
- `mutate\_y' above:
4763
+ no relationship with the symbol \texttt{R{[}:a{]}} used in the
4764
+ definition of `mutate\_y' above:
4201
4765
 
4202
4766
  \begin{Shaded}
4203
4767
  \begin{Highlighting}[]
@@ -4207,8 +4771,9 @@ no relationship with the symbol `:a' used in the definition of
4207
4771
  \end{Shaded}
4208
4772
 
4209
4773
  \begin{verbatim}
4210
- ## Error in strsplit(path, "/") : non-character argument
4211
- ## Calls: mutate ... .rlang_purrr_map_mold -> vapply -> FUN -> path_trim_prefix -> strsplit
4774
+ ## Error: i In argument: `y = a + x`.
4775
+ ## Caused by error:
4776
+ ## ! object 'a' not found
4212
4777
  \end{verbatim}
4213
4778
 
4214
4779
  \subsection{Different expressions}\label{different-expressions}
@@ -4304,7 +4869,7 @@ e.g.~\texttt{:df}).
4304
4869
 
4305
4870
  \begin{Shaded}
4306
4871
  \begin{Highlighting}[]
4307
- \FunctionTok{puts} \OperatorTok{\textasciitilde{}}\WarningTok{:df}
4872
+ \FunctionTok{puts} \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:df}\KeywordTok{]}
4308
4873
  \end{Highlighting}
4309
4874
  \end{Shaded}
4310
4875
 
@@ -4318,16 +4883,16 @@ e.g.~\texttt{:df}).
4318
4883
  \end{verbatim}
4319
4884
 
4320
4885
  We then create the `my\_summarize' method and call it passing the R data
4321
- frame and the group by variable `:g1':
4886
+ frame and the group by variable `R{[}:g1{]}':
4322
4887
 
4323
4888
  \begin{Shaded}
4324
4889
  \begin{Highlighting}[]
4325
4890
  \ControlFlowTok{def}\NormalTok{ my\_summarize(df, group\_var)}
4326
4891
  \NormalTok{ df}\AttributeTok{.group\_by}\NormalTok{(group\_var)}\AttributeTok{.}
4327
- \AttributeTok{summarize}\NormalTok{(}\WarningTok{a:} \WarningTok{:a}\AttributeTok{.mean}\NormalTok{)}
4892
+ \AttributeTok{summarize}\NormalTok{(}\WarningTok{a:} \ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]}\AttributeTok{.mean}\NormalTok{)}
4328
4893
  \ControlFlowTok{end}
4329
4894
 
4330
- \FunctionTok{puts}\NormalTok{ my\_summarize(}\WarningTok{:df}\NormalTok{, }\WarningTok{:g1}\NormalTok{)}
4895
+ \FunctionTok{puts}\NormalTok{ my\_summarize(}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:df}\KeywordTok{]}\NormalTok{, }\ConstantTok{R}\KeywordTok{[}\WarningTok{:g1}\KeywordTok{]}\NormalTok{)}
4331
4896
  \end{Highlighting}
4332
4897
  \end{Shaded}
4333
4898
 
@@ -4343,7 +4908,7 @@ It works!!! Well, let's make sure this was not just some coincidence
4343
4908
 
4344
4909
  \begin{Shaded}
4345
4910
  \begin{Highlighting}[]
4346
- \FunctionTok{puts}\NormalTok{ my\_summarize(}\WarningTok{:df}\NormalTok{, }\WarningTok{:g2}\NormalTok{)}
4911
+ \FunctionTok{puts}\NormalTok{ my\_summarize(}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:df}\KeywordTok{]}\NormalTok{, }\ConstantTok{R}\KeywordTok{[}\WarningTok{:g2}\KeywordTok{]}\NormalTok{)}
4347
4912
  \end{Highlighting}
4348
4913
  \end{Shaded}
4349
4914
 
@@ -4396,10 +4961,10 @@ Let's try it in galaaz:
4396
4961
  \NormalTok{ )}
4397
4962
  \ControlFlowTok{end}
4398
4963
 
4399
- \FunctionTok{puts}\NormalTok{ my\_summarise2((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:a}\NormalTok{)}
4964
+ \FunctionTok{puts}\NormalTok{ my\_summarise2((}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:df}\KeywordTok{]}\NormalTok{), }\WarningTok{:a}\NormalTok{)}
4400
4965
  \FunctionTok{puts} \StringTok{"}
4401
4966
  \StringTok{"}
4402
- \FunctionTok{puts}\NormalTok{ my\_summarise2((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:a} \OperatorTok{*} \WarningTok{:b}\NormalTok{)}
4967
+ \FunctionTok{puts}\NormalTok{ my\_summarise2((}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:df}\KeywordTok{]}\NormalTok{), }\ConstantTok{R}\KeywordTok{[}\WarningTok{:a}\KeywordTok{]} \OperatorTok{*} \ConstantTok{R}\KeywordTok{[}\WarningTok{:b}\KeywordTok{]}\NormalTok{)}
4403
4968
  \end{Highlighting}
4404
4969
  \end{Shaded}
4405
4970
 
@@ -4462,10 +5027,10 @@ Here is our Ruby code:
4462
5027
  \NormalTok{ sum\_name }\OperatorTok{=\textgreater{}} \ConstantTok{E}\AttributeTok{.sum}\NormalTok{(expr))}
4463
5028
  \ControlFlowTok{end}
4464
5029
 
4465
- \FunctionTok{puts}\NormalTok{ my\_mutate((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:a}\NormalTok{)}
5030
+ \FunctionTok{puts}\NormalTok{ my\_mutate((}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:df}\KeywordTok{]}\NormalTok{), }\WarningTok{:a}\NormalTok{)}
4466
5031
  \FunctionTok{puts} \StringTok{"}
4467
5032
  \StringTok{"}
4468
- \FunctionTok{puts}\NormalTok{ my\_mutate((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:b}\NormalTok{)}
5033
+ \FunctionTok{puts}\NormalTok{ my\_mutate((}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:df}\KeywordTok{]}\NormalTok{), }\WarningTok{:b}\NormalTok{)}
4469
5034
  \end{Highlighting}
4470
5035
  \end{Shaded}
4471
5036
 
@@ -4513,7 +5078,7 @@ number of paramenters the paramenter is preceded by '*':
4513
5078
  \AttributeTok{summarise}\NormalTok{(}\WarningTok{a:} \ConstantTok{E}\AttributeTok{.mean}\NormalTok{(}\WarningTok{:a}\NormalTok{))}
4514
5079
  \ControlFlowTok{end}
4515
5080
 
4516
- \FunctionTok{puts}\NormalTok{ my\_summarise3((}\OperatorTok{\textasciitilde{}}\WarningTok{:df}\NormalTok{), }\WarningTok{:g1}\NormalTok{, }\WarningTok{:g2}\NormalTok{)}
5081
+ \FunctionTok{puts}\NormalTok{ my\_summarise3((}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:df}\KeywordTok{]}\NormalTok{), }\ConstantTok{R}\KeywordTok{[}\WarningTok{:g1}\KeywordTok{]}\NormalTok{, }\ConstantTok{R}\KeywordTok{[}\WarningTok{:g2}\KeywordTok{]}\NormalTok{)}
4517
5082
  \end{Highlighting}
4518
5083
  \end{Shaded}
4519
5084
 
@@ -4548,10 +5113,10 @@ used, so `x = a' is immediately evaluate and variable `x' will receive
4548
5113
  the value of variable `a' as soon as the Ruby statement is executed.
4549
5114
  Ruby also provides the notion of a symbol; `:a' is a symbol and does not
4550
5115
  evaluate to anything. Galaaz uses Ruby symbols to build expressions that
4551
- are not bound to anything: `:a.eq :b' is clearly an expression and has
4552
- no relationship whatsoever with the statment `a = b'. By using symbols,
4553
- variables and expressions all the possible ambiguities that are found in
4554
- R are eliminated in Galaaz.
5116
+ are not bound to anything: `R{[}:a{]}.eq R{[}:b{]}' is clearly an
5117
+ expression and has no relationship whatsoever with the statment `a = b'.
5118
+ By using symbols, variables and expressions all the possible ambiguities
5119
+ that are found in R are eliminated in Galaaz.
4555
5120
 
4556
5121
  The main problem that remains, is that in R, functions are not clearly
4557
5122
  documented as what type of input they are expecting, they might be
@@ -4560,7 +5125,7 @@ the R function will know how to deal with an input of the form `a = b',
4560
5125
  now for the Ruby developer it might not be immediately clear if it
4561
5126
  should call the function passing the value `true' if variable `a' is
4562
5127
  equal to variable `b' or if it should call the function passing the
4563
- expression `:a.eq :b'.
5128
+ expression `R{[}:a{]}.eq R{[}:b{]}'.
4564
5129
 
4565
5130
  \subsection{Advanced dplyr features}\label{advanced-dplyr-features}
4566
5131
 
@@ -4589,22 +5154,22 @@ the Starwars movies:
4589
5154
 
4590
5155
  \begin{Shaded}
4591
5156
  \begin{Highlighting}[]
4592
- \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\WarningTok{:starwars}\NormalTok{)}\AttributeTok{.head}
5157
+ \FunctionTok{puts}\NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:starwars}\KeywordTok{]}\NormalTok{)}\AttributeTok{.head}
4593
5158
  \end{Highlighting}
4594
5159
  \end{Shaded}
4595
5160
 
4596
5161
  \begin{verbatim}
4597
5162
  ## # A tibble: 6 x 14
4598
- ## name height mass hair_color skin_color eye_color birth_year sex gender
4599
- ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr>
4600
- ## 1 Luke Sky~ 172 77 blond fair blue 19 male mascu~
4601
- ## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu~
4602
- ## 3 R2-D2 96 32 <NA> white, bl~ red 33 none mascu~
4603
- ## 4 Darth Va~ 202 136 none white yellow 41.9 male mascu~
4604
- ## 5 Leia Org~ 150 49 brown light brown 19 fema~ femin~
4605
- ## 6 Owen Lars 178 120 brown, gr~ light blue 52 male mascu~
4606
- ## # i 5 more variables: homeworld <chr>, species <chr>, films <list>,
4607
- ## # vehicles <list>, starships <list>
5163
+ ## name height mass hair_color skin_color eye_color birth_year sex
5164
+ ## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr>
5165
+ ## 1 Luke ~ 172 77 blond fair blue 19 male
5166
+ ## 2 C-3PO 167 75 <NA> gold yellow 112 none
5167
+ ## 3 R2-D2 96 32 <NA> white, bl~ red 33 none
5168
+ ## 4 Darth~ 202 136 none white yellow 41.9 male
5169
+ ## 5 Leia ~ 150 49 brown light brown 19 fema~
5170
+ ## 6 Owen ~ 178 120 brown, gr~ light blue 52 male
5171
+ ## # i 6 more variables: gender <chr>, homeworld <chr>, species <chr>,
5172
+ ## # films <list>, vehicles <list>, starships <list>
4608
5173
  \end{verbatim}
4609
5174
 
4610
5175
  The grouped\_mean function below will receive a grouping variable and
@@ -4635,8 +5200,8 @@ calculate summaries for the value\_variables given:
4635
5200
  ## # Auto named with `tibble::lst()`: tibble::lst(mean, median)
4636
5201
  ##
4637
5202
  ## # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
4638
- ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
4639
- ## generated.
5203
+ ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning
5204
+ ## was generated.
4640
5205
  \end{verbatim}
4641
5206
 
4642
5207
  \begin{Shaded}
@@ -4672,11 +5237,19 @@ The same code with Galaaz, becomes:
4672
5237
  \NormalTok{ data}\AttributeTok{.}
4673
5238
  \AttributeTok{group\_by\_at}\NormalTok{(grouping\_variables)}\AttributeTok{.}
4674
5239
  \AttributeTok{mutate}\NormalTok{(}\WarningTok{count:} \ConstantTok{E}\AttributeTok{.n}\NormalTok{)}\AttributeTok{.}
4675
- \AttributeTok{summarise\_at}\NormalTok{(}\ConstantTok{E}\AttributeTok{.c}\NormalTok{(value\_variables, }\StringTok{"count"}\NormalTok{), }\OperatorTok{\textasciitilde{}}\WarningTok{:mean}\NormalTok{, }\WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{)}\AttributeTok{.}
4676
- \AttributeTok{rename\_at}\NormalTok{(value\_variables, }\ConstantTok{E}\AttributeTok{.funs}\NormalTok{(}\ConstantTok{E}\AttributeTok{.paste0}\NormalTok{(}\StringTok{"mean\_"}\NormalTok{, value\_variables)))}
5240
+ \AttributeTok{summarise\_at}\NormalTok{(}
5241
+ \ConstantTok{E}\AttributeTok{.c}\NormalTok{(value\_variables, }\StringTok{"count"}\NormalTok{),}
5242
+ \OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:mean}\KeywordTok{]}\NormalTok{,}
5243
+ \WarningTok{na\_\_rm:} \DecValTok{true}\NormalTok{)}\AttributeTok{.}
5244
+ \AttributeTok{rename\_at}\NormalTok{(}
5245
+ \NormalTok{ value\_variables,}
5246
+ \ConstantTok{E}\AttributeTok{.funs}\NormalTok{(}\ConstantTok{E}\AttributeTok{.paste0}\NormalTok{(}\StringTok{"mean\_"}\NormalTok{, value\_variables)))}
4677
5247
  \ControlFlowTok{end}
4678
5248
 
4679
- \FunctionTok{puts}\NormalTok{ grouped\_mean((}\OperatorTok{\textasciitilde{}}\WarningTok{:starwars}\NormalTok{), }\StringTok{"eye\_color"}\NormalTok{, }\ConstantTok{E}\AttributeTok{.c}\NormalTok{(}\StringTok{"mass"}\NormalTok{, }\StringTok{"birth\_year"}\NormalTok{))}
5249
+ \FunctionTok{puts}\NormalTok{ grouped\_mean(}
5250
+ \NormalTok{ (}\OperatorTok{\textasciitilde{}}\ConstantTok{R}\KeywordTok{[}\WarningTok{:starwars}\KeywordTok{]}\NormalTok{),}
5251
+ \StringTok{"eye\_color"}\NormalTok{,}
5252
+ \ConstantTok{E}\AttributeTok{.c}\NormalTok{(}\StringTok{"mass"}\NormalTok{, }\StringTok{"birth\_year"}\NormalTok{))}
4680
5253
  \end{Highlighting}
4681
5254
  \end{Shaded}
4682
5255
 
@@ -4718,8 +5291,9 @@ function-specific arguments.
4718
5291
  (\texttt{git\ checkout\ -b\ my-new-feature})
4719
5292
  \item
4720
5293
  Write tests --- use \textbf{\texttt{bin/run\_rspec}} or
4721
- \textbf{\texttt{bin/run\_all\_rspec}} with \textbf{JRuby} so JVM flags
4722
- and the load path match \textbf{\texttt{docs/testing.md}}
5294
+ \textbf{\texttt{bin/run\_all\_rspec}} (JRuby or CRuby via
5295
+ \textbf{\texttt{GALAAZ\_RUBY}}) so the load path matches
5296
+ \textbf{\texttt{docs/testing.md}}
4723
5297
  \item
4724
5298
  Commit your changes
4725
5299
  (\texttt{git\ commit\ -am\ \textquotesingle{}Add\ some\ feature\textquotesingle{}})