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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot.Rmd +63 -58
- data/blogs/galaaz_ggplot/galaaz_ggplot.log +59 -68
- data/blogs/galaaz_ggplot/galaaz_ggplot.md +91 -84
- data/blogs/galaaz_ggplot/galaaz_ggplot.tex +125 -94
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-html/scatter_plot_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/midwest_rb.png +0 -0
- data/blogs/galaaz_ggplot/galaaz_ggplot_files/figure-markdown_github/scatter_plot_rb.png +0 -0
- data/blogs/gknit/gknit.Rmd +33 -28
- data/blogs/gknit/gknit.md +47 -42
- data/blogs/gknit/gknit.tex +1368 -0
- data/blogs/gknit/gknit_files/figure-html/bubble-1.png +0 -0
- data/blogs/gknit/gknit_files/figure-html/diverging_bar.png +0 -0
- data/blogs/gknit/gknit_files/figure-latex/bubble-1.png +0 -0
- data/blogs/gknit/gknit_files/gknit_files/figure-latex/bubble-1.png +0 -0
- data/blogs/manual/manual.Rmd +129 -60
- data/blogs/manual/manual.log +289 -545
- data/blogs/manual/manual.md +551 -467
- data/blogs/manual/manual.tex +1059 -485
- data/blogs/manual/manual_files/figure-html/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-latex/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-markdown_github/bubble-1.png +0 -0
- data/blogs/manual/manual_files/figure-markdown_github/diverging_bar.png +0 -0
- data/blogs/manual/manual_files/manual_files/figure-latex/bubble-1.png +0 -0
- data/blogs/nse_dplyr/nse_dplyr.Rmd +28 -7
- data/blogs/nse_dplyr/nse_dplyr.log +49 -153
- data/blogs/nse_dplyr/nse_dplyr.md +676 -705
- data/blogs/nse_dplyr/nse_dplyr.tex +1589 -0
- data/blogs/oh_my/oh_my.Rmd +193 -55
- data/blogs/oh_my/oh_my.log +265 -95
- data/blogs/oh_my/oh_my.md +236 -95
- data/blogs/oh_my/oh_my.tex +1976 -68
- data/blogs/ruby_plot/ruby_plot.Rmd +42 -34
- data/blogs/ruby_plot/ruby_plot.log +101 -99
- data/blogs/ruby_plot/ruby_plot.md +52 -46
- data/blogs/ruby_plot/ruby_plot.tex +134 -102
- data/blogs/ruby_plot/ruby_plot_files/figure-html/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-html/violin_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/dose_len.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_delivery.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facet_by_dose.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_by_delivery_color2.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_decorations.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_jitter.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/facets_with_points.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_box_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/final_violin_plot.png +0 -0
- data/blogs/ruby_plot/ruby_plot_files/ruby_plot_files/figure-latex/violin_with_jitter.png +0 -0
- data/lib/galaaz/cli.rb +51 -10
- data/script/omarchy/README.md +1 -1
- data/script/omarchy/galaaz-guide.sh +1 -1
- data/sty/galaaz.sty +22 -0
- data/version.rb +1 -1
- metadata +19 -1
data/blogs/oh_my/oh_my.md
CHANGED
|
@@ -77,6 +77,8 @@ keyword 'attr_reader' and a colom before the variables name:
|
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
|
|
81
|
+
|
|
80
82
|
``` ruby
|
|
81
83
|
class Trajectories
|
|
82
84
|
attr_reader :times
|
|
@@ -102,7 +104,7 @@ puts @traj
|
|
|
102
104
|
```
|
|
103
105
|
|
|
104
106
|
```
|
|
105
|
-
## #<RC::Trajectories:
|
|
107
|
+
## #<RC::Trajectories:0x58ea712d>
|
|
106
108
|
```
|
|
107
109
|
|
|
108
110
|
To see the contents of an object, one needs to access its components using the '.' operator:
|
|
@@ -161,7 +163,8 @@ one uses the ':' operator after parameter's name as we can see below:
|
|
|
161
163
|
@traj = Trajectories.new(times: R.c(1, 2, 3, 4))
|
|
162
164
|
|
|
163
165
|
# Create a Trajectories with times and matrix
|
|
164
|
-
@traj2 = Trajectories.new(times: R.c(1, 3), matrix: R.matrix((1..4),
|
|
166
|
+
@traj2 = Trajectories.new(times: R.c(1, 3), matrix: R.matrix((1..4),
|
|
167
|
+
ncol: 2))
|
|
165
168
|
```
|
|
166
169
|
|
|
167
170
|
# Access to Instance Variables (to reach a slot)
|
|
@@ -222,7 +225,8 @@ Cochin and Saint-Anne. We first show the code in R and the corresponding Galaaz
|
|
|
222
225
|
+ times=c(1: 10, (6: 16) *2),
|
|
223
226
|
+ traj=rbind(
|
|
224
227
|
+ matrix (seq (16,19, length=21), ncol=21, nrow=50, byrow=TRUE),
|
|
225
|
-
+ matrix (seq (15.8, 18, length=21), ncol=21, nrow=30,
|
|
228
|
+
+ matrix (seq (15.8, 18, length=21), ncol=21, nrow=30,
|
|
229
|
+
byrow=TRUE)
|
|
226
230
|
+ )+rnorm (21*80,0,0.2)
|
|
227
231
|
+ )
|
|
228
232
|
```
|
|
@@ -241,12 +245,16 @@ This same code in Galaaz becomes:
|
|
|
241
245
|
R.c(15.7, 15.6, 15.8, 16)))
|
|
242
246
|
|
|
243
247
|
@trajStAnne =
|
|
244
|
-
Trajectories.new(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
Trajectories.new(
|
|
249
|
+
times: R.c((1..10), R.c(6..16) * 2),
|
|
250
|
+
matrix: (
|
|
251
|
+
R.rbind(
|
|
252
|
+
R.matrix(R.seq(16, 19, length: 21),
|
|
253
|
+
ncol: 21, nrow: 50, byrow: true),
|
|
254
|
+
R.matrix(R.seq(15.8, 18, length: 21),
|
|
255
|
+
ncol: 21, nrow: 30, byrow: true)
|
|
256
|
+
) + R.rnorm(21 * 80, 0, 0.2)
|
|
257
|
+
))
|
|
250
258
|
```
|
|
251
259
|
|
|
252
260
|
Let's check that the 'times' and 'matrix' instance variables were correctly set:
|
|
@@ -264,10 +272,10 @@ puts @trajStAnne.times
|
|
|
264
272
|
## [1] 1 3 4 5
|
|
265
273
|
##
|
|
266
274
|
## [,1] [,2] [,3] [,4]
|
|
267
|
-
##
|
|
268
|
-
##
|
|
269
|
-
##
|
|
270
|
-
##
|
|
275
|
+
## g2_v729 15.0 15.1 15.2 15.2
|
|
276
|
+
## g2_v730 16.0 15.9 16.0 16.4
|
|
277
|
+
## g2_v731 15.2 NA 15.3 15.3
|
|
278
|
+
## g2_v732 15.7 15.6 15.8 16.0
|
|
271
279
|
##
|
|
272
280
|
## [1] 1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 22 24 26 28 30 32
|
|
273
281
|
```
|
|
@@ -466,10 +474,10 @@ end
|
|
|
466
474
|
## 5
|
|
467
475
|
## traj =
|
|
468
476
|
## [,1] [,2] [,3] [,4]
|
|
469
|
-
##
|
|
470
|
-
##
|
|
471
|
-
##
|
|
472
|
-
##
|
|
477
|
+
## g2_v729 15.0 15.1 15.2 15.2
|
|
478
|
+
## g2_v730 16.0 15.9 16.0 16.4
|
|
479
|
+
## g2_v731 15.2 NA 15.3 15.3
|
|
480
|
+
## g2_v732 15.7 15.6 15.8 16.0
|
|
473
481
|
## ******* End Print (trajectories) *******
|
|
474
482
|
```
|
|
475
483
|
|
|
@@ -541,7 +549,8 @@ class Trajectories
|
|
|
541
549
|
nrow_show = [10, @matrix.nrow >> 0].min
|
|
542
550
|
ncol_show = R.min(10, @matrix.ncol) >> 0
|
|
543
551
|
puts("* Traj (limited to a matrix 10x10) = ")
|
|
544
|
-
puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2,
|
|
552
|
+
puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2,
|
|
553
|
+
nsmall: 2)
|
|
545
554
|
puts("******* End Show (trajectories) ******* ")
|
|
546
555
|
end
|
|
547
556
|
|
|
@@ -577,28 +586,28 @@ end
|
|
|
577
586
|
## 30
|
|
578
587
|
## 32
|
|
579
588
|
## * Traj (limited to a matrix 10x10) =
|
|
580
|
-
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
|
|
581
|
-
## [1,] "
|
|
582
|
-
## [2,] "16.
|
|
583
|
-
## [3,] "
|
|
584
|
-
## [4,] "
|
|
585
|
-
## [5,] "16.
|
|
586
|
-
## [6,] "
|
|
587
|
-
## [7,] "
|
|
588
|
-
## [8,] "
|
|
589
|
-
## [9,] "
|
|
590
|
-
## [10,] "
|
|
591
|
-
## [,10]
|
|
592
|
-
## [1,] "17.
|
|
593
|
-
## [2,] "17.
|
|
594
|
-
## [3,] "17.
|
|
595
|
-
## [4,] "17.
|
|
596
|
-
## [5,] "17.
|
|
597
|
-
## [6,] "17.
|
|
598
|
-
## [7,] "16.
|
|
599
|
-
## [8,] "17.
|
|
600
|
-
## [9,] "17.
|
|
601
|
-
## [10,] "17.
|
|
589
|
+
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
|
|
590
|
+
## [1,] "16.11" "16.22" "16.57" "16.54" "16.06" "16.73" "16.52" "17.07"
|
|
591
|
+
## [2,] "16.22" "15.78" "16.51" "16.27" "16.78" "17.07" "16.89" "17.03"
|
|
592
|
+
## [3,] "16.11" "16.32" "16.17" "16.56" "16.63" "16.83" "16.76" "17.17"
|
|
593
|
+
## [4,] "16.28" "16.11" "16.42" "16.40" "16.54" "16.22" "16.48" "17.14"
|
|
594
|
+
## [5,] "16.11" "16.30" "16.12" "16.47" "16.49" "16.66" "16.98" "17.17"
|
|
595
|
+
## [6,] "15.63" "16.22" "16.53" "16.52" "16.50" "16.63" "17.07" "17.04"
|
|
596
|
+
## [7,] "16.18" "16.16" "15.89" "16.22" "16.82" "16.97" "17.16" "17.22"
|
|
597
|
+
## [8,] "15.53" "15.93" "16.36" "16.86" "16.26" "16.92" "16.96" "16.97"
|
|
598
|
+
## [9,] "15.92" "16.22" "16.22" "16.13" "16.52" "16.77" "17.14" "16.76"
|
|
599
|
+
## [10,] "16.45" "15.91" "16.14" "16.62" "16.53" "17.11" "16.96" "17.00"
|
|
600
|
+
## [,9] [,10]
|
|
601
|
+
## [1,] "17.24" "17.34"
|
|
602
|
+
## [2,] "17.60" "17.19"
|
|
603
|
+
## [3,] "17.63" "17.24"
|
|
604
|
+
## [4,] "17.18" "17.55"
|
|
605
|
+
## [5,] "17.25" "17.49"
|
|
606
|
+
## [6,] "17.19" "17.06"
|
|
607
|
+
## [7,] "16.90" "17.34"
|
|
608
|
+
## [8,] "17.32" "17.01"
|
|
609
|
+
## [9,] "17.46" "17.31"
|
|
610
|
+
## [10,] "17.29" "17.21"
|
|
602
611
|
## ******* End Show (trajectories) *******
|
|
603
612
|
```
|
|
604
613
|
|
|
@@ -612,10 +621,20 @@ we try to 'show' it, it will generate an error. Let's see it:
|
|
|
612
621
|
|
|
613
622
|
|
|
614
623
|
``` ruby
|
|
615
|
-
|
|
624
|
+
begin
|
|
625
|
+
@empty_traj.show
|
|
626
|
+
rescue => e
|
|
627
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
628
|
+
puts e.class.to_s
|
|
629
|
+
# Wrap long messages for PDF code-box width.
|
|
630
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
631
|
+
end
|
|
616
632
|
```
|
|
617
633
|
|
|
618
634
|
```
|
|
635
|
+
## *** Class Trajectories, method Show ***
|
|
636
|
+
## times =
|
|
637
|
+
## NoMethodError
|
|
619
638
|
## undefined method 'nrow' for nil
|
|
620
639
|
```
|
|
621
640
|
|
|
@@ -644,7 +663,8 @@ class Trajectories
|
|
|
644
663
|
nrow_show = [10, @matrix.nrow >> 0].min
|
|
645
664
|
ncol_show = R.min(10, @matrix.ncol) >> 0
|
|
646
665
|
puts("* Traj (limited to a matrix 10x10) = ")
|
|
647
|
-
puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2,
|
|
666
|
+
puts @matrix[(1..nrow_show), (1..ncol_show)].format(digits: 2,
|
|
667
|
+
nsmall: 2)
|
|
648
668
|
puts("******* End Show (trajectories) ******* ")
|
|
649
669
|
end
|
|
650
670
|
|
|
@@ -769,7 +789,8 @@ Here we show the R code for this validation:
|
|
|
769
789
|
+ validity=function(object){
|
|
770
790
|
+ cat("~~~ Trajectories: inspector ~~~ \\n")
|
|
771
791
|
+ if(length(object@times)!=ncol(object@traj)){
|
|
772
|
-
+ stop ("[Trajectories: validation] the number of temporal
|
|
792
|
+
+ stop ("[Trajectories: validation] the number of temporal
|
|
793
|
+
+ measurements does not correspond
|
|
773
794
|
+ }else{}
|
|
774
795
|
+ return(TRUE)
|
|
775
796
|
+ }
|
|
@@ -786,10 +807,14 @@ class Trajectories
|
|
|
786
807
|
@times = times
|
|
787
808
|
@matrix = matrix
|
|
788
809
|
|
|
789
|
-
#
|
|
790
|
-
# @matrix are the same
|
|
810
|
+
# Validate: length(@times) must equal ncol(@matrix)
|
|
791
811
|
puts ("~~~ Trajectories: inspector ~~~ ")
|
|
792
|
-
|
|
812
|
+
if ((@times.length >> 0) != (@matrix.ncol >> 0))
|
|
813
|
+
raise(
|
|
814
|
+
"[Trajectories: validation] the number of temporal " +
|
|
815
|
+
"measurements does not correspond with the number of " +
|
|
816
|
+
"columns in the matrix")
|
|
817
|
+
end
|
|
793
818
|
|
|
794
819
|
# show the object just created
|
|
795
820
|
show
|
|
@@ -805,7 +830,8 @@ validation was done and then print the object.
|
|
|
805
830
|
|
|
806
831
|
|
|
807
832
|
``` ruby
|
|
808
|
-
ok = Trajectories.new(times: R.c(1..2), matrix: R.matrix((1..2),
|
|
833
|
+
ok = Trajectories.new(times: R.c(1..2), matrix: R.matrix((1..2),
|
|
834
|
+
ncol: 2))
|
|
809
835
|
```
|
|
810
836
|
|
|
811
837
|
```
|
|
@@ -827,11 +853,22 @@ on exceptions on the web.
|
|
|
827
853
|
|
|
828
854
|
|
|
829
855
|
``` ruby
|
|
830
|
-
|
|
856
|
+
begin
|
|
857
|
+
error = Trajectories.new(times: R.c(1..3), matrix: R.matrix((1..2),
|
|
858
|
+
ncol: 2))
|
|
859
|
+
rescue => e
|
|
860
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
861
|
+
puts e.class.to_s
|
|
862
|
+
# Wrap long messages for PDF code-box width.
|
|
863
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
864
|
+
end
|
|
831
865
|
```
|
|
832
866
|
|
|
833
867
|
```
|
|
834
|
-
##
|
|
868
|
+
## ~~~ Trajectories: inspector ~~~
|
|
869
|
+
## RuntimeError
|
|
870
|
+
## [Trajectories: validation] the number of temporal measurements does
|
|
871
|
+
## not correspond with the number of columns in the matrix
|
|
835
872
|
```
|
|
836
873
|
|
|
837
874
|
The validation above does not consider the case when an empty object is created. Here we will
|
|
@@ -863,12 +900,18 @@ class Trajectories
|
|
|
863
900
|
def validate
|
|
864
901
|
|
|
865
902
|
# Let's first check that we do not have an empty object
|
|
866
|
-
|
|
903
|
+
if (@times.nil? || @matrix.nil?)
|
|
904
|
+
raise "Neither times nor matrix can be an empty object"
|
|
905
|
+
end
|
|
867
906
|
|
|
868
|
-
#
|
|
869
|
-
# @matrix are the same
|
|
907
|
+
# Validate: length(@times) must equal ncol(@matrix)
|
|
870
908
|
puts ("~~~ Trajectories: inspector ~~~ ")
|
|
871
|
-
|
|
909
|
+
if ((@times.length >> 0) != (@matrix.ncol >> 0))
|
|
910
|
+
raise(
|
|
911
|
+
"[Trajectories: validation] the number of temporal " +
|
|
912
|
+
"measurements does not correspond with the number of " +
|
|
913
|
+
"columns in the matrix")
|
|
914
|
+
end
|
|
872
915
|
|
|
873
916
|
end
|
|
874
917
|
|
|
@@ -885,10 +928,18 @@ Let's try then creating an empty object:
|
|
|
885
928
|
|
|
886
929
|
|
|
887
930
|
``` ruby
|
|
888
|
-
|
|
931
|
+
begin
|
|
932
|
+
error = Trajectories.new
|
|
933
|
+
rescue => e
|
|
934
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
935
|
+
puts e.class.to_s
|
|
936
|
+
# Wrap long messages for PDF code-box width.
|
|
937
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
938
|
+
end
|
|
889
939
|
```
|
|
890
940
|
|
|
891
941
|
```
|
|
942
|
+
## RuntimeError
|
|
892
943
|
## Neither times nor matrix can be an empty object
|
|
893
944
|
```
|
|
894
945
|
|
|
@@ -896,10 +947,18 @@ Another example:
|
|
|
896
947
|
|
|
897
948
|
|
|
898
949
|
``` ruby
|
|
899
|
-
|
|
950
|
+
begin
|
|
951
|
+
error = Trajectories.new(times: 1)
|
|
952
|
+
rescue => e
|
|
953
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
954
|
+
puts e.class.to_s
|
|
955
|
+
# Wrap long messages for PDF code-box width.
|
|
956
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
957
|
+
end
|
|
900
958
|
```
|
|
901
959
|
|
|
902
960
|
```
|
|
961
|
+
## RuntimeError
|
|
903
962
|
## Neither times nor matrix can be an empty object
|
|
904
963
|
```
|
|
905
964
|
|
|
@@ -908,7 +967,8 @@ input:
|
|
|
908
967
|
|
|
909
968
|
|
|
910
969
|
``` ruby
|
|
911
|
-
ok = Trajectories.new(times: R.c(1, 2), matrix: R.matrix((1..2),
|
|
970
|
+
ok = Trajectories.new(times: R.c(1, 2), matrix: R.matrix((1..2),
|
|
971
|
+
ncol: 2))
|
|
912
972
|
```
|
|
913
973
|
|
|
914
974
|
```
|
|
@@ -962,13 +1022,19 @@ class Trajectories
|
|
|
962
1022
|
def validate
|
|
963
1023
|
|
|
964
1024
|
# Let's first check that we do not have an empty object
|
|
965
|
-
|
|
1025
|
+
if (@times.nil? || @matrix.nil?)
|
|
1026
|
+
raise "Neither times nor matrix can be an empty object"
|
|
1027
|
+
end
|
|
966
1028
|
|
|
967
|
-
#
|
|
968
|
-
# @matrix are the same
|
|
1029
|
+
# Validate: length(@times) must equal ncol(@matrix)
|
|
969
1030
|
puts ("~~~ Trajectories: inspector ~~~ ")
|
|
970
1031
|
tl = @times.length >> 0; mc = @matrix.ncol >> 0
|
|
971
|
-
|
|
1032
|
+
if (tl != mc)
|
|
1033
|
+
raise(
|
|
1034
|
+
"[Trajectories: validation] the number of temporal " +
|
|
1035
|
+
"measurements #{tl} does not correspond with the number " +
|
|
1036
|
+
"of columns in the matrix #{mc}")
|
|
1037
|
+
end
|
|
972
1038
|
|
|
973
1039
|
end
|
|
974
1040
|
|
|
@@ -1062,7 +1128,8 @@ end
|
|
|
1062
1128
|
|
|
1063
1129
|
|
|
1064
1130
|
``` ruby
|
|
1065
|
-
@traj = Trajectories.new(times: R.c(1,2,4,8), matrix: R.matrix((1..8),
|
|
1131
|
+
@traj = Trajectories.new(times: R.c(1,2,4,8), matrix: R.matrix((1..8),
|
|
1132
|
+
nrow: 2))
|
|
1066
1133
|
```
|
|
1067
1134
|
|
|
1068
1135
|
```
|
|
@@ -1085,11 +1152,22 @@ Trajectories or one in which the sizes are wrong:
|
|
|
1085
1152
|
|
|
1086
1153
|
|
|
1087
1154
|
``` ruby
|
|
1088
|
-
|
|
1155
|
+
begin
|
|
1156
|
+
error = Trajectories.new(times: R.c(1, 2, 48), matrix: R.matrix((1..8),
|
|
1157
|
+
nrow: 2))
|
|
1158
|
+
rescue => e
|
|
1159
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
1160
|
+
puts e.class.to_s
|
|
1161
|
+
# Wrap long messages for PDF code-box width.
|
|
1162
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
1163
|
+
end
|
|
1089
1164
|
```
|
|
1090
1165
|
|
|
1091
1166
|
```
|
|
1092
|
-
##
|
|
1167
|
+
## ~~~ Trajectories: inspector ~~~
|
|
1168
|
+
## RuntimeError
|
|
1169
|
+
## [Trajectories: validation] the number of temporal measurements 3 doe
|
|
1170
|
+
## s not correspond with the number of columns in the matrix 4
|
|
1093
1171
|
```
|
|
1094
1172
|
|
|
1095
1173
|
A constructor does not necessarily take the instance variable of the object as argument. For
|
|
@@ -1104,7 +1182,8 @@ First the code in R, we skip the definition of class TrajectoriesBis:
|
|
|
1104
1182
|
> setMethod ("initialize",
|
|
1105
1183
|
+ "TrajectoriesBis",
|
|
1106
1184
|
+ function(.Object,nbWeek,BMIinit){
|
|
1107
|
-
+ traj <- outer(BMIinit,1:nbWeek,
|
|
1185
|
+
+ traj <- outer(BMIinit, 1:nbWeek,
|
|
1186
|
+
+ function(init, week) { return(init + 0.1 * week) })
|
|
1108
1187
|
+ colnames(traj) <- paste("T",1:nbWeek,sep="")
|
|
1109
1188
|
+ rownames(traj) <- paste("I",1:nrow(traj),sep="")
|
|
1110
1189
|
+ .Object@times <- 1:nbWeek
|
|
@@ -1137,7 +1216,8 @@ class TrajectoriesBis
|
|
|
1137
1216
|
|
|
1138
1217
|
def initialize(number_weeks, bmi_init)
|
|
1139
1218
|
@matrix = bmi_init.outer((1..number_weeks),
|
|
1140
|
-
R.eval("function(init,
|
|
1219
|
+
R.eval("function(init,
|
|
1220
|
+
week) {return(init + 0.1 * week)}"))
|
|
1141
1221
|
@times = R.c((1..number_weeks))
|
|
1142
1222
|
end
|
|
1143
1223
|
|
|
@@ -1170,7 +1250,9 @@ class TrajectoriesBis
|
|
|
1170
1250
|
|
|
1171
1251
|
def initialize(number_weeks, bmi_init, increment)
|
|
1172
1252
|
@matrix = bmi_init.outer((1..number_weeks),
|
|
1173
|
-
R.eval("function(init,
|
|
1253
|
+
R.eval("function(init,
|
|
1254
|
+
week) {return(init +
|
|
1255
|
+
#{increment} * week)}"))
|
|
1174
1256
|
@times = R.c((1..number_weeks))
|
|
1175
1257
|
end
|
|
1176
1258
|
|
|
@@ -1206,7 +1288,8 @@ week, let's define a regular trajectory without having to define a TrajectoriesB
|
|
|
1206
1288
|
|
|
1207
1289
|
```
|
|
1208
1290
|
> regularTrajectories <- function(nbWeek,BMIinit) {
|
|
1209
|
-
+ traj <- outer(BMIinit,1:nbWeek,
|
|
1291
|
+
+ traj <- outer(BMIinit, 1:nbWeek,
|
|
1292
|
+
+ function(init, week) { return(init + 0.1 * week) })
|
|
1210
1293
|
+ times <- 1: nbWeek
|
|
1211
1294
|
+ return(new(Class="Trajectories",times=times,traj=traj))
|
|
1212
1295
|
+ }
|
|
@@ -1226,7 +1309,8 @@ class Trajectories
|
|
|
1226
1309
|
|
|
1227
1310
|
def self.regular(number_weeks: nil, bmi_init: nil)
|
|
1228
1311
|
matrix = bmi_init.outer((1..number_weeks),
|
|
1229
|
-
R.eval("function(init,
|
|
1312
|
+
R.eval("function(init,
|
|
1313
|
+
week) {return(init + 0.1 * week)}"))
|
|
1230
1314
|
times = R.c((1..number_weeks))
|
|
1231
1315
|
Trajectories.new(times: times, matrix: matrix)
|
|
1232
1316
|
end
|
|
@@ -1236,7 +1320,8 @@ end
|
|
|
1236
1320
|
|
|
1237
1321
|
|
|
1238
1322
|
``` ruby
|
|
1239
|
-
@regular = Trajectories.regular(bmi_init: R.c(14, 15, 16),
|
|
1323
|
+
@regular = Trajectories.regular(bmi_init: R.c(14, 15, 16),
|
|
1324
|
+
number_weeks: 3)
|
|
1240
1325
|
```
|
|
1241
1326
|
|
|
1242
1327
|
```
|
|
@@ -1425,7 +1510,12 @@ class Trajectories
|
|
|
1425
1510
|
def times=(times)
|
|
1426
1511
|
times = as_r(times)
|
|
1427
1512
|
tl = times.length >> 0; mc = @matrix.ncol >> 0
|
|
1428
|
-
|
|
1513
|
+
if (tl != mc)
|
|
1514
|
+
raise(
|
|
1515
|
+
"[Trajectories: validation] the number of temporal " +
|
|
1516
|
+
"measurements #{tl} does not correspond with the number " +
|
|
1517
|
+
"of columns in the matrix #{mc}")
|
|
1518
|
+
end
|
|
1429
1519
|
@times = times
|
|
1430
1520
|
end
|
|
1431
1521
|
|
|
@@ -1434,11 +1524,20 @@ end
|
|
|
1434
1524
|
|
|
1435
1525
|
|
|
1436
1526
|
``` ruby
|
|
1437
|
-
|
|
1527
|
+
begin
|
|
1528
|
+
@trajCochin.times = (1..5)
|
|
1529
|
+
rescue => e
|
|
1530
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
1531
|
+
puts e.class.to_s
|
|
1532
|
+
# Wrap long messages for PDF code-box width.
|
|
1533
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
1534
|
+
end
|
|
1438
1535
|
```
|
|
1439
1536
|
|
|
1440
1537
|
```
|
|
1441
|
-
##
|
|
1538
|
+
## RuntimeError
|
|
1539
|
+
## [Trajectories: validation] the number of temporal measurements 5 doe
|
|
1540
|
+
## s not correspond with the number of columns in the matrix 4
|
|
1442
1541
|
```
|
|
1443
1542
|
|
|
1444
1543
|
We now set the value appropriately and will not get any errors:
|
|
@@ -1587,9 +1686,9 @@ puts @partStAnne.part
|
|
|
1587
1686
|
```
|
|
1588
1687
|
|
|
1589
1688
|
```
|
|
1590
|
-
## [1] A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
|
|
1591
|
-
## [
|
|
1592
|
-
## [
|
|
1689
|
+
## [1] A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
|
|
1690
|
+
## [34] A A A A A A A A A A A A A A A A A B B B B B B B B B B B B B B B B
|
|
1691
|
+
## [67] B B B B B B B B B B B B B B
|
|
1593
1692
|
## Levels: A B
|
|
1594
1693
|
```
|
|
1595
1694
|
|
|
@@ -1627,10 +1726,18 @@ both times and matrix to be non null.
|
|
|
1627
1726
|
|
|
1628
1727
|
|
|
1629
1728
|
``` ruby
|
|
1630
|
-
|
|
1729
|
+
begin
|
|
1730
|
+
@tdPitie = TrajPartitioned.new
|
|
1731
|
+
rescue => e
|
|
1732
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
1733
|
+
puts e.class.to_s
|
|
1734
|
+
# Wrap long messages for PDF code-box width.
|
|
1735
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
1736
|
+
end
|
|
1631
1737
|
```
|
|
1632
1738
|
|
|
1633
1739
|
```
|
|
1740
|
+
## RuntimeError
|
|
1634
1741
|
## Neither times nor matrix can be an empty object
|
|
1635
1742
|
```
|
|
1636
1743
|
|
|
@@ -1646,11 +1753,21 @@ And now let's create the TrajPartitioned:
|
|
|
1646
1753
|
|
|
1647
1754
|
|
|
1648
1755
|
``` ruby
|
|
1649
|
-
|
|
1650
|
-
|
|
1756
|
+
begin
|
|
1757
|
+
@tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
|
|
1758
|
+
matrix: @trajCochin.matrix,
|
|
1759
|
+
list_partitions: R.list(@partCochin,
|
|
1760
|
+
@partCochin2))
|
|
1761
|
+
rescue => e
|
|
1762
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
1763
|
+
puts e.class.to_s
|
|
1764
|
+
# Wrap long messages for PDF code-box width.
|
|
1765
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
1766
|
+
end
|
|
1651
1767
|
```
|
|
1652
1768
|
|
|
1653
1769
|
```
|
|
1770
|
+
## ArgumentError
|
|
1654
1771
|
## unknown keyword: :list_partitions
|
|
1655
1772
|
```
|
|
1656
1773
|
|
|
@@ -1662,11 +1779,21 @@ solution:
|
|
|
1662
1779
|
|
|
1663
1780
|
|
|
1664
1781
|
``` ruby
|
|
1665
|
-
|
|
1666
|
-
|
|
1782
|
+
begin
|
|
1783
|
+
@tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
|
|
1784
|
+
matrix: @trajCochin.matrix,
|
|
1785
|
+
list_partitions: [@partCochin,
|
|
1786
|
+
@partCochin2])
|
|
1787
|
+
rescue => e
|
|
1788
|
+
# Short message only — full backtraces overflow PDF boxes.
|
|
1789
|
+
puts e.class.to_s
|
|
1790
|
+
# Wrap long messages for PDF code-box width.
|
|
1791
|
+
e.message.to_s.scan(/.{1,68}/).each { |line| puts line }
|
|
1792
|
+
end
|
|
1667
1793
|
```
|
|
1668
1794
|
|
|
1669
1795
|
```
|
|
1796
|
+
## ArgumentError
|
|
1670
1797
|
## unknown keyword: :list_partitions
|
|
1671
1798
|
```
|
|
1672
1799
|
|
|
@@ -1701,8 +1828,10 @@ Let's try our example again:
|
|
|
1701
1828
|
|
|
1702
1829
|
|
|
1703
1830
|
``` ruby
|
|
1704
|
-
@tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
|
|
1705
|
-
|
|
1831
|
+
@tdCochin = TrajPartitioned.new(times: R.c(1,3,4,5),
|
|
1832
|
+
matrix: @trajCochin.matrix,
|
|
1833
|
+
list_partitions: [@partCochin,
|
|
1834
|
+
@partCochin2])
|
|
1706
1835
|
```
|
|
1707
1836
|
|
|
1708
1837
|
```
|
|
@@ -1739,7 +1868,9 @@ class TrajPartitioned
|
|
|
1739
1868
|
|
|
1740
1869
|
def print
|
|
1741
1870
|
super
|
|
1742
|
-
puts
|
|
1871
|
+
puts(
|
|
1872
|
+
"the object also contains " +
|
|
1873
|
+
"#{@list_partitions.length} partition")
|
|
1743
1874
|
puts ("***** Fine of print (TrajPartitioned) *****")
|
|
1744
1875
|
end
|
|
1745
1876
|
|
|
@@ -1906,15 +2037,18 @@ However, we will implement those classes in order to show Ruby's inheritance:
|
|
|
1906
2037
|
|
|
1907
2038
|
|
|
1908
2039
|
``` ruby
|
|
1909
|
-
# Parent class. Differently from SS4, both 'nb_groups' and 'part' are
|
|
2040
|
+
# Parent class. Differently from SS4, both 'nb_groups' and 'part' are
|
|
2041
|
+
# defined in the
|
|
1910
2042
|
# parent class.
|
|
1911
2043
|
class PartitionFather
|
|
1912
2044
|
|
|
1913
2045
|
attr_reader :nb_groups
|
|
1914
2046
|
attr_reader :part
|
|
1915
2047
|
|
|
1916
|
-
# initialize class PartitionFather with the number of groups and
|
|
1917
|
-
#
|
|
2048
|
+
# initialize class PartitionFather with the number of groups and
|
|
2049
|
+
# parts. Note that we
|
|
2050
|
+
# use R.c for nb_groups in order to convert the number of groups into
|
|
2051
|
+
# an R vector.
|
|
1918
2052
|
def initialize(nb_groups: 0, part: nil)
|
|
1919
2053
|
@nb_groups = R.c(nb_groups)
|
|
1920
2054
|
@part = part
|
|
@@ -1925,7 +2059,8 @@ class PartitionFather
|
|
|
1925
2059
|
@nb_groups * 2
|
|
1926
2060
|
end
|
|
1927
2061
|
|
|
1928
|
-
# method 'to_s' is called whenever we try to print a Ruby object.
|
|
2062
|
+
# method 'to_s' is called whenever we try to print a Ruby object.
|
|
2063
|
+
# This method emulates
|
|
1929
2064
|
# R 'print' method that prints all the slots.
|
|
1930
2065
|
def to_s
|
|
1931
2066
|
puts ("Variable 'nb_groups':")
|
|
@@ -1938,8 +2073,10 @@ class PartitionFather
|
|
|
1938
2073
|
|
|
1939
2074
|
end
|
|
1940
2075
|
|
|
1941
|
-
# Class PartitionSimple is a subclass of PartitionFather. To make a
|
|
1942
|
-
#
|
|
2076
|
+
# Class PartitionSimple is a subclass of PartitionFather. To make a
|
|
2077
|
+
# subclass of a
|
|
2078
|
+
# class we use the operator '<'. Since the whole logic is in the parent
|
|
2079
|
+
# class
|
|
1943
2080
|
# PartitionSimple is just an empty class
|
|
1944
2081
|
class PartitionSimple < PartitionFather
|
|
1945
2082
|
|
|
@@ -1953,7 +2090,9 @@ end
|
|
|
1953
2090
|
|
|
1954
2091
|
|
|
1955
2092
|
``` ruby
|
|
1956
|
-
@a = PartitionSimple.new(
|
|
2093
|
+
@a = PartitionSimple.new(
|
|
2094
|
+
nb_groups: 3,
|
|
2095
|
+
part: ((~R[:LETTERS])[R.c(1, 2, 3, 2, 2, 1)].factor))
|
|
1957
2096
|
puts @a
|
|
1958
2097
|
```
|
|
1959
2098
|
|
|
@@ -1965,7 +2104,7 @@ puts @a
|
|
|
1965
2104
|
## [1] A B C B B A
|
|
1966
2105
|
## Levels: A B C
|
|
1967
2106
|
##
|
|
1968
|
-
## #<RC::PartitionSimple:
|
|
2107
|
+
## #<RC::PartitionSimple:0x666d3927>
|
|
1969
2108
|
```
|
|
1970
2109
|
|
|
1971
2110
|
|
|
@@ -1979,7 +2118,9 @@ puts @a.nb_mult_two
|
|
|
1979
2118
|
|
|
1980
2119
|
|
|
1981
2120
|
``` ruby
|
|
1982
|
-
@b = PartitionEval.new(
|
|
2121
|
+
@b = PartitionEval.new(
|
|
2122
|
+
nb_groups: 5,
|
|
2123
|
+
part: (~R[:LETTERS])[R.c(1, 5, 3, 4, 2, 4)].ordered)
|
|
1983
2124
|
puts @b
|
|
1984
2125
|
```
|
|
1985
2126
|
|
|
@@ -1991,7 +2132,7 @@ puts @b
|
|
|
1991
2132
|
## [1] A E C D B D
|
|
1992
2133
|
## Levels: A < B < C < D < E
|
|
1993
2134
|
##
|
|
1994
|
-
## #<RC::PartitionEval:
|
|
2135
|
+
## #<RC::PartitionEval:0x22d4f3a8>
|
|
1995
2136
|
```
|
|
1996
2137
|
|
|
1997
2138
|
|
|
@@ -2033,7 +2174,7 @@ puts @a
|
|
|
2033
2174
|
## [1] A B C B B A
|
|
2034
2175
|
## Levels: A B C
|
|
2035
2176
|
##
|
|
2036
|
-
## #<RC::PartitionSimple:
|
|
2177
|
+
## #<RC::PartitionSimple:0x666d3927>
|
|
2037
2178
|
```
|
|
2038
2179
|
|
|
2039
2180
|
As can be seen, 'puts @a' now calls method 'to_s' defined in class PartitionSimple. This
|
|
@@ -2056,7 +2197,7 @@ puts @b
|
|
|
2056
2197
|
## [1] A E C D B D
|
|
2057
2198
|
## Levels: A < B < C < D < E
|
|
2058
2199
|
##
|
|
2059
|
-
## #<RC::PartitionEval:
|
|
2200
|
+
## #<RC::PartitionEval:0x22d4f3a8>
|
|
2060
2201
|
```
|
|
2061
2202
|
|
|
2062
2203
|
# Internal Modification of an Object
|