/
genericMethods.R
2047 lines (1743 loc) · 62.6 KB
/
genericMethods.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# genericMethods - S4 generics
# FLCore/R/genericMethods
# Copyright 2003-2016 FLR Team. Distributed under the GPL 2 or later
# Maintainer: Iago Mosqueira, EC JRC
globalVariables(c("qname"))
# -- OVERLOADED methods/functions {{{
setGeneric("AIC", useAsDefault = stats::AIC)
setGeneric("append", useAsDefault = append)
setGeneric("apply", useAsDefault = apply)
setGeneric("as.data.frame", useAsDefault = as.data.frame)
setGeneric("barchart", useAsDefault = lattice::barchart)
setGeneric("bwplot", useAsDefault = lattice::bwplot)
setGeneric("coef", useAsDefault = coef)
setGeneric("cor", useAsDefault = cov)
setGeneric("cov", useAsDefault = cov)
setGeneric("densityplot", useAsDefault = densityplot)
setGeneric("drop", useAsDefault = drop)
setGeneric("dotplot", useAsDefault = dotplot)
setGeneric("expand", useAsDefault=Matrix::expand)
setGeneric("head", useAsDefault = utils::head)
setGeneric("histogram", useAsDefault = histogram)
setGeneric("ifelse", useAsDefault = ifelse)
setGeneric("intersect", useAsDefault = intersect)
setGeneric("lapply", useAsDefault = lapply)
setGeneric("lm", useAsDefault = lm)
setGeneric("lowess", useAsDefault = lowess)
setGeneric("mean", useAsDefault = mean)
setGeneric("median", useAsDefault = median)
setGeneric("merge", useAsDefault = merge)
setGeneric("model.frame", useAsDefault = model.frame)
setGeneric("mvrnorm", useAsDefault = mvrnorm)
setGeneric("names")
setGeneric("names<-")
setGeneric("nls", useAsDefault = nls)
setGeneric("plot")
setGeneric("predict", useAsDefault = predict)
setGeneric("print", useAsDefault = print)
setGeneric("profile", useAsDefault = profile)
setGeneric("quantile", useAsDefault = quantile)
setGeneric('residuals', useAsDefault = stats::residuals)
setGeneric("rgamma", useAsDefault = rgamma)
setGeneric("rlnorm", useAsDefault=rlnorm)
setGeneric("rnorm", useAsDefault=rnorm)
setGeneric("rpois", useAsDefault=rpois)
setGeneric("scale", useAsDefault = scale)
setGeneric("sd", useAsDefault = sd)
setGeneric("split", useAsDefault = split)
setGeneric("splom", useAsDefault = splom)
setGeneric("stripplot", useAsDefault = stripplot)
setGeneric("subset", useAsDefault = subset)
setGeneric("summary", useAsDefault = summary)
setGeneric("sweep", useAsDefault = sweep)
setGeneric("tail", useAsDefault = utils::tail)
setGeneric("transform", useAsDefault = transform)
setGeneric("tsp", useAsDefault = tsp)
setGeneric("units", useAsDefault = units)
setGeneric("units<-", useAsDefault = `units<-`)
setGeneric("update", useAsDefault = update)
setGeneric("var", useAsDefault = var)
setGeneric("vcov", useAsDefault = vcov)
setGeneric("window", useAsDefault = window)
setGeneric("wireframe", useAsDefault = wireframe)
setGeneric("xyplot", useAsDefault = xyplot) # }}}
# -- CONSTRUCTORS, documented with each class {{{
# FLBiol
#' @rdname FLBiol
#' @aliases FLBiol FLBiol-methods
setGeneric('FLBiol', function(object, ...) standardGeneric('FLBiol'))
# FLBiols
#' @rdname FLBiols
#' @aliases FLBiols FLBiols-methods
setGeneric("FLBiols", function(object, ...) standardGeneric("FLBiols"))
# FLCohort
#' @rdname FLCohort
#' @aliases FLCohort FLCohort-methods
setGeneric("FLCohort", function(object, ...) standardGeneric("FLCohort"))
# FLCohorts
#' @rdname FLCohorts
#' @aliases FLCohorts FLCohorts-methods
setGeneric("FLCohorts", function(object, ...) standardGeneric("FLCohorts"))
# FLIndex
#' @rdname FLIndex
#' @aliases FLIndex FLIndex-methods
setGeneric('FLIndex', function(object, ...) standardGeneric('FLIndex'))
# FLIndexBiomass
#' @rdname FLIndexBiomass
#' @aliases FLIndexBiomass FLIndexBiomass-methods
setGeneric('FLIndexBiomass', function(object, ...)
standardGeneric('FLIndexBiomass'))
# FLIndices
#' @rdname FLIndices
#' @aliases FLIndices FLIndices-methods
setGeneric("FLIndices", function(object, ...) standardGeneric("FLIndices"))
# FLlst
#' @rdname FLlst
#' @aliases FLlst FLlst-methods
setGeneric("FLlst", function(object, ...) standardGeneric("FLlst"))
# FLModel
#' @rdname FLModel
#' @aliases FLModel FLModel-methods
setGeneric('FLModel', function(model, ...) standardGeneric('FLModel'))
# FLModelSim
#' @rdname FLModelSim
#' @aliases FLModelSim FLModelSim-methods
setGeneric("FLModelSim", function(object, ...)
standardGeneric("FLModelSim"))
# FLPar
#' @rdname FLPar
#' @aliases FLPar FLPar-methods
setGeneric("FLPar", function(object, ...) standardGeneric("FLPar"))
# FLPars
#' @rdname FLPars
#' @aliases FLPars FLPars-methods
setGeneric("FLPars", function(object, ...) standardGeneric("FLPars"))
# FLQuant
#' @rdname FLQuant
#' @aliases FLQuant FLQuant-methods
setGeneric("FLQuant", function(object, ...) standardGeneric("FLQuant"))
# FLQuant
#' @rdname FLQuants
#' @aliases FLQuants FLQuants-methods
setGeneric("FLQuants", function(object, ...) standardGeneric("FLQuants"))
# FLQuantDistr
#' @rdname FLQuantDistr
#' @aliases FLQuantDistr FLQuantDistr-methods
setGeneric("FLQuantDistr", function(object, var, ...)
standardGeneric("FLQuantDistr"))
# FLQuantPoint
#' @rdname FLQuantPoint
#' @aliases FLQuantPoint FLQuantPoint-methods
setGeneric("FLQuantPoint", function(object, ...)
standardGeneric("FLQuantPoint"))
# FLSR
#' @rdname FLSR
#' @aliases FLSR FLSR-methods
setGeneric("FLSR", function(model, ...) standardGeneric("FLSR"))
# FLSRs
#' @rdname FLSRs
#' @aliases FLSRs FLSRs-methods
setGeneric("FLSRs", function(object, ...) standardGeneric("FLSRs"))
# FLStock
#' @rdname FLStock
#' @aliases FLStock FLStock-methods
setGeneric('FLStock', function(object, ...) standardGeneric('FLStock'))
# FLStockLen
#' @rdname FLStockLen
#' @aliases FLStockLen FLStockLen-methods
setGeneric('FLStockLen', function(object, ...) standardGeneric('FLStockLen'))
# FLStocks
#' @rdname FLStocks
#' @aliases FLStocks FLStocks-methods
setGeneric("FLStocks", function(object, ...) standardGeneric("FLStocks"))
# }}}
# -- ACCESSORS {{{
#' accessor and replacement methods for FLCore classes
#'
#' All S4 classes defined in FLCore have methods for accessing and replacing any
#' of their slots. These methods are named as the slot, and will return the
#' content of the slot, for the accessor method, or modify it with the provided
#' value.
#'
#' Accessors and replacement methods, with some exception, are created at build
#' time by calls to the \code{createFLAccessors} function. An accessor method is
#' created for each slot, with simply calls \code{slot()} on the relevant slot
#' name. For slots of class \code{\link{FLQuant}}, or \code{FLArray}-based, two
#' methods are created: one if \code{value} is of class \code{FLQuant}, and
#' another for \code{value} being a numeric vector. The later would insert the
#' vector into the slot structure, using R's recycling rules.
#'
#' Users are encouraged to use the accessor methods, rather than the '@' operator
#' or the \code{slot()} method, to isolate code from the internal structure of
#' the class. If a slot was to be altered or deleted in the future, a method
#' would be provided to return the same value, computed from other slots.
#'
#' Some of these methods might already not access directly an slot, and instead
#' carry out a calculation to return the requested value, depending on the class
#' being called with. Please refer to the particular method implementation to
#' see if this is the case.
#'
#' Accessor methods for slots of class \code{\link{predictModel}} behave
#' differently depending on the \code{compute} argument. Please refer to the
#' relevant help page for further clarification.
#'
#' @param object The object from which a slot is to be extracted or replaced
#' @param value Object to be inserted into the relevant slot
#'
#' @return The required slot, for an accessor method, or invisible modifies the
#' object, for the replacement one.
#'
#' @name accessors
#' @rdname accessors
#'
#' @author The FLR Team
#' @seealso \code{\link{FLQuant}}, \code{\link{FLStock}}, \code{\link{FLIndex}},
#' \code{\link{FLBiol}}, \code{\link{predictModel}}
#' @keywords methods
#' @examples
#'
#' data(ple4)
#'
#' # To access the catch slot in an FLStock, use
#' catch(ple4)
#'
#' # while to modify it, do
#' catch(ple4) <- catch(ple4) * 2
#'
#' # A number can be used as input, to be recycled
#' m(ple4) <- 0.3
#' # same as a longer vector, by age
#' m(ple4) <- 0.4^(seq(1, 2, length=10))
#'
#' # To see the methods defined by createFLAccessors, run, for example
#' getMethod('catch', 'FLS')
#'
NULL
# name, name<-
#' @rdname accessors
#' @aliases name, name<- name, name<-<-
setGeneric('name', function(object, ...) standardGeneric('name'))
setGeneric('name<-', function(object, ..., value) standardGeneric('name<-'))
# desc
#' @rdname accessors
#' @aliases desc desc<-
setGeneric('desc', function(object, ...) standardGeneric('desc'))
setGeneric('desc<-', function(object, ..., value) standardGeneric('desc<-'))
# range<-
#' @rdname accessors
#' @aliases range<-
setGeneric("range<-", function(x, i, value) standardGeneric("range<-"))
# catch
#' @rdname accessors
#' @aliases catch catch<-
setGeneric('catch', function(object, ...) standardGeneric('catch'))
setGeneric('catch<-', function(object, ..., value) standardGeneric('catch<-'))
# catch.n
setGeneric('catch.n', function(object, ...) standardGeneric('catch.n'))
#' @rdname accessors
#' @aliases catch.n<-
setGeneric('catch.n<-', function(object, ..., value) standardGeneric('catch.n<-'))
# catch.wt
#' @rdname accessors
#' @aliases catch.wt catch.wt<-
setGeneric('catch.wt', function(object, ...) standardGeneric('catch.wt'))
setGeneric('catch.wt<-', function(object, ..., value) standardGeneric('catch.wt<-'))
# discards
#' @rdname accessors
#' @aliases discards discards<-
setGeneric('discards', function(object, ...) standardGeneric('discards'))
setGeneric('discards<-', function(object, ..., value) standardGeneric('discards<-'))
# discards.n
#' @rdname accessors
#' @aliases discards.n discards.n<-
setGeneric('discards.n', function(object, ...) standardGeneric('discards.n'))
setGeneric('discards.n<-', function(object, ..., value) standardGeneric('discards.n<-'))
# discards.wt
#' @rdname accessors
#' @aliases discards.wt discards.wt<-
setGeneric('discards.wt', function(object, ...) standardGeneric('discards.wt'))
setGeneric('discards.wt<-', function(object, ..., value) standardGeneric('discards.wt<-'))
# landings
#' @rdname accessors
#' @aliases landings landings<-
setGeneric('landings', function(object, ...) standardGeneric('landings'))
setGeneric('landings<-', function(object, ..., value) standardGeneric('landings<-'))
# landings.n
#' @rdname accessors
#' @aliases landings.n landings.n<-
setGeneric('landings.n', function(object, ...) standardGeneric('landings.n'))
setGeneric('landings.n<-', function(object, ..., value) standardGeneric('landings.n<-'))
# landings.wt
#' @rdname accessors
#' @aliases landings.wt landings.wt<-
setGeneric('landings.wt', function(object, ...) standardGeneric('landings.wt'))
setGeneric('landings.wt<-', function(object, ..., value) standardGeneric('landings.wt<-'))
# m
#' @rdname accessors
#' @aliases m m<-
setGeneric('m', function(object, ...) standardGeneric('m'))
setGeneric('m<-', function(object, ..., value) standardGeneric('m<-'))
# stock
#' @rdname accessors
#' @aliases stock stock<-
setGeneric('stock', function(object, ...) standardGeneric('stock'))
setGeneric('stock<-', function(object, ..., value) standardGeneric('stock<-'))
# stock.n
#' @rdname accessors
#' @aliases stock.n stock.n<-
setGeneric('stock.n', function(object, ...) standardGeneric('stock.n'))
setGeneric('stock.n<-', function(object, ..., value) standardGeneric('stock.n<-'))
# stock.wt
#' @rdname accessors
#' @aliases stock.wt stock.wt<-
setGeneric('stock.wt', function(object, ...) standardGeneric('stock.wt'))
setGeneric('stock.wt<-', function(object, ..., value) standardGeneric('stock.wt<-'))
# m.spwn
#' @rdname accessors
#' @aliases m.spwn m.spwn<-
setGeneric('m.spwn', function(object, ...) standardGeneric('m.spwn'))
setGeneric('m.spwn<-', function(object, ..., value) standardGeneric('m.spwn<-'))
# harvest
#' @rdname accessors
#' @aliases harvest harvest<-
setGeneric('harvest', function(object, catch, ...) standardGeneric('harvest'))
setGeneric('harvest<-', function(object, ..., value) standardGeneric('harvest<-'))
# harvest.spwn
#' @rdname accessors
#' @aliases harvest.spwn harvest.spwn<-
setGeneric('harvest.spwn', function(object, ...) standardGeneric('harvest.spwn'))
setGeneric('harvest.spwn<-', function(object, ..., value) standardGeneric('harvest.spwn<-'))
# mat
#' @rdname accessors
#' @aliases mat mat<-
setGeneric('mat', function(object, ...) standardGeneric('mat'))
setGeneric('mat<-', function(object, ..., value) standardGeneric('mat<-'))
# n
#' @rdname accessors
#' @aliases n n<-
setGeneric('n', function(object, ...) standardGeneric('n'))
setGeneric('n<-', function(object, ..., value) standardGeneric('n<-'))
# m
#' @rdname accessors
#' @aliases m m<-
setGeneric('m', function(object, ...) standardGeneric('m'))
setGeneric('m<-', function(object, ..., value) standardGeneric('m<-'))
# wt
#' @rdname accessors
#' @aliases wt wt<-
setGeneric('wt', function(object, ...) standardGeneric('wt'))
setGeneric('wt<-', function(object, ..., value) standardGeneric('wt<-'))
# fec
#' @rdname accessors
#' @aliases fec fec<-
setGeneric('fec', function(object, ...) standardGeneric('fec'))
setGeneric('fec<-', function(object, ..., value) standardGeneric('fec<-'))
# spwn
#' @rdname accessors
#' @aliases spwn spwn<-
setGeneric('spwn', function(object, ...) standardGeneric('spwn'))
setGeneric('spwn<-', function(object, ..., value) standardGeneric('spwn<-'))
# effort
#' @rdname accessors
#' @aliases effort effort<-
setGeneric("effort", function(object, metier, ...) standardGeneric("effort"))
setGeneric("effort<-", function(object, ..., value) standardGeneric("effort<-"))
# type
#' @rdname accessors
#' @aliases type type<-
setGeneric('type', function(object, ...) standardGeneric('type'))
setGeneric('type<-', function(object, ..., value) standardGeneric('type<-'))
# distr
#' @rdname accessors
#' @aliases distr distr<-
setGeneric('distr', function(object, ...) standardGeneric('distr'))
setGeneric('distr<-', function(object, ..., value) standardGeneric('distr<-'))
# distribution
#' @rdname accessors
#' @aliases distribution distribution<-
setGeneric('distribution', function(object, ...)
standardGeneric('distribution'))
setGeneric('distribution<-', function(object, ..., value)
standardGeneric('distribution<-'))
# index
#' @rdname accessors
#' @aliases index index<-
setGeneric('index', function(object, ...)
standardGeneric('index'))
setGeneric('index<-', function(object, ..., value)
standardGeneric('index<-'))
# index.var
#' @rdname accessors
#' @aliases index.var index.var<-
setGeneric('index.var', function(object, ...)
standardGeneric('index.var'))
setGeneric('index.var<-', function(object, ..., value)
standardGeneric('index.var<-'))
# catch.n
#' @rdname accessors
#' @aliases catch.n catch.n<-
setGeneric('catch.n', function(object, ...)
standardGeneric('catch.n'))
setGeneric('catch.n<-', function(object, ..., value)
standardGeneric('catch.n<-'))
# catch.wt
#' @rdname accessors
#' @aliases catch.wt catch.wt<-
setGeneric('catch.wt', function(object, ...)
standardGeneric('catch.wt'))
setGeneric('catch.wt<-', function(object, ..., value)
standardGeneric('catch.wt<-'))
# sel.pattern
#' @rdname accessors
#' @aliases sel.pattern sel.pattern<-
setGeneric('sel.pattern', function(object, ...)
standardGeneric('sel.pattern'))
setGeneric('sel.pattern<-', function(object, ..., value)
standardGeneric('sel.pattern<-'))
# index.q
#' @rdname accessors
#' @aliases index.q index.q<-
setGeneric('index.q', function(object, ...)
standardGeneric('index.q'))
setGeneric('index.q<-', function(object, ..., value)
standardGeneric('index.q<-'))
# model
#' @rdname accessors
#' @aliases model model<-
setGeneric('model', function(object, ...)
standardGeneric('model'))
setGeneric('model<-', function(object, ..., value)
standardGeneric('model<-'))
# logl
#' @rdname accessors
#' @aliases logl logl<-
setGeneric('logl', function(object, ...)
standardGeneric('logl'))
setGeneric('logl<-', function(object, ..., value)
standardGeneric('logl<-'))
# gr
#' @rdname accessors
#' @aliases gr gr<-
setGeneric('gr', function(object, ...)
standardGeneric('gr'))
setGeneric('gr<-', function(object, ..., value)
standardGeneric('gr<-'))
# initial
#' @rdname accessors
#' @aliases initial initial<-
setGeneric('initial', function(object, ...)
standardGeneric('initial'))
setGeneric('initial<-', function(object, ..., value)
standardGeneric('initial<-'))
# logLik
#' @rdname accessors
#' @aliases logLik logLik<-
setGeneric('logLik', function(object, ...)
standardGeneric('logLik'))
setGeneric('logLik<-', function(object, ..., value)
standardGeneric('logLik<-'))
# vcov
#' @rdname accessors
#' @aliases vcov vcov<-
setGeneric('vcov<-', function(object, ..., value)
standardGeneric('vcov<-'))
# hessian
#' @rdname accessors
#' @aliases hessian hessian<-
setGeneric('hessian', function(object, ...)
standardGeneric('hessian'))
setGeneric('hessian<-', function(object, ..., value)
standardGeneric('hessian<-'))
# logerror
#' @rdname accessors
#' @aliases logerror logerror<-
setGeneric('logerror', function(object, ...)
standardGeneric('logerror'))
setGeneric('logerror<-', function(object, ..., value)
standardGeneric('logerror<-'))
# details
#' @rdname accessors
#' @aliases details details<-
setGeneric('details', function(object, ...)
standardGeneric('details'))
setGeneric('details<-', function(object, ..., value)
standardGeneric('details<-'))
# residuals
#' @rdname accessors
#' @aliases residuals<-
setGeneric('residuals<-', function(object, ..., value)
standardGeneric('residuals<-'))
# fitted
#' @rdname accessors
#' @aliases fitted fitted<-
setGeneric('fitted', function(object, ...)
standardGeneric('fitted'))
setGeneric('fitted<-', function(object, ..., value)
standardGeneric('fitted<-'))
# rec
#' @rdname accessors
#' @aliases rec rec<-
setGeneric('rec', function(object, ...)
standardGeneric('rec'))
setGeneric('rec<-', function(object, ..., value)
standardGeneric('rec<-'))
# rec.obs
#' @rdname accessors
#' @aliases rec.obs rec.obs<-
setGeneric('rec.obs', function(object, ...)
standardGeneric('rec.obs'))
# catch.q
#' @rdname accessors
#' @aliases catch.q catch.q<-
setGeneric('catch.q', function(object, ...)
standardGeneric('catch.q'))
setGeneric('catch.q<-', function(object, ..., value)
standardGeneric('catch.q<-'))
# discards.sel
#' @rdname accessors
#' @aliases discards.sel discards.sel<-
setGeneric('discards.sel', function(object, ...)
standardGeneric('discards.sel'))
setGeneric('discards.sel<-', function(object, ..., value)
standardGeneric('discards.sel<-'))
# landings.sel
#' @rdname accessors
#' @aliases landings.sel landings.sel<-
setGeneric('landings.sel', function(object, ...)
standardGeneric('landings.sel'))
setGeneric('landings.sel<-', function(object, ..., value)
standardGeneric('landings.sel<-'))
# params, params<-
#' @rdname accessors
#' @aliases params, params<- params, params<-<-
setGeneric("params", function(object, ...)
standardGeneric("params"))
setGeneric("params<-", function(object, value)
standardGeneric("params<-"))
# }}}
# -- METHODS
# quant, quant<- {{{
#' Method quant
#'
#' Function to get or set the name of the first dimension (quant) in an object
#' of any FLArray-based class, like \code{\link{FLQuant}} or \code{\link{FLCohort}}.
#'
#' @name quant
#' @rdname quant
#' @aliases quant quant-methods
#' @docType methods
#' @section Generic function: quant(object) quant<-(object,value)
#' @author The FLR Team
#' @seealso \linkS4class{FLQuant}, \linkS4class{FLCohort}
#' @keywords methods
#' @examples
#'
#' # quant is 'quant' by default
#' quant(FLQuant())
#'
#' flq <- FLQuant(rnorm(80), dim=c(4,20), quant='age')
#' quant(flq)
#' quant(flq) <- 'length'
#' summary(flq)
#'
setGeneric("quant", function(object, ...)
standardGeneric("quant"))
setGeneric("quant<-", function(object, value)
standardGeneric("quant<-")) # }}}
# iter, iter<- {{{
#' Methods iter
#'
#' Select or modify iterations of an FLR object
#'
#' To extract or modify a subset of the iterations contained in an FLR object,
#' the \code{iter} and \code{iter<-} methods can be used.
#'
#' In complex objects with various \code{FLQuant} slots, the \code{iter} method
#' checks whether individual slots contain more than one iteration, i.e.
#' \code{dims(object)[6] > 1}. If a particular slot contains a single
#' iteration, that is returned, otherwise the chosen iteration is selected.
#' This is in contrast with the subset operator \code{[}, which does not carry
#' out this check.
#'
#' For objects of class \code{\link{FLModel}}, iters are extracted for slots of
#' classes \code{FLQuant}, \code{FLCohort} and \code{FLPar}.
#'
#' @name iter
#' @aliases iter iter-methods
#' @docType methods
#' @section Generic function: iter(object) iter<-(object,value)
#' @author The FLR Team
#' @seealso \linkS4class{FLComp}, \linkS4class{FLQuant}
#' @keywords methods
#setGeneric("iter", function(obj, ...)
# standardGeneric("iter"))
setGeneric("iter", useAsDefault = iterators::iter)
setGeneric("iter<-", function(object, ..., value)
standardGeneric("iter<-")) # }}}
# lower & upper {{{
#' Extract and modify the *lower* and *upper* FLModel attibutes.
#'
#' Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
#'
#' Details: Aliquam sagittis feugiat felis eget consequat.
#'
#' @param object Object to extract from or modify
#' @param value New value
#' @param ... Other arguments
#'
#' @return RETURN Lorem ipsum dolor sit amet
#'
#' @name upperlower
#' @rdname upperlower-methods
#' @aliases upper upper-methods upper<- upper<--methods
#' @aliases lower lower-methods lower<- lower<--methods
#'
#' @author The FLR Team
#' @seealso [`FLModel`]
#' @keywords methods
#' @md
setGeneric("lower", function(object, ...)
standardGeneric("lower"))
setGeneric("lower<-", function(object, ..., value)
standardGeneric("lower<-"))
setGeneric("upper", function(object, ...)
standardGeneric("upper"))
setGeneric("upper<-", function(object, ..., value)
standardGeneric("upper<-"))
# }}}
# ssb {{{
#' Calculate or return the Spawning Stock Biomass
#'
#' The calculated Spawning Stock Biomass (SSB) of a fish population is returned
#' by this method. SSB is the combined weight of all individuals in a fish stock
#' that are capable of reproducing. In some classes this is calculated from
#' information stored in different slots, while in others \code{ssb()} is simply
#' an slot accessor. When the later is the case, the corresponding replacement
#' method also exists.
#'
#' @param object Object on which \code{ssb} is calculated or extracted.
#'
#' @return An object, generally of class \code{\link{FLQuant}}.
#'
#' @name ssb
#' @rdname ssb
#' @aliases ssb ssb-methods
#'
#' @author The FLR Team
#' @seealso \link{FLComp}
#' @keywords methods
#' @examples
#' data(ple4)
setGeneric('ssb', function(object, ...)
standardGeneric('ssb'))
setGeneric('ssb<-', function(object, ..., value)
standardGeneric('ssb<-')) # }}}
setGeneric('ssf', function(object, ...)
standardGeneric('ssf')) # }}}
# dims {{{
#' Method dims
#'
#' List with information on object dimensions
#'
#' Method \code{dims} returns a named list with information on the dimensions
#' and dimension names of a given object. The list returned could be
#' extended in the future and currently contains, depending on the class of the
#' object, some of the following:
#' \describe{
#' \item{quant}{Length of the first dimension}
#' \item{min}{First quant}
#' \item{max}{Last quant}
#' \item{year}{Number of years}
#' \item{minyear}{First year in series}
#' \item{maxyear}{Last year in series}
#' \item{cohort}{Number of cohorts}
#' \item{mincohort}{First cohort in series}
#' \item{maxcohort}{Last cohort in series}
#' \item{unit}{Length of the third (\code{unit}) dimension}
#' \item{season}{Length of the fourth (\code{season}) dimension}
#' \item{area}{Length of the fifth (\code{area}) dimension}
#' \item{iter}{Length of the sixth (\code{iter}) dimension} }
#' Values in the returned list are of class \code{numeric}, unless dimnames are
#' strings with no numeric translation, in which case the result is \code{NA}.
#'
#' Please note that the name of the first element in the returned list changes
#' with the name of the first dimension in the input object. Use
#' \code{\link{quant}} to obtain the name and extract the relevant element from
#' the result list.
#'
#' @name dims
#' @aliases dims dims-methods
#' @docType methods
#' @section Generic function: dims(obj)
#' @author The FLR Team
#' @seealso \code{\link[base]{dimnames}}, \code{\link{FLQuant}}
#' @keywords methods
setGeneric("dims", function(obj, ...) standardGeneric("dims")) # }}}
# compute {{{
#' Methods to compute quantities
#'
#' Methods to compute total quant-aggregated catch, landings, discards and
#' stock biomass from age or length-structured numbers and mean weights.
#'
#' These methods compute the total catch, landings, discards and stock biomass
#' from the quant-structured values in numbers and weight per individual. The
#' calculation for landings, discards and stock involves the product of the
#' landings/discards/stock in numbers (\code{landings.n}, \code{discards.n} or
#' \code{stock.n}) by the individual weight-at-quant (\code{landings.wt},
#' \code{discards.wt} or \code{stock.wt}), as in
#'
#' \deqn{L=L_n * L_{wt}}{landings = landings.n * landings.wt}
#'
#' By selecting \code{slot="catch"}, \code{computeCatch} can calculate in the
#' same way the total catch from the catch-at-quant and weight in the catch.
#' Those two values (in slots \code{catch.n} and \code{catch.wt}) can also be
#' calculated (from landings and discards) by specifying \code{slot="n"} and
#' \code{slot="wt"} respectively. Calling \code{computeCatch} with option
#' \code{slot="all"} will carry out the three calculations. In this case, the
#' returned object will be of class \code{\link{FLQuants}}, with element names
#' \code{catch}, \code{catch.n} and \code{catch.wt}, which can then be passed
#' directly to the \code{\link{catch<-}} replacement method.
#'
#' @name compute
#' @docType methods
#' @section Generic function:
#' computeCatch(object, ...)
#'
#' computeLandings(object, ...)
#'
#' computeDiscards(object, ...)
#'
#' computeStock(object, ...)
#'
#' @author The FLR Team
#' @seealso \link{FLComp}
#' @keywords methods
#' @examples
#'
#' data(ple4)
#' summary(computeLandings(ple4))
#' summary(computeCatch(ple4, slot="all"))
#' stock(ple4) <- computeStock(ple4)
#' landings(ple4) <- computeLandings(ple4)
#' catch.n(ple4) <- computeCatch(ple4, slot="n")
#' catch(ple4) <- computeCatch(ple4, slot="all")
#'
#' @rdname compute
#' @aliases computeLandings computeLandings-methods
setGeneric("computeLandings", function(object, ...)
standardGeneric("computeLandings"))
#' @rdname compute
#' @aliases computeDiscards computeDiscards-methods
setGeneric("computeDiscards", function(object, ...)
standardGeneric("computeDiscards"))
#' @rdname compute
#' @aliases computeLandings computeCatch-methods
setGeneric("computeCatch", function(object, ...)
standardGeneric("computeCatch"))
#' @rdname compute
#' @aliases computeStock computeStock-methods
setGeneric("computeStock", function(object, ...)
standardGeneric("computeStock"))
#' @rdname compute
#' @aliases computeHarvest computeHarvest-methods
setGeneric("computeHarvest", function(object, catch, ...)
standardGeneric("computeHarvest"))
# }}}
# tsb
setGeneric("tsb", function(object, ...)
standardGeneric("tsb"))
# tep
setGeneric("tep", function(object, ...)
standardGeneric("tep"))
# tb
setGeneric("tb", function(object, ...)
standardGeneric("tb"))
# fbar
setGeneric("fbar", function(object, ...)
standardGeneric("fbar"))
# ssbpurec
setGeneric("ssbpurec", function(object, ...)
standardGeneric("ssbpurec"))
# meanLifespan
setGeneric("meanLifespan", function(x, ...)
standardGeneric("meanLifespan"))
# dims {{{
#' Method dims
#'
#' List with information on object dimensions
#'
#' Method \code{dims} returns a named list with information on the dimensions
#' and dimension names of a given object. The list returned could be
#' extended in the future and currently contains, depending on the class of the
#' object, some of the following:
#' \describe{
#' \item{quant}{Length of the first dimension}
#' \item{min}{First quant}
#' \item{max}{Last quant}
#' \item{year}{Number of years}
#' \item{minyear}{First year in series}
#' \item{maxyear}{Last year in series}
#' \item{cohort}{Number of cohorts}
#' \item{mincohort}{First cohort in series}
#' \item{maxcohort}{Last cohort in series}
#' \item{unit}{Length of the third (\code{unit}) dimension}
#' \item{season}{Length of the fourth (\code{season}) dimension}
#' \item{area}{Length of the fifth (\code{area}) dimension}
#' \item{iter}{Length of the sixth (\code{iter}) dimension} }
#' Values in the returned list are of class \code{numeric}, unless dimnames are
#' strings with no numeric translation, in which case the result is \code{NA}.
#'
#' Please note that the name of the first element in the returned list changes
#' with the name of the first dimension in the input object. Use
#' \code{\link{quant}} to obtain the name and extract the relevant element from
#' the result list.
#'
#' @name dims
#' @aliases dims dims-methods
#' @docType methods
#' @section Generic function: dims(obj)
#' @author The FLR Team
#' @seealso \code{\link[base]{dimnames}}, \code{\link{FLQuant}}
#' @keywords methods
setGeneric("dims", function(obj, ...) standardGeneric("dims")) # }}}
# compute {{{
#' Methods to compute quantities
#'
#' Methods to compute total quant-aggregated catch, landings, discards and
#' stock biomass from age or length-structured numbers and mean weights.
#'
#' These methods compute the total catch, landings, discards and stock biomass
#' from the quant-structured values in numbers and weight per individual. The
#' calculation for landings, discards and stock involves the product of the
#' landings/discards/stock in numbers (\code{landings.n}, \code{discards.n} or
#' \code{stock.n}) by the individual weight-at-quant (\code{landings.wt},
#' \code{discards.wt} or \code{stock.wt}), as in
#'
#' \deqn{L=L_n * L_{wt}}{landings = landings.n * landings.wt}
#'
#' By selecting \code{slot="catch"}, \code{computeCatch} can calculate in the
#' same way the total catch from the catch-at-quant and weight in the catch.
#' Those two values (in slots \code{catch.n} and \code{catch.wt}) can also be
#' calculated (from landings and discards) by specifying \code{slot="n"} and
#' \code{slot="wt"} respectively. Calling \code{computeCatch} with option
#' \code{slot="all"} will carry out the three calculations. In this case, the
#' returned object will be of class \code{\link{FLQuants}}, with element names
#' \code{catch}, \code{catch.n} and \code{catch.wt}, which can then be passed
#' directly to the \code{\link{catch<-}} replacement method.
#'
#' @name compute
#' @docType methods
#' @section Generic function:
#' computeCatch(object, ...)
#'
#' computeLandings(object, ...)
#'
#' computeDiscards(object, ...)
#'
#' computeStock(object, ...)
#'
#' @author The FLR Team
#' @seealso \link{FLComp}
#' @keywords methods
#' @examples
#'
#' data(ple4)
#' summary(computeLandings(ple4))
#' summary(computeCatch(ple4, slot="all"))
#' stock(ple4) <- computeStock(ple4)
#' landings(ple4) <- computeLandings(ple4)
#' catch.n(ple4) <- computeCatch(ple4, slot="n")
#' catch(ple4) <- computeCatch(ple4, slot="all")
#'
#' @rdname compute
#' @aliases computeLandings computeLandings-methods
setGeneric("computeLandings", function(object, ...)
standardGeneric("computeLandings"))
#' @rdname compute
#' @aliases computeDiscards computeDiscards-methods
setGeneric("computeDiscards", function(object, ...)
standardGeneric("computeDiscards"))
#' @rdname compute
#' @aliases computeLandings computeCatch-methods
setGeneric("computeCatch", function(object, ...)
standardGeneric("computeCatch"))
#' @rdname compute
#' @aliases computeStock computeStock-methods
setGeneric("computeStock", function(object, ...)
standardGeneric("computeStock"))
# }}}
# tsb
setGeneric("tsb", function(object, ...)
standardGeneric("tsb"))
# fbar
setGeneric("fbar", function(object, ...)
standardGeneric("fbar"))