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
@@ -20,7 +20,7 @@ fontsize: 11pt
20
20
  ---
21
21
 
22
22
  ```{r setup, echo=FALSE}
23
-
23
+ options(width = 70)
24
24
  ```
25
25
 
26
26
  # Introduction
@@ -78,6 +78,21 @@ the details of instance variables in Ruby, but here we created those variables w
78
78
  keyword 'attr_reader' and a colom before the variables name:
79
79
 
80
80
 
81
+ ```{ruby class_cleanup, echo=FALSE}
82
+ # Drop classes left from a prior output format in one gknit process.
83
+ # Chunks run via KnitrEngine#instance_eval, so classes live under RC.
84
+ mods = [Object]
85
+ mods << RC if defined?(RC)
86
+ %w[
87
+ Trajectories TrajectoriesBis TrajPartitioned
88
+ Partition PartitionFather PartitionSimple PartitionEval
89
+ ].each do |name|
90
+ mods.each do |mod|
91
+ mod.send(:remove_const, name) if mod.const_defined?(name, false)
92
+ end
93
+ end
94
+ ```
95
+
81
96
  ```{ruby class_trajectories}
82
97
  class Trajectories
83
98
  attr_reader :times
@@ -153,7 +168,8 @@ one uses the ':' operator after parameter's name as we can see below:
153
168
  @traj = Trajectories.new(times: R.c(1, 2, 3, 4))
154
169
 
155
170
  # Create a Trajectories with times and matrix
156
- @traj2 = Trajectories.new(times: R.c(1, 3), matrix: R.matrix((1..4), ncol: 2))
171
+ @traj2 = Trajectories.new(times: R.c(1, 3), matrix: R.matrix((1..4),
172
+ ncol: 2))
157
173
  ```
158
174
 
159
175
  # Access to Instance Variables (to reach a slot)
@@ -200,7 +216,8 @@ Cochin and Saint-Anne. We first show the code in R and the corresponding Galaaz
200
216
  + times=c(1: 10, (6: 16) *2),
201
217
  + traj=rbind(
202
218
  + 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)
219
+ + matrix (seq (15.8, 18, length=21), ncol=21, nrow=30,
220
+ byrow=TRUE)
204
221
  + )+rnorm (21*80,0,0.2)
205
222
  + )
206
223
  ```
@@ -218,12 +235,16 @@ This same code in Galaaz becomes:
218
235
  R.c(15.7, 15.6, 15.8, 16)))
219
236
 
220
237
  @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)))
238
+ Trajectories.new(
239
+ times: R.c((1..10), R.c(6..16) * 2),
240
+ matrix: (
241
+ R.rbind(
242
+ R.matrix(R.seq(16, 19, length: 21),
243
+ ncol: 21, nrow: 50, byrow: true),
244
+ R.matrix(R.seq(15.8, 18, length: 21),
245
+ ncol: 21, nrow: 30, byrow: true)
246
+ ) + R.rnorm(21 * 80, 0, 0.2)
247
+ ))
227
248
 
228
249
  ```
229
250
 
@@ -470,7 +491,8 @@ class Trajectories
470
491
  nrow_show = [10, @matrix.nrow >> 0].min
471
492
  ncol_show = R.min(10, @matrix.ncol) >> 0
472
493
  puts("* Traj (limited to a matrix 10x10) = ")
473
- puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2, nsmall: 2)
494
+ puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2,
495
+ nsmall: 2)
474
496
  puts("******* End Show (trajectories) ******* ")
475
497
  end
476
498
 
@@ -489,7 +511,14 @@ we try to 'show' it, it will generate an error. Let's see it:
489
511
  ```
490
512
 
491
513
  ```{ruby eval_error_1, warning = FALSE}
492
- @empty_traj.show
514
+ begin
515
+ @empty_traj.show
516
+ rescue => e
517
+ # Short message only — full backtraces overflow PDF boxes.
518
+ puts e.class.to_s
519
+ # Wrap long messages for PDF code-box width.
520
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
521
+ end
493
522
  ```
494
523
 
495
524
  In this example, `@matrix` is `nil`, so calling `@matrix.nrow` raises
@@ -516,7 +545,8 @@ class Trajectories
516
545
  nrow_show = [10, @matrix.nrow >> 0].min
517
546
  ncol_show = R.min(10, @matrix.ncol) >> 0
518
547
  puts("* Traj (limited to a matrix 10x10) = ")
519
- puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2, nsmall: 2)
548
+ puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2,
549
+ nsmall: 2)
520
550
  puts("******* End Show (trajectories) ******* ")
521
551
  end
522
552
 
@@ -621,7 +651,8 @@ Here we show the R code for this validation:
621
651
  + validity=function(object){
622
652
  + cat("~~~ Trajectories: inspector ~~~ \\n")
623
653
  + if(length(object@times)!=ncol(object@traj)){
624
- + stop ("[Trajectories: validation] the number of temporal measurements does not correspond
654
+ + stop ("[Trajectories: validation] the number of temporal
655
+ + measurements does not correspond
625
656
  + }else{}
626
657
  + return(TRUE)
627
658
  + }
@@ -637,10 +668,14 @@ class Trajectories
637
668
  @times = times
638
669
  @matrix = matrix
639
670
 
640
- # validate the input, to make sure that size of @times and the number of columns in
641
- # @matrix are the same
671
+ # Validate: length(@times) must equal ncol(@matrix)
642
672
  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))
673
+ if ((@times.length >> 0) != (@matrix.ncol >> 0))
674
+ raise(
675
+ "[Trajectories: validation] the number of temporal " +
676
+ "measurements does not correspond with the number of " +
677
+ "columns in the matrix")
678
+ end
644
679
 
645
680
  # show the object just created
646
681
  show
@@ -655,7 +690,8 @@ equal to the number of columns of the matrix. In this case, we will show a mess
655
690
  validation was done and then print the object.
656
691
 
657
692
  ```{ruby}
658
- ok = Trajectories.new(times: R.c(1..2), matrix: R.matrix((1..2), ncol: 2))
693
+ ok = Trajectories.new(times: R.c(1..2), matrix: R.matrix((1..2),
694
+ ncol: 2))
659
695
  ```
660
696
 
661
697
  Now, if we try to create a Trajectories that does not pass the validation criteria, our code
@@ -665,7 +701,15 @@ on exceptions on the web.
665
701
 
666
702
 
667
703
  ```{ruby eval_error_2, warning = FALSE}
668
- error = Trajectories.new(times: R.c(1..3), matrix: R.matrix((1..2), ncol: 2))
704
+ begin
705
+ error = Trajectories.new(times: R.c(1..3), matrix: R.matrix((1..2),
706
+ ncol: 2))
707
+ rescue => e
708
+ # Short message only — full backtraces overflow PDF boxes.
709
+ puts e.class.to_s
710
+ # Wrap long messages for PDF code-box width.
711
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
712
+ end
669
713
  ```
670
714
 
671
715
  The validation above does not consider the case when an empty object is created. Here we will
@@ -696,12 +740,18 @@ class Trajectories
696
740
  def validate
697
741
 
698
742
  # 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?)
743
+ if (@times.nil? || @matrix.nil?)
744
+ raise "Neither times nor matrix can be an empty object"
745
+ end
700
746
 
701
- # validate the input, to make sure that size of @times and the number of columns in
702
- # @matrix are the same
747
+ # Validate: length(@times) must equal ncol(@matrix)
703
748
  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))
749
+ if ((@times.length >> 0) != (@matrix.ncol >> 0))
750
+ raise(
751
+ "[Trajectories: validation] the number of temporal " +
752
+ "measurements does not correspond with the number of " +
753
+ "columns in the matrix")
754
+ end
705
755
 
706
756
  end
707
757
 
@@ -717,20 +767,35 @@ Let's try then creating an empty object:
717
767
 
718
768
 
719
769
  ```{ruby eval_error_3, warning = FALSE}
720
- error = Trajectories.new
770
+ begin
771
+ error = Trajectories.new
772
+ rescue => e
773
+ # Short message only — full backtraces overflow PDF boxes.
774
+ puts e.class.to_s
775
+ # Wrap long messages for PDF code-box width.
776
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
777
+ end
721
778
  ```
722
779
 
723
780
  Another example:
724
781
 
725
782
  ```{ruby eval_error_4, warning = FALSE}
726
- error = Trajectories.new(times: 1)
783
+ begin
784
+ error = Trajectories.new(times: 1)
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
727
791
  ```
728
792
 
729
793
  Let's see now that the implementation is correct and that it does not raise an error on valid
730
794
  input:
731
795
 
732
796
  ```{ruby}
733
- ok = Trajectories.new(times: R.c(1, 2), matrix: R.matrix((1..2), ncol: 2))
797
+ ok = Trajectories.new(times: R.c(1, 2), matrix: R.matrix((1..2),
798
+ ncol: 2))
734
799
  ```
735
800
 
736
801
  The 'initialize' method is called ONLY during the initial creation of the object. If any instance
@@ -772,13 +837,19 @@ class Trajectories
772
837
  def validate
773
838
 
774
839
  # 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?)
840
+ if (@times.nil? || @matrix.nil?)
841
+ raise "Neither times nor matrix can be an empty object"
842
+ end
776
843
 
777
- # validate the input, to make sure that size of @times and the number of columns in
778
- # @matrix are the same
844
+ # Validate: length(@times) must equal ncol(@matrix)
779
845
  puts ("~~~ Trajectories: inspector ~~~ ")
780
846
  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)
847
+ if (tl != mc)
848
+ raise(
849
+ "[Trajectories: validation] the number of temporal " +
850
+ "measurements #{tl} does not correspond with the number " +
851
+ "of columns in the matrix #{mc}")
852
+ end
782
853
 
783
854
  end
784
855
 
@@ -858,14 +929,23 @@ end
858
929
  ```
859
930
 
860
931
  ```{ruby}
861
- @traj = Trajectories.new(times: R.c(1,2,4,8), matrix: R.matrix((1..8), nrow: 2))
932
+ @traj = Trajectories.new(times: R.c(1,2,4,8), matrix: R.matrix((1..8),
933
+ nrow: 2))
862
934
  ```
863
935
 
864
936
  Note that we still call our 'validate' method and it is still an error to create an empty
865
937
  Trajectories or one in which the sizes are wrong:
866
938
 
867
939
  ```{ruby eval_error_5, warning = FALSE}
868
- error = Trajectories.new(times: R.c(1, 2, 48), matrix: R.matrix((1..8), nrow: 2))
940
+ begin
941
+ error = Trajectories.new(times: R.c(1, 2, 48), matrix: R.matrix((1..8),
942
+ nrow: 2))
943
+ rescue => e
944
+ # Short message only — full backtraces overflow PDF boxes.
945
+ puts e.class.to_s
946
+ # Wrap long messages for PDF code-box width.
947
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
948
+ end
869
949
  ```
870
950
 
871
951
  A constructor does not necessarily take the instance variable of the object as argument. For
@@ -880,7 +960,8 @@ First the code in R, we skip the definition of class TrajectoriesBis:
880
960
  > setMethod ("initialize",
881
961
  + "TrajectoriesBis",
882
962
  + function(.Object,nbWeek,BMIinit){
883
- + traj <- outer(BMIinit,1:nbWeek,function(init,week){return(init+0.1*week)})
963
+ + traj <- outer(BMIinit, 1:nbWeek,
964
+ + function(init, week) { return(init + 0.1 * week) })
884
965
  + colnames(traj) <- paste("T",1:nbWeek,sep="")
885
966
  + rownames(traj) <- paste("I",1:nrow(traj),sep="")
886
967
  + .Object@times <- 1:nbWeek
@@ -912,7 +993,8 @@ class TrajectoriesBis
912
993
 
913
994
  def initialize(number_weeks, bmi_init)
914
995
  @matrix = bmi_init.outer((1..number_weeks),
915
- R.eval("function(init, week) {return(init + 0.1 * week)}"))
996
+ R.eval("function(init,
997
+ week) {return(init + 0.1 * week)}"))
916
998
  @times = R.c((1..number_weeks))
917
999
  end
918
1000
 
@@ -936,7 +1018,9 @@ class TrajectoriesBis
936
1018
 
937
1019
  def initialize(number_weeks, bmi_init, increment)
938
1020
  @matrix = bmi_init.outer((1..number_weeks),
939
- R.eval("function(init, week) {return(init + #{increment} * week)}"))
1021
+ R.eval("function(init,
1022
+ week) {return(init +
1023
+ #{increment} * week)}"))
940
1024
  @times = R.c((1..number_weeks))
941
1025
  end
942
1026
 
@@ -964,7 +1048,8 @@ week, let's define a regular trajectory without having to define a TrajectoriesB
964
1048
 
965
1049
  ```
966
1050
  > regularTrajectories <- function(nbWeek,BMIinit) {
967
- + traj <- outer(BMIinit,1:nbWeek,function(init,week){return(init+0.1*week)})
1051
+ + traj <- outer(BMIinit, 1:nbWeek,
1052
+ + function(init, week) { return(init + 0.1 * week) })
968
1053
  + times <- 1: nbWeek
969
1054
  + return(new(Class="Trajectories",times=times,traj=traj))
970
1055
  + }
@@ -983,7 +1068,8 @@ class Trajectories
983
1068
 
984
1069
  def self.regular(number_weeks: nil, bmi_init: nil)
985
1070
  matrix = bmi_init.outer((1..number_weeks),
986
- R.eval("function(init, week) {return(init + 0.1 * week)}"))
1071
+ R.eval("function(init,
1072
+ week) {return(init + 0.1 * week)}"))
987
1073
  times = R.c((1..number_weeks))
988
1074
  Trajectories.new(times: times, matrix: matrix)
989
1075
  end
@@ -992,7 +1078,8 @@ end
992
1078
  ```
993
1079
 
994
1080
  ```{ruby}
995
- @regular = Trajectories.regular(bmi_init: R.c(14, 15, 16), number_weeks: 3)
1081
+ @regular = Trajectories.regular(bmi_init: R.c(14, 15, 16),
1082
+ number_weeks: 3)
996
1083
  ```
997
1084
 
998
1085
  We have already seen that constructors can be as complex as needed, calling other methods and doing
@@ -1124,7 +1211,12 @@ class Trajectories
1124
1211
  def times=(times)
1125
1212
  times = as_r(times)
1126
1213
  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)
1214
+ if (tl != mc)
1215
+ raise(
1216
+ "[Trajectories: validation] the number of temporal " +
1217
+ "measurements #{tl} does not correspond with the number " +
1218
+ "of columns in the matrix #{mc}")
1219
+ end
1128
1220
  @times = times
1129
1221
  end
1130
1222
 
@@ -1132,7 +1224,14 @@ end
1132
1224
  ```
1133
1225
 
1134
1226
  ```{ruby eval_error_6, warning = FALSE}
1135
- @trajCochin.times = (1..5)
1227
+ begin
1228
+ @trajCochin.times = (1..5)
1229
+ rescue => e
1230
+ # Short message only — full backtraces overflow PDF boxes.
1231
+ puts e.class.to_s
1232
+ # Wrap long messages for PDF code-box width.
1233
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
1234
+ end
1136
1235
  ```
1137
1236
 
1138
1237
  We now set the value appropriately and will not get any errors:
@@ -1286,7 +1385,14 @@ both times and matrix to be non null.
1286
1385
 
1287
1386
 
1288
1387
  ```{ruby eval_error_7, warning = FALSE}
1289
- @tdPitie = TrajPartitioned.new
1388
+ begin
1389
+ @tdPitie = TrajPartitioned.new
1390
+ rescue => e
1391
+ # Short message only — full backtraces overflow PDF boxes.
1392
+ puts e.class.to_s
1393
+ # Wrap long messages for PDF code-box width.
1394
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
1395
+ end
1290
1396
  ```
1291
1397
 
1292
1398
  Let's try to create a TrajPartitioned, but passing to it two partitions. For that, let's first
@@ -1299,8 +1405,17 @@ create a new Partition:
1299
1405
  And now let's create the TrajPartitioned:
1300
1406
 
1301
1407
  ```{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))
1408
+ begin
1409
+ @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
1410
+ matrix: @trajCochin.matrix,
1411
+ list_partitions: R.list(@partCochin,
1412
+ @partCochin2))
1413
+ rescue => e
1414
+ # Short message only — full backtraces overflow PDF boxes.
1415
+ puts e.class.to_s
1416
+ # Wrap long messages for PDF code-box width.
1417
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
1418
+ end
1304
1419
  ```
1305
1420
 
1306
1421
  This didn't work: R function 'list' expects R objects, and in this case, @partCochin and
@@ -1310,8 +1425,17 @@ as Ruby has data structures to maintain a list of objects, the Array. Let's the
1310
1425
  solution:
1311
1426
 
1312
1427
  ```{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])
1428
+ begin
1429
+ @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
1430
+ matrix: @trajCochin.matrix,
1431
+ list_partitions: [@partCochin,
1432
+ @partCochin2])
1433
+ rescue => e
1434
+ # Short message only — full backtraces overflow PDF boxes.
1435
+ puts e.class.to_s
1436
+ # Wrap long messages for PDF code-box width.
1437
+ e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
1438
+ end
1315
1439
  ```
1316
1440
 
1317
1441
  We now get a second error: 'unknown keyword: list_partitions'. Class TrajPartitioned inherits
@@ -1343,8 +1467,10 @@ end
1343
1467
  Let's try our example again:
1344
1468
 
1345
1469
  ```{ruby}
1346
- @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5), matrix: @trajCochin.matrix,
1347
- list_partitions: [@partCochin, @partCochin2])
1470
+ @tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
1471
+ matrix: @trajCochin.matrix,
1472
+ list_partitions: [@partCochin,
1473
+ @partCochin2])
1348
1474
  ```
1349
1475
 
1350
1476
  Now @tdCochin is created correctly; however, the 'show' method only shows information about
@@ -1363,7 +1489,9 @@ class TrajPartitioned
1363
1489
 
1364
1490
  def print
1365
1491
  super
1366
- puts ("the object also contains #{@list_partitions.length} partition")
1492
+ puts(
1493
+ "the object also contains " +
1494
+ "#{@list_partitions.length} partition")
1367
1495
  puts ("***** Fine of print (TrajPartitioned) *****")
1368
1496
  end
1369
1497
 
@@ -1498,15 +1626,18 @@ Since Ruby has no type definition, there is no really need for a parent class an
1498
1626
  However, we will implement those classes in order to show Ruby's inheritance:
1499
1627
 
1500
1628
  ```{ruby}
1501
- # Parent class. Differently from SS4, both 'nb_groups' and 'part' are defined in the
1629
+ # Parent class. Differently from SS4, both 'nb_groups' and 'part' are
1630
+ # defined in the
1502
1631
  # parent class.
1503
1632
  class PartitionFather
1504
1633
 
1505
1634
  attr_reader :nb_groups
1506
1635
  attr_reader :part
1507
1636
 
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.
1637
+ # initialize class PartitionFather with the number of groups and
1638
+ # parts. Note that we
1639
+ # use R.c for nb_groups in order to convert the number of groups into
1640
+ # an R vector.
1510
1641
  def initialize(nb_groups: 0, part: nil)
1511
1642
  @nb_groups = R.c(nb_groups)
1512
1643
  @part = part
@@ -1517,7 +1648,8 @@ class PartitionFather
1517
1648
  @nb_groups * 2
1518
1649
  end
1519
1650
 
1520
- # method 'to_s' is called whenever we try to print a Ruby object. This method emulates
1651
+ # method 'to_s' is called whenever we try to print a Ruby object.
1652
+ # This method emulates
1521
1653
  # R 'print' method that prints all the slots.
1522
1654
  def to_s
1523
1655
  puts ("Variable 'nb_groups':")
@@ -1530,8 +1662,10 @@ class PartitionFather
1530
1662
 
1531
1663
  end
1532
1664
 
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
1665
+ # Class PartitionSimple is a subclass of PartitionFather. To make a
1666
+ # subclass of a
1667
+ # class we use the operator '<'. Since the whole logic is in the parent
1668
+ # class
1535
1669
  # PartitionSimple is just an empty class
1536
1670
  class PartitionSimple < PartitionFather
1537
1671
 
@@ -1544,7 +1678,9 @@ end
1544
1678
  ```
1545
1679
 
1546
1680
  ```{ruby}
1547
- @a = PartitionSimple.new(nb_groups: 3, part: ((~R[:LETTERS])[R.c(1, 2, 3, 2, 2, 1)].factor))
1681
+ @a = PartitionSimple.new(
1682
+ nb_groups: 3,
1683
+ part: ((~R[:LETTERS])[R.c(1, 2, 3, 2, 2, 1)].factor))
1548
1684
  puts @a
1549
1685
  ```
1550
1686
 
@@ -1553,7 +1689,9 @@ puts @a.nb_mult_two
1553
1689
  ```
1554
1690
 
1555
1691
  ```{ruby}
1556
- @b = PartitionEval.new(nb_groups: 5, part: (~R[:LETTERS])[R.c(1, 5, 3, 4, 2, 4)].ordered)
1692
+ @b = PartitionEval.new(
1693
+ nb_groups: 5,
1694
+ part: (~R[:LETTERS])[R.c(1, 5, 3, 4, 2, 4)].ordered)
1557
1695
  puts @b
1558
1696
  ```
1559
1697