galaaz 2.1.7 → 2.1.9

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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/Rakefile +20 -2
  4. data/bin/check_gemfile_lock_version +46 -0
  5. data/bin/release_bump +26 -0
  6. data/blogs/README.md +4 -0
  7. data/blogs/galaaz_2_0/galaaz_2_0.Rmd +385 -0
  8. data/blogs/galaaz_2_0/galaaz_2_0.md +409 -0
  9. data/blogs/galaaz_2_0/galaaz_2_0.tex +756 -0
  10. data/blogs/galaaz_2_0/images/galaaz-header.png +0 -0
  11. data/blogs/galaaz_2_0/images/galaaz-lockup-stacked.png +0 -0
  12. data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +76 -58
  13. data/blogs/galaaz_ggplot/galaaz_ggplot.md +188 -161
  14. data/blogs/galaaz_ggplot/galaaz_ggplot.tex +185 -117
  15. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
  16. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
  17. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
  18. data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
  19. data/blogs/galaaz_ggplot/images/galaaz-lockup-stacked.png +0 -0
  20. data/blogs/gknit/gknit.Rmd +48 -28
  21. data/blogs/gknit/gknit.md +60 -43
  22. data/blogs/gknit/gknit.tex +1409 -0
  23. data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
  24. data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
  25. data/blogs/gknit/gknit_files/figure-latex/bubble-1.png +0 -0
  26. data/blogs/gknit/images/galaaz-lockup-stacked.png +0 -0
  27. data/blogs/manual/images/galaaz-lockup-stacked.png +0 -0
  28. data/blogs/manual/manual.Rmd +161 -71
  29. data/blogs/manual/manual.md +573 -482
  30. data/blogs/manual/manual.tex +1113 -517
  31. data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
  32. data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
  33. data/blogs/manual/manual_files/figure-markdown_github/bubble-1.png +0 -0
  34. data/blogs/manual/manual_files/figure-markdown_github/diverging_bar.png +0 -0
  35. data/blogs/nse_dplyr/images/galaaz-lockup-stacked.png +0 -0
  36. data/blogs/nse_dplyr/nse_dplyr.Rmd +42 -8
  37. data/blogs/nse_dplyr/nse_dplyr.md +69 -50
  38. data/blogs/nse_dplyr/nse_dplyr.tex +1626 -0
  39. data/blogs/oh_my/images/galaaz-lockup-stacked.png +0 -0
  40. data/blogs/oh_my/oh_my.Rmd +206 -55
  41. data/blogs/oh_my/oh_my.md +247 -96
  42. data/blogs/oh_my/oh_my.tex +2038 -93
  43. data/blogs/r_on_rails_ledger/images/00_portfolio_page.png +0 -0
  44. data/blogs/r_on_rails_ledger/images/01_results_panel.png +0 -0
  45. data/blogs/r_on_rails_ledger/images/02_density_tail_risk.png +0 -0
  46. data/blogs/r_on_rails_ledger/images/03_mc_cone.png +0 -0
  47. data/blogs/r_on_rails_ledger/images/04_rolling_var.png +0 -0
  48. data/blogs/r_on_rails_ledger/images/galaaz-lockup-stacked.png +0 -0
  49. data/blogs/r_on_rails_ledger/r_on_rails_ledger.Rmd +354 -0
  50. data/blogs/r_on_rails_ledger/r_on_rails_ledger.md +365 -0
  51. data/blogs/r_on_rails_ledger/r_on_rails_ledger.tex +670 -0
  52. data/blogs/ruby_plot/images/galaaz-lockup-stacked.png +0 -0
  53. data/blogs/ruby_plot/ruby_plot.Rmd +56 -35
  54. data/blogs/ruby_plot/ruby_plot.md +63 -47
  55. data/blogs/ruby_plot/ruby_plot.tex +194 -125
  56. data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
  57. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
  58. data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
  59. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
  60. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
  61. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
  62. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
  63. data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
  64. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
  65. data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
  66. data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
  67. data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
  68. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  69. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  70. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  71. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  72. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  73. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  74. data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  75. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  76. data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  77. data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  78. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/dose_len.png +0 -0
  79. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
  80. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
  81. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
  82. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
  83. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
  84. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
  85. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
  86. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
  87. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
  88. data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
  89. data/lib/galaaz/cli.rb +98 -13
  90. data/logos/icon-font/README.md +27 -0
  91. data/logos/icon-font/build_font.py +130 -0
  92. data/logos/icon-font/galaaz-mark.svg +34 -0
  93. data/script/omarchy/README.md +9 -2
  94. data/script/omarchy/fonts/galaaz.ttf +0 -0
  95. data/script/omarchy/galaaz-guide.sh +1 -1
  96. data/script/omarchy/install-galaaz.sh +8 -1
  97. data/script/omarchy/omarchy-menu.jsonc +21 -9
  98. data/sty/galaaz-header.png +0 -0
  99. data/sty/galaaz-headers-from-p3.tex +4 -0
  100. data/sty/galaaz.sty +76 -23
  101. data/version.rb +1 -1
  102. metadata +46 -7
  103. data/blogs/galaaz_ggplot/galaaz_ggplot.log +0 -754
  104. data/blogs/manual/manual.log +0 -1786
  105. data/blogs/nse_dplyr/nse_dplyr.log +0 -928
  106. data/blogs/oh_my/oh_my.log +0 -804
  107. data/blogs/ruby_plot/ruby_plot.log +0 -885
@@ -9,9 +9,17 @@ output:
9
9
  html_document:
10
10
  self_contained: true
11
11
  keep_md: true
12
+ toc: true
13
+ toc_float: true
14
+ toc_depth: 2
15
+ number_sections: true
16
+ includes:
17
+ before_body: _logo_before_body.html
12
18
  pdf_document:
13
19
  includes:
14
- in_header: "../../sty/galaaz.sty"
20
+ in_header:
21
+ - "../../sty/galaaz.sty"
22
+ - "../../sty/galaaz-headers-from-p3.tex"
15
23
  keep_tex: yes
16
24
  number_sections: yes
17
25
  toc: true
@@ -20,7 +28,12 @@ fontsize: 11pt
20
28
  ---
21
29
 
22
30
  ```{r setup, echo=FALSE}
31
+ options(width = 70)
32
+ ```
23
33
 
34
+ ```{r brand_logo, echo=FALSE, fig.align='center', out.width='45%', eval=knitr::is_latex_output()}
35
+ # PDF only — HTML uses _logo_before_body.html (above the TOC).
36
+ knitr::include_graphics("images/galaaz-lockup-stacked.png")
24
37
  ```
25
38
 
26
39
  # Introduction
@@ -78,6 +91,21 @@ the details of instance variables in Ruby, but here we created those variables w
78
91
  keyword 'attr_reader' and a colom before the variables name:
79
92
 
80
93
 
94
+ ```{ruby class_cleanup, echo=FALSE}
95
+ # Drop classes left from a prior output format in one gknit process.
96
+ # Chunks run via KnitrEngine#instance_eval, so classes live under RC.
97
+ mods = [Object]
98
+ mods << RC if defined?(RC)
99
+ %w[
100
+ Trajectories TrajectoriesBis TrajPartitioned
101
+ Partition PartitionFather PartitionSimple PartitionEval
102
+ ].each do |name|
103
+ mods.each do |mod|
104
+ mod.send(:remove_const, name) if mod.const_defined?(name, false)
105
+ end
106
+ end
107
+ ```
108
+
81
109
  ```{ruby class_trajectories}
82
110
  class Trajectories
83
111
  attr_reader :times
@@ -153,7 +181,8 @@ one uses the ':' operator after parameter's name as we can see below:
153
181
  @traj = Trajectories.new(times: R.c(1, 2, 3, 4))
154
182
 
155
183
  # Create a Trajectories with times and matrix
156
- @traj2 = Trajectories.new(times: R.c(1, 3), matrix: R.matrix((1..4), ncol: 2))
184
+ @traj2 = Trajectories.new(times: R.c(1, 3), matrix: R.matrix((1..4),
185
+ ncol: 2))
157
186
  ```
158
187
 
159
188
  # Access to Instance Variables (to reach a slot)
@@ -200,7 +229,8 @@ Cochin and Saint-Anne. We first show the code in R and the corresponding Galaaz
200
229
  + times=c(1: 10, (6: 16) *2),
201
230
  + traj=rbind(
202
231
  + matrix (seq (16,19, length=21), ncol=21, nrow=50, byrow=TRUE),
203
- + matrix (seq (15.8, 18, length=21), ncol=21, nrow=30, byrow=TRUE)
232
+ + matrix (seq (15.8, 18, length=21), ncol=21, nrow=30,
233
+ byrow=TRUE)
204
234
  + )+rnorm (21*80,0,0.2)
205
235
  + )
206
236
  ```
@@ -218,12 +248,16 @@ This same code in Galaaz becomes:
218
248
  R.c(15.7, 15.6, 15.8, 16)))
219
249
 
220
250
  @trajStAnne =
221
- Trajectories.new(times: R.c((1..10), R.c(6..16) * 2),
222
- matrix: (R.rbind(
223
- R.matrix(R.seq(16, 19, length: 21), ncol: 21,
224
- nrow: 50, byrow: true),
225
- R.matrix(R.seq(15.8, 18, length: 21), ncol: 21,
226
- nrow: 30, byrow: true)) + R.rnorm(21*80, 0, 0.2)))
251
+ Trajectories.new(
252
+ times: R.c((1..10), R.c(6..16) * 2),
253
+ matrix: (
254
+ R.rbind(
255
+ R.matrix(R.seq(16, 19, length: 21),
256
+ ncol: 21, nrow: 50, byrow: true),
257
+ R.matrix(R.seq(15.8, 18, length: 21),
258
+ ncol: 21, nrow: 30, byrow: true)
259
+ ) + R.rnorm(21 * 80, 0, 0.2)
260
+ ))
227
261
 
228
262
  ```
229
263
 
@@ -470,7 +504,8 @@ class Trajectories
470
504
  nrow_show = [10, @matrix.nrow >> 0].min
471
505
  ncol_show = R.min(10, @matrix.ncol) >> 0
472
506
  puts("* Traj (limited to a matrix 10x10) = ")
473
- puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2, nsmall: 2)
507
+ puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2,
508
+ nsmall: 2)
474
509
  puts("******* End Show (trajectories) ******* ")
475
510
  end
476
511
 
@@ -489,7 +524,14 @@ we try to 'show' it, it will generate an error. Let's see it:
489
524
  ```
490
525
 
491
526
  ```{ruby eval_error_1, warning = FALSE}
492
- @empty_traj.show
527
+ begin
528
+ @empty_traj.show
529
+ rescue => e
530
+ # Short message only — full backtraces overflow PDF boxes.
531
+ puts e.class.to_s
532
+ # Wrap long messages for PDF code-box width.
533
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
534
+ end
493
535
  ```
494
536
 
495
537
  In this example, `@matrix` is `nil`, so calling `@matrix.nrow` raises
@@ -516,7 +558,8 @@ class Trajectories
516
558
  nrow_show = [10, @matrix.nrow >> 0].min
517
559
  ncol_show = R.min(10, @matrix.ncol) >> 0
518
560
  puts("* Traj (limited to a matrix 10x10) = ")
519
- puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2, nsmall: 2)
561
+ puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2,
562
+ nsmall: 2)
520
563
  puts("******* End Show (trajectories) ******* ")
521
564
  end
522
565
 
@@ -621,7 +664,8 @@ Here we show the R code for this validation:
621
664
  + validity=function(object){
622
665
  + cat("~~~ Trajectories: inspector ~~~ \\n")
623
666
  + if(length(object@times)!=ncol(object@traj)){
624
- + stop ("[Trajectories: validation] the number of temporal measurements does not correspond
667
+ + stop ("[Trajectories: validation] the number of temporal
668
+ + measurements does not correspond
625
669
  + }else{}
626
670
  + return(TRUE)
627
671
  + }
@@ -637,10 +681,14 @@ class Trajectories
637
681
  @times = times
638
682
  @matrix = matrix
639
683
 
640
- # validate the input, to make sure that size of @times and the number of columns in
641
- # @matrix are the same
684
+ # Validate: length(@times) must equal ncol(@matrix)
642
685
  puts ("~~~ Trajectories: inspector ~~~ ")
643
- raise "[Trajectories: validation] the number of temporal measurements does not correspond with the number of columns in the matrix" if ((@times.length >> 0) != (@matrix.ncol >> 0))
686
+ if ((@times.length >> 0) != (@matrix.ncol >> 0))
687
+ raise(
688
+ "[Trajectories: validation] the number of temporal " +
689
+ "measurements does not correspond with the number of " +
690
+ "columns in the matrix")
691
+ end
644
692
 
645
693
  # show the object just created
646
694
  show
@@ -655,7 +703,8 @@ equal to the number of columns of the matrix. In this case, we will show a mess
655
703
  validation was done and then print the object.
656
704
 
657
705
  ```{ruby}
658
- ok = Trajectories.new(times: R.c(1..2), matrix: R.matrix((1..2), ncol: 2))
706
+ ok = Trajectories.new(times: R.c(1..2), matrix: R.matrix((1..2),
707
+ ncol: 2))
659
708
  ```
660
709
 
661
710
  Now, if we try to create a Trajectories that does not pass the validation criteria, our code
@@ -665,7 +714,15 @@ on exceptions on the web.
665
714
 
666
715
 
667
716
  ```{ruby eval_error_2, warning = FALSE}
668
- error = Trajectories.new(times: R.c(1..3), matrix: R.matrix((1..2), ncol: 2))
717
+ begin
718
+ error = Trajectories.new(times: R.c(1..3), matrix: R.matrix((1..2),
719
+ ncol: 2))
720
+ rescue => e
721
+ # Short message only — full backtraces overflow PDF boxes.
722
+ puts e.class.to_s
723
+ # Wrap long messages for PDF code-box width.
724
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
725
+ end
669
726
  ```
670
727
 
671
728
  The validation above does not consider the case when an empty object is created. Here we will
@@ -696,12 +753,18 @@ class Trajectories
696
753
  def validate
697
754
 
698
755
  # Let's first check that we do not have an empty object
699
- raise "Neither times nor matrix can be an empty object" if (@times.nil? || @matrix.nil?)
756
+ if (@times.nil? || @matrix.nil?)
757
+ raise "Neither times nor matrix can be an empty object"
758
+ end
700
759
 
701
- # validate the input, to make sure that size of @times and the number of columns in
702
- # @matrix are the same
760
+ # Validate: length(@times) must equal ncol(@matrix)
703
761
  puts ("~~~ Trajectories: inspector ~~~ ")
704
- raise "[Trajectories: validation] the number of temporal measurements does not correspond with the number of columns in the matrix" if ((@times.length >> 0) != (@matrix.ncol >> 0))
762
+ if ((@times.length >> 0) != (@matrix.ncol >> 0))
763
+ raise(
764
+ "[Trajectories: validation] the number of temporal " +
765
+ "measurements does not correspond with the number of " +
766
+ "columns in the matrix")
767
+ end
705
768
 
706
769
  end
707
770
 
@@ -717,20 +780,35 @@ Let's try then creating an empty object:
717
780
 
718
781
 
719
782
  ```{ruby eval_error_3, warning = FALSE}
720
- error = Trajectories.new
783
+ begin
784
+ error = Trajectories.new
785
+ rescue => e
786
+ # Short message only — full backtraces overflow PDF boxes.
787
+ puts e.class.to_s
788
+ # Wrap long messages for PDF code-box width.
789
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
790
+ end
721
791
  ```
722
792
 
723
793
  Another example:
724
794
 
725
795
  ```{ruby eval_error_4, warning = FALSE}
726
- error = Trajectories.new(times: 1)
796
+ begin
797
+ error = Trajectories.new(times: 1)
798
+ rescue => e
799
+ # Short message only — full backtraces overflow PDF boxes.
800
+ puts e.class.to_s
801
+ # Wrap long messages for PDF code-box width.
802
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
803
+ end
727
804
  ```
728
805
 
729
806
  Let's see now that the implementation is correct and that it does not raise an error on valid
730
807
  input:
731
808
 
732
809
  ```{ruby}
733
- ok = Trajectories.new(times: R.c(1, 2), matrix: R.matrix((1..2), ncol: 2))
810
+ ok = Trajectories.new(times: R.c(1, 2), matrix: R.matrix((1..2),
811
+ ncol: 2))
734
812
  ```
735
813
 
736
814
  The 'initialize' method is called ONLY during the initial creation of the object. If any instance
@@ -772,13 +850,19 @@ class Trajectories
772
850
  def validate
773
851
 
774
852
  # Let's first check that we do not have an empty object
775
- raise "Neither times nor matrix can be an empty object" if (@times.nil? || @matrix.nil?)
853
+ if (@times.nil? || @matrix.nil?)
854
+ raise "Neither times nor matrix can be an empty object"
855
+ end
776
856
 
777
- # validate the input, to make sure that size of @times and the number of columns in
778
- # @matrix are the same
857
+ # Validate: length(@times) must equal ncol(@matrix)
779
858
  puts ("~~~ Trajectories: inspector ~~~ ")
780
859
  tl = @times.length >> 0; mc = @matrix.ncol >> 0
781
- raise "[Trajectories: validation] the number of temporal measurements #{tl} does not correspond with the number of columns in the matrix #{mc}" if (tl != mc)
860
+ if (tl != mc)
861
+ raise(
862
+ "[Trajectories: validation] the number of temporal " +
863
+ "measurements #{tl} does not correspond with the number " +
864
+ "of columns in the matrix #{mc}")
865
+ end
782
866
 
783
867
  end
784
868
 
@@ -858,14 +942,23 @@ end
858
942
  ```
859
943
 
860
944
  ```{ruby}
861
- @traj = Trajectories.new(times: R.c(1,2,4,8), matrix: R.matrix((1..8), nrow: 2))
945
+ @traj = Trajectories.new(times: R.c(1,2,4,8), matrix: R.matrix((1..8),
946
+ nrow: 2))
862
947
  ```
863
948
 
864
949
  Note that we still call our 'validate' method and it is still an error to create an empty
865
950
  Trajectories or one in which the sizes are wrong:
866
951
 
867
952
  ```{ruby eval_error_5, warning = FALSE}
868
- error = Trajectories.new(times: R.c(1, 2, 48), matrix: R.matrix((1..8), nrow: 2))
953
+ begin
954
+ error = Trajectories.new(times: R.c(1, 2, 48), matrix: R.matrix((1..8),
955
+ nrow: 2))
956
+ rescue => e
957
+ # Short message only — full backtraces overflow PDF boxes.
958
+ puts e.class.to_s
959
+ # Wrap long messages for PDF code-box width.
960
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
961
+ end
869
962
  ```
870
963
 
871
964
  A constructor does not necessarily take the instance variable of the object as argument. For
@@ -880,7 +973,8 @@ First the code in R, we skip the definition of class TrajectoriesBis:
880
973
  > setMethod ("initialize",
881
974
  + "TrajectoriesBis",
882
975
  + function(.Object,nbWeek,BMIinit){
883
- + traj <- outer(BMIinit,1:nbWeek,function(init,week){return(init+0.1*week)})
976
+ + traj <- outer(BMIinit, 1:nbWeek,
977
+ + function(init, week) { return(init + 0.1 * week) })
884
978
  + colnames(traj) <- paste("T",1:nbWeek,sep="")
885
979
  + rownames(traj) <- paste("I",1:nrow(traj),sep="")
886
980
  + .Object@times <- 1:nbWeek
@@ -912,7 +1006,8 @@ class TrajectoriesBis
912
1006
 
913
1007
  def initialize(number_weeks, bmi_init)
914
1008
  @matrix = bmi_init.outer((1..number_weeks),
915
- R.eval("function(init, week) {return(init + 0.1 * week)}"))
1009
+ R.eval("function(init,
1010
+ week) {return(init + 0.1 * week)}"))
916
1011
  @times = R.c((1..number_weeks))
917
1012
  end
918
1013
 
@@ -936,7 +1031,9 @@ class TrajectoriesBis
936
1031
 
937
1032
  def initialize(number_weeks, bmi_init, increment)
938
1033
  @matrix = bmi_init.outer((1..number_weeks),
939
- R.eval("function(init, week) {return(init + #{increment} * week)}"))
1034
+ R.eval("function(init,
1035
+ week) {return(init +
1036
+ #{increment} * week)}"))
940
1037
  @times = R.c((1..number_weeks))
941
1038
  end
942
1039
 
@@ -964,7 +1061,8 @@ week, let's define a regular trajectory without having to define a TrajectoriesB
964
1061
 
965
1062
  ```
966
1063
  > regularTrajectories <- function(nbWeek,BMIinit) {
967
- + traj <- outer(BMIinit,1:nbWeek,function(init,week){return(init+0.1*week)})
1064
+ + traj <- outer(BMIinit, 1:nbWeek,
1065
+ + function(init, week) { return(init + 0.1 * week) })
968
1066
  + times <- 1: nbWeek
969
1067
  + return(new(Class="Trajectories",times=times,traj=traj))
970
1068
  + }
@@ -983,7 +1081,8 @@ class Trajectories
983
1081
 
984
1082
  def self.regular(number_weeks: nil, bmi_init: nil)
985
1083
  matrix = bmi_init.outer((1..number_weeks),
986
- R.eval("function(init, week) {return(init + 0.1 * week)}"))
1084
+ R.eval("function(init,
1085
+ week) {return(init + 0.1 * week)}"))
987
1086
  times = R.c((1..number_weeks))
988
1087
  Trajectories.new(times: times, matrix: matrix)
989
1088
  end
@@ -992,7 +1091,8 @@ end
992
1091
  ```
993
1092
 
994
1093
  ```{ruby}
995
- @regular = Trajectories.regular(bmi_init: R.c(14, 15, 16), number_weeks: 3)
1094
+ @regular = Trajectories.regular(bmi_init: R.c(14, 15, 16),
1095
+ number_weeks: 3)
996
1096
  ```
997
1097
 
998
1098
  We have already seen that constructors can be as complex as needed, calling other methods and doing
@@ -1124,7 +1224,12 @@ class Trajectories
1124
1224
  def times=(times)
1125
1225
  times = as_r(times)
1126
1226
  tl = times.length >> 0; mc = @matrix.ncol >> 0
1127
- raise "[Trajectories: validation] the number of temporal measurements #{tl} does not correspond with the number of columns in the matrix #{mc}" if (tl != mc)
1227
+ if (tl != mc)
1228
+ raise(
1229
+ "[Trajectories: validation] the number of temporal " +
1230
+ "measurements #{tl} does not correspond with the number " +
1231
+ "of columns in the matrix #{mc}")
1232
+ end
1128
1233
  @times = times
1129
1234
  end
1130
1235
 
@@ -1132,7 +1237,14 @@ end
1132
1237
  ```
1133
1238
 
1134
1239
  ```{ruby eval_error_6, warning = FALSE}
1135
- @trajCochin.times = (1..5)
1240
+ begin
1241
+ @trajCochin.times = (1..5)
1242
+ rescue => e
1243
+ # Short message only — full backtraces overflow PDF boxes.
1244
+ puts e.class.to_s
1245
+ # Wrap long messages for PDF code-box width.
1246
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
1247
+ end
1136
1248
  ```
1137
1249
 
1138
1250
  We now set the value appropriately and will not get any errors:
@@ -1286,7 +1398,14 @@ both times and matrix to be non null.
1286
1398
 
1287
1399
 
1288
1400
  ```{ruby eval_error_7, warning = FALSE}
1289
- @tdPitie = TrajPartitioned.new
1401
+ begin
1402
+ @tdPitie = TrajPartitioned.new
1403
+ rescue => e
1404
+ # Short message only — full backtraces overflow PDF boxes.
1405
+ puts e.class.to_s
1406
+ # Wrap long messages for PDF code-box width.
1407
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
1408
+ end
1290
1409
  ```
1291
1410
 
1292
1411
  Let's try to create a TrajPartitioned, but passing to it two partitions. For that, let's first
@@ -1299,8 +1418,17 @@ create a new Partition:
1299
1418
  And now let's create the TrajPartitioned:
1300
1419
 
1301
1420
  ```{ruby eval_error_8, warning = FALSE}
1302
- @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5), matrix: @trajCochin.matrix,
1303
- list_partitions: R.list(@partCochin, @partCochin2))
1421
+ begin
1422
+ @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
1423
+ matrix: @trajCochin.matrix,
1424
+ list_partitions: R.list(@partCochin,
1425
+ @partCochin2))
1426
+ rescue => e
1427
+ # Short message only — full backtraces overflow PDF boxes.
1428
+ puts e.class.to_s
1429
+ # Wrap long messages for PDF code-box width.
1430
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
1431
+ end
1304
1432
  ```
1305
1433
 
1306
1434
  This didn't work: R function 'list' expects R objects, and in this case, @partCochin and
@@ -1310,8 +1438,17 @@ as Ruby has data structures to maintain a list of objects, the Array. Let's the
1310
1438
  solution:
1311
1439
 
1312
1440
  ```{ruby eval_error_9, warning = FALSE}
1313
- @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5), matrix: @trajCochin.matrix,
1314
- list_partitions: [@partCochin, @partCochin2])
1441
+ begin
1442
+ @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
1443
+ matrix: @trajCochin.matrix,
1444
+ list_partitions: [@partCochin,
1445
+ @partCochin2])
1446
+ rescue => e
1447
+ # Short message only — full backtraces overflow PDF boxes.
1448
+ puts e.class.to_s
1449
+ # Wrap long messages for PDF code-box width.
1450
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
1451
+ end
1315
1452
  ```
1316
1453
 
1317
1454
  We now get a second error: 'unknown keyword: list_partitions'. Class TrajPartitioned inherits
@@ -1343,8 +1480,10 @@ end
1343
1480
  Let's try our example again:
1344
1481
 
1345
1482
  ```{ruby}
1346
- @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5), matrix: @trajCochin.matrix,
1347
- list_partitions: [@partCochin, @partCochin2])
1483
+ @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
1484
+ matrix: @trajCochin.matrix,
1485
+ list_partitions: [@partCochin,
1486
+ @partCochin2])
1348
1487
  ```
1349
1488
 
1350
1489
  Now @tdCochin is created correctly; however, the 'show' method only shows information about
@@ -1363,7 +1502,9 @@ class TrajPartitioned
1363
1502
 
1364
1503
  def print
1365
1504
  super
1366
- puts ("the object also contains #{@list_partitions.length} partition")
1505
+ puts(
1506
+ "the object also contains " +
1507
+ "#{@list_partitions.length} partition")
1367
1508
  puts ("***** Fine of print (TrajPartitioned) *****")
1368
1509
  end
1369
1510
 
@@ -1498,15 +1639,18 @@ Since Ruby has no type definition, there is no really need for a parent class an
1498
1639
  However, we will implement those classes in order to show Ruby's inheritance:
1499
1640
 
1500
1641
  ```{ruby}
1501
- # Parent class. Differently from SS4, both 'nb_groups' and 'part' are defined in the
1642
+ # Parent class. Differently from SS4, both 'nb_groups' and 'part' are
1643
+ # defined in the
1502
1644
  # parent class.
1503
1645
  class PartitionFather
1504
1646
 
1505
1647
  attr_reader :nb_groups
1506
1648
  attr_reader :part
1507
1649
 
1508
- # initialize class PartitionFather with the number of groups and parts. Note that we
1509
- # use R.c for nb_groups in order to convert the number of groups into an R vector.
1650
+ # initialize class PartitionFather with the number of groups and
1651
+ # parts. Note that we
1652
+ # use R.c for nb_groups in order to convert the number of groups into
1653
+ # an R vector.
1510
1654
  def initialize(nb_groups: 0, part: nil)
1511
1655
  @nb_groups = R.c(nb_groups)
1512
1656
  @part = part
@@ -1517,7 +1661,8 @@ class PartitionFather
1517
1661
  @nb_groups * 2
1518
1662
  end
1519
1663
 
1520
- # method 'to_s' is called whenever we try to print a Ruby object. This method emulates
1664
+ # method 'to_s' is called whenever we try to print a Ruby object.
1665
+ # This method emulates
1521
1666
  # R 'print' method that prints all the slots.
1522
1667
  def to_s
1523
1668
  puts ("Variable 'nb_groups':")
@@ -1530,8 +1675,10 @@ class PartitionFather
1530
1675
 
1531
1676
  end
1532
1677
 
1533
- # Class PartitionSimple is a subclass of PartitionFather. To make a subclass of a
1534
- # class we use the operator '<'. Since the whole logic is in the parent class
1678
+ # Class PartitionSimple is a subclass of PartitionFather. To make a
1679
+ # subclass of a
1680
+ # class we use the operator '<'. Since the whole logic is in the parent
1681
+ # class
1535
1682
  # PartitionSimple is just an empty class
1536
1683
  class PartitionSimple < PartitionFather
1537
1684
 
@@ -1544,7 +1691,9 @@ end
1544
1691
  ```
1545
1692
 
1546
1693
  ```{ruby}
1547
- @a = PartitionSimple.new(nb_groups: 3, part: ((~R[:LETTERS])[R.c(1, 2, 3, 2, 2, 1)].factor))
1694
+ @a = PartitionSimple.new(
1695
+ nb_groups: 3,
1696
+ part: ((~R[:LETTERS])[R.c(1, 2, 3, 2, 2, 1)].factor))
1548
1697
  puts @a
1549
1698
  ```
1550
1699
 
@@ -1553,7 +1702,9 @@ puts @a.nb_mult_two
1553
1702
  ```
1554
1703
 
1555
1704
  ```{ruby}
1556
- @b = PartitionEval.new(nb_groups: 5, part: (~R[:LETTERS])[R.c(1, 5, 3, 4, 2, 4)].ordered)
1705
+ @b = PartitionEval.new(
1706
+ nb_groups: 5,
1707
+ part: (~R[:LETTERS])[R.c(1, 5, 3, 4, 2, 4)].ordered)
1557
1708
  puts @b
1558
1709
  ```
1559
1710