-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRLum.Analysis-class.R
822 lines (724 loc) · 27.7 KB
/
RLum.Analysis-class.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
#' @include get_RLum.R set_RLum.R length_RLum.R structure_RLum.R names_RLum.R smooth_RLum.R melt_RLum.R view.R
NULL
#' Class `"RLum.Analysis"`
#'
#' Object class to represent analysis data for protocol analysis, i.e. all curves,
#' spectra etc. from one measurements. Objects from this class are produced,
#' by e.g. [read_XSYG2R], [read_Daybreak2R]
#'
#'
#' @name RLum.Analysis-class
#'
#' @docType class
#'
#' @slot protocol
#' Object of class [character] describing the applied measurement protocol
#'
#' @slot records
#' Object of class [list] containing objects of class [RLum.Data-class]
#'
#' @note
#' The method [structure_RLum] is currently just available for objects
#' containing [RLum.Data.Curve-class].
#'
#' @section Objects from the Class:
#' Objects can be created by calls of the form `set_RLum("RLum.Analysis", ...)`.
#'
#' @section Class version: 0.4.18
#'
#' @author
#' Sebastian Kreutzer, Institute of Geography, Heidelberg University (Germany)
#'
#' @seealso [Risoe.BINfileData2RLum.Analysis],
#' [Risoe.BINfileData-class], [RLum-class]
#'
#' @keywords classes methods
#'
#' @examples
#'
#' showClass("RLum.Analysis")
#'
#' ##set empty object
#' set_RLum(class = "RLum.Analysis")
#'
#' ###use example data
#' ##load data
#' data(ExampleData.RLum.Analysis, envir = environment())
#'
#' ##show curves in object
#' get_RLum(IRSAR.RF.Data)
#'
#' ##show only the first object, but by keeping the object
#' get_RLum(IRSAR.RF.Data, record.id = 1, drop = FALSE)
#'
#' @keywords internal
#'
#' @md
#' @export
setClass("RLum.Analysis",
slots = list(
protocol = "character",
records = "list"
),
contains = "RLum",
prototype = list (
protocol = NA_character_,
records = list()
)
)
# as() -----------------------------------------------------------------------------------------
##LIST
##COERCE RLum.Analyse >> list AND list >> RLum.Analysis
#' as() - RLum-object coercion
#'
#' for `[RLum.Analysis-class]`
#'
#' **[RLum.Analysis-class]**
#'
#' \tabular{ll}{
#' **from** \tab **to**\cr
#' `list` \tab `list`\cr
#' }
#'
#' Given that the [list] consists of [RLum.Analysis-class] objects.
#'
#' @md
#' @name as
setAs("list", "RLum.Analysis",
function(from,to){
new(to,
protocol = NA_character_,
records = from)
})
setAs("RLum.Analysis", "list",
function(from){
lapply(from@records, function(x) x)
})
# show() --------------------------------------------------------------------------------------
#' @describeIn RLum.Analysis
#' Show structure of `RLum.Analysis` object
#'
#' @md
#' @export
setMethod("show",
signature(object = "RLum.Analysis"),
function(object){
##print
cat("\n [RLum.Analysis-class]")
## show originator, for compatibility reasons with old example data
if(.hasSlot(object, "originator")){cat("\n\t originator:", paste0(object@originator,"()"))}
cat("\n\t protocol:", object@protocol)
cat("\n\t additional info elements: ", if(.hasSlot(object, "info")){length(object@info)}else{0})
cat("\n\t number of records:", length(object@records))
#skip this part if nothing is included in the object
if(length(object@records) > 0){
##get object class types
temp <- vapply(object@records, function(x){
class(x)[1]
}, FUN.VALUE = vector(mode = "character", length = 1))
##print object class types
lapply(1:length(table(temp)), function(x){
##show RLum class type
cat("\n\t .. :", names(table(temp)[x]),":",table(temp)[x])
##show structure
##set width option ... just an implementation for the tutorial output
if(getOption("width")<=50) temp.width <- 4 else temp.width <- 7
##set line break variable
linebreak <- FALSE
env <- environment()
##create terminal output
terminal_output <-
vapply(1:length(object@records), function(i) {
if (names(table(temp)[x]) == is(object@records[[i]])[1]) {
if (i %% temp.width == 0 & i != length(object@records)) {
assign(x = "linebreak", value = TRUE, envir = env)
}
##FIRST
first <- paste0("#", i, " ", object@records[[i]]@recordType)
##LAST
if (i < length(object@records) &&
!is.null(object@records[[i]]@info[["parentID"]]) &&
!is.null(object@records[[i + 1]]@info[["parentID"]]) &&
(object@records[[i]]@info[["parentID"]] ==
object@records[[i+1]]@info[["parentID"]])) {
last <- " <> "
}else {
last <- " | "
if (i == length(object@records)) {
last <- ""
} else if (linebreak) {
last <- "\n\t .. .. : "
assign(x = "linebreak", value = FALSE, envir = env)
}
}
return(paste0(first,last))
}else{
return("")
}
}, FUN.VALUE = vector(mode = "character", length = 1))
##print on screen, differentiate between records with many
##curves or just one
if(any(grepl(terminal_output, pattern = "<>", fixed = TRUE))){
cat("\n\t .. .. : ",
gsub(pattern = "|", replacement = "\n\t .. .. :",
x = terminal_output, fixed = TRUE), sep = "")
} else{
cat("\n\t .. .. : ", terminal_output, sep = "")
}
})
}else{
cat("\n\t >> This is an empty object, which cannot be used for further analysis! <<")
}
cat("\n")
}
)##end show method
# set_RLum() ----------------------------------------------------------------------------------
#' @describeIn RLum.Analysis
#' Construction method for [RLum.Analysis-class] objects.
#'
#' @param class [`set_RLum`] [character] (**required**):
#' name of the `RLum` class to be created
#'
#' @param originator [`set_RLum`] [character] (*automatic*):
#' contains the name of the calling function (the function that produces this object);
#' can be set manually.
#'
#' @param .uid [`set_RLum`] [character] (*automatic*):
#' sets an unique ID for this object using the internal C++ function `create_UID`.
#'
#' @param .pid [`set_RLum`] [character] (*with default*):
#' option to provide a parent id for nesting at will.
#'
#' @param protocol [`set_RLum`] [character] (*optional*):
#' sets protocol type for analysis object. Value may be used by subsequent analysis functions.
#'
#' @param records [`set_RLum`] [list] (**required**):
#' list of [RLum.Analysis-class] objects
#'
#' @param info [`set_RLum`] [list] (*optional*):
#' a list containing additional info data for the object
#'
#' **`set_RLum`**:
#'
#' Returns an [RLum.Analysis-class] object.
#'
#' @md
#' @export
setMethod(
"set_RLum",
signature = "RLum.Analysis",
definition = function(
class,
originator,
.uid,
.pid,
protocol = NA_character_,
records = list(),
info = list()) {
##produce empty class object
newRLumAnalysis <- new(Class = "RLum.Analysis")
##allow self set to reset an RLum.Analysis object
if(inherits(records, "RLum.Analysis")){
#fill slots (this is much faster than the old code!)
newRLumAnalysis@protocol <- if(missing(protocol)) records@protocol else protocol
newRLumAnalysis@originator <- originator
newRLumAnalysis@records <- records@records
newRLumAnalysis@info <- if(missing(info)) records@info else c(records@info, info)
newRLumAnalysis@.uid <- .uid
newRLumAnalysis@.pid <- if(missing(.pid)) records@.uid else .pid
}else{
#fill slots (this is much faster than the old code!)
newRLumAnalysis@protocol <- protocol
newRLumAnalysis@originator <- originator
newRLumAnalysis@records <- records
newRLumAnalysis@info <- info
newRLumAnalysis@.uid <- .uid
newRLumAnalysis@.pid <- .pid
}
return(newRLumAnalysis)
}
)
# get_RLum() ----------------------------------------------------------------------------------
#' @describeIn RLum.Analysis
#' Accessor method for RLum.Analysis object.
#'
#' The slots record.id, `@recordType`, `@curveType` and `@RLum.type` are optional to allow for records
#' limited by their id (list index number), their record type (e.g. `recordType = "OSL"`)
#' or object type.
#'
#' Example: curve type (e.g. `curveType = "predefined"` or `curveType ="measured"`)
#'
#' The selection of a specific RLum.type object superimposes the default selection.
#' Currently supported objects are: RLum.Data.Curve and RLum.Data.Spectrum
#'
#' @param object [`get_RLum`]: [`names_RLum`], [`length_RLum`], [`structure_RLum`] (**required**):
#' an object of class [RLum.Analysis-class]
#'
#' @param record.id [`get_RLum`]: [numeric] or [logical] (*optional*):
#' IDs of specific records. If of type `logical` the entire id range is assumed
#' and `TRUE` and `FALSE` indicates the selection.
#'
#' @param recordType [`get_RLum`]: [character] (*optional*):
#' record type (e.g., "OSL"). Can be also a vector, for multiple matching,
#' e.g., `recordType = c("OSL", "IRSL")`
#'
#' @param curveType [`get_RLum`]: [character] (*optional*):
#' curve type (e.g. "predefined" or "measured")
#'
#' @param RLum.type [`get_RLum`]: [character] (*optional*):
#' RLum object type. Defaults to "RLum.Data.Curve" and "RLum.Data.Spectrum".
#'
#' @param get.index [`get_RLum`]: [logical] (*optional*):
#' return a numeric vector with the index of each element in the RLum.Analysis object.
#'
#' @param recursive [`get_RLum`]: [logical] (*with default*):
#' if `TRUE` (the default) and the result of the `get_RLum()` request is a single
#' object this object will be unlisted, means only the object itself and no
#' list containing exactly one object is returned. Mostly this makes things
#' easier, however, if this method is used within a loop this might be undesired.
#'
#' @param drop [`get_RLum`]: [logical] (*with default*):
#' coerce to the next possible layer (which are `RLum.Data`-objects),
#' `drop = FALSE` keeps the original `RLum.Analysis`
#'
#' @param info.object [`get_RLum`]: [character] (*optional*):
#' name of the wanted info element
#'
#' @param subset [`get_RLum`]: [expression] (*optional*):
#' logical expression indicating elements or rows to keep: missing values are
#' taken as false. This argument takes precedence over all other arguments,
#' meaning they are not considered when subsetting the object.
#'
#' @param env [`get_RLum`]: [environment] (*with default*):
#' An environment passed to [eval] as the enclosure. This argument is only
#' relevant when subsetting the object and should not be used manually.
#'
#' @return
#'
#' **`get_RLum`**:
#'
#' Returns:
#'
#' 1. [list] of [RLum.Data-class] objects or
#' 2. Single [RLum.Data-class] object, if only one object is contained and `recursive = FALSE` or
#' 3. [RLum.Analysis-class] objects for `drop = FALSE`
#'
#' @md
#' @export
setMethod("get_RLum",
signature = ("RLum.Analysis"),
function(object, record.id = NULL, recordType = NULL, curveType = NULL, RLum.type = NULL,
protocol = "UNKNOWN", get.index = NULL, drop = TRUE, recursive = TRUE,
info.object = NULL, subset = NULL, env = parent.frame(2)) {
.set_function_name("get_RLum")
on.exit(.unset_function_name(), add = TRUE)
if (!is.null(substitute(subset))) {
# To account for different lengths and elements in the @info slot we first
# check all unique elements (in all records)
info_el <- unique(unlist(lapply(object@records, function(el) names(el@info))))
envir <- as.data.frame(do.call(rbind,
lapply(object@records, function(el) {
val <- c(curveType = el@curveType, recordType = el@recordType, unlist(el@info))
# add missing info elements and set NA
if (any(!info_el %in% names(val))) {
val_new <- setNames(
rep("",length(info_el[!info_el %in% names(val)])), info_el[!info_el %in% names(val)])
val <- c(val, val_new)
}
# order the named char vector by its names so we don't mix up the columns
val <- val[order(names(val))]
return(val)
})), stringAsFactors = FALSE)
##select relevant rows
sel <- tryCatch(eval(
expr = substitute(subset),
envir = envir,
enclos = env
),
error = function(e) {
.throw_error("Invalid subset expression, valid terms are: ",
.collapse(names(envir)))
})
if (!is.logical(sel)) {
.throw_error("'subset' must contain a logical expression")
}
if (all(is.na(sel)))
sel <- FALSE
if (any(sel)) {
object@records <- object@records[sel]
return(object)
} else {
tmp <- mapply(function(name, op) {
message(" ", name, ": ", .collapse(unique(op), quote = FALSE))
}, names(envir), envir)
.throw_message("'subset' expression produced an ",
"empty selection, NULL returned")
return(NULL)
}
}
##if info.object is set, only the info objects are returned
else if(!is.null(info.object)) {
if(info.object %in% names(object@info)){
unlist(object@info[info.object])
}else{
##check for entries
if(length(object@info) == 0){
.throw_warning("This 'RLum.Analysis' object has no info ",
"objects, NULL returned")
}else{
.throw_warning("Invalid 'info.object' name, valid names are: ",
.collapse(names(object@info)))
}
return(NULL)
}
} else {
##check for records
if (length(object@records) == 0) {
.throw_warning("This 'RLum.Analysis' object has no records, ",
"NULL returned")
return(NULL)
}
##record.id
if (is.null(record.id)) {
record.id <- c(1:length(object@records))
} else {
.validate_class(record.id, c("integer", "numeric", "logical"))
}
##logical needs a slightly different treatment
##Why do we need this? Because a lot of standard R functions work with logical
##values instead of numerical indices
if (is.logical(record.id)) {
record.id <- c(1:length(object@records))[record.id]
}
##check if record.id exists
if (!all(abs(record.id) %in% (1:length(object@records)))) {
.throw_message("At least one 'record.id' is invalid, ",
"NULL returned")
return(NULL)
}
##recordType
if (is.null(recordType)) {
recordType <-
unique(vapply(object@records, function(x)
x@recordType, character(1)))
} else {
.validate_class(recordType, "character")
}
##curveType
if (is.null(curveType)) {
curveType <- unique(unlist(lapply(1:length(object@records),
function(x) {
object@records[[x]]@curveType
})))
} else {
.validate_class(curveType, "character")
}
##RLum.type
if (is.null(RLum.type)) {
RLum.type <- c("RLum.Data.Curve", "RLum.Data.Spectrum", "RLum.Data.Image")
} else {
.validate_class(RLum.type, "character")
}
##get.index
if (is.null(get.index)) {
get.index <- FALSE
} else {
.validate_class(get.index, "logical")
}
##get originator
originator <- NA_character_
if (.hasSlot(object, "originator")) {
originator <- object@originator
}
##-----------------------------------------------------------------##
##a pre-selection is necessary to support negative index selection
object@records <- object@records[record.id]
record.id <- 1:length(object@records)
##select curves according to the chosen parameter
if (length(record.id) >= 1) {
temp <- lapply(record.id, function(x) {
if (is(object@records[[x]])[1] %in% RLum.type) {
##as input a vector is allowed
temp <- lapply(1:length(recordType), function(k) {
##translate input to regular expression
recordType[k] <- glob2rx(recordType[k])
recordType[k] <- substr(recordType[k], start = 2, stop = nchar(recordType[k]) - 1)
##handle NA
if(is.na(object@records[[x]]@recordType))
recordType_comp <- "NA"
else
recordType_comp <- object@records[[x]]@recordType
## get the results object and if requested, get the index
if (grepl(recordType[k], recordType_comp) &
object@records[[x]]@curveType %in% curveType) {
if (!get.index) object@records[[x]] else x
}
})
##remove empty entries and select just one to unlist
temp <- temp[!vapply(temp, is.null,logical(1))]
##if list has length 0 skip entry
if (length(temp) != 0) {
temp[[1]]
} else{
temp <- NULL
}
}
})
##remove empty list element
temp <- temp[!vapply(temp, is.null, logical(1))]
##check if the produced object is empty and show warning message
if (length(temp) == 0)
.throw_warning("This request produced an empty list of records")
##remove list for get.index
if (get.index) {
return(unlist(temp))
} else{
if (!drop) {
temp <- set_RLum(
class = "RLum.Analysis",
originator = originator,
records = temp,
protocol = object@protocol,
.pid = object@.pid
)
return(temp)
} else{
if (length(temp) == 1 & recursive == TRUE) {
return(temp[[1]])
} else{
return(temp)
}
}
}
} else{
## FIXME(mcol): this block seems unreachable : as before the
## `if` block we set `record.id <- 1:length(object@records)`,
## it can never happen that `length(record.id) < 1`
# nocov start
if (!get.index[1]) {
if (drop == FALSE) {
##needed to keep the argument drop == TRUE
temp <- set_RLum(
class = "RLum.Analysis",
originator = originator,
records = list(object@records[[record.id]]),
protocol = object@protocol,
.pid = object@.pid
)
return(temp)
} else{
return(object@records[[record.id]])
}
} else{
return(record.id)
}
# nocov end
}
}
})
# structure_RLum() ----------------------------------------------------------------------------
###
#' @describeIn RLum.Analysis
#' Method to show the structure of an [RLum.Analysis-class] object.
#'
#' @param fullExtent [structure_RLum]; [logical] (*with default*):
#' extends the returned `data.frame` to its full extent, i.e. all info elements
#' are part of the return as well. The default value is `FALSE` as the data
#' frame might become rather big.
#'
#' @return
#'
#' **`structure_RLum`**:
#'
#' Returns [data.frame-class] showing the structure.
#'
#' @md
#' @export
setMethod("structure_RLum",
signature= "RLum.Analysis",
definition = function(object, fullExtent = FALSE) {
.set_function_name("structure_RLum")
on.exit(.unset_function_name(), add = TRUE)
##check if the object containing other elements than allowed
if(!all(vapply(object@records, FUN = class, character(1)) == "RLum.Data.Curve"))
.throw_error("Only 'RLum.Data.Curve' objects are allowed")
##get length object
temp.object.length <- length(object@records)
##ID
temp.id <- seq_along(object@records)
##recordType
temp.recordType <-
vapply(object@records, function(x) {
x@recordType
}, character(1))
##PROTOCOL STEP
temp.protocol.step <- c(NA)
length(temp.protocol.step) <- temp.object.length
##n.channels
temp.n.channels <- vapply(object@records, function(x){length(x@data[,1])}, numeric(1))
##X.MIN
temp.x.min <- vapply(object@records, function(x){min(x@data[,1])}, numeric(1))
##X.MAX
temp.x.max <- vapply(object@records, function(x){max(x@data[,1])}, numeric(1))
##y.MIN
temp.y.min <- vapply(object@records, function(x){min(x@data[,2])}, numeric(1))
##X.MAX
temp.y.max <- vapply(object@records, function(x){max(x@data[,2])}, numeric(1))
##.uid
temp.uid <- unlist(lapply(object@records, function(x){x@.uid}))
##.pid
temp.pid <- unlist(lapply(object@records, function(x){x@.pid}))
if (length(temp.pid) > 1)
temp.pid <- paste(temp.pid, collapse = ", ")
##originator
temp.originator <- unlist(lapply(object@records, function(x){x@originator}))
##curveType
temp.curveType <- unlist(lapply(object@records, function(x){x@curveType}))
##info elements as character value
if (fullExtent) {
temp.info.elements <- as.data.frame(data.table::rbindlist(lapply(object@records, function(x) {
x@info
}), fill = TRUE))
if (nrow(temp.info.elements) == 0) {
## if we are here temp.info.elements 0 rows and 0 columns:
## to avoid crashing further down in the data.frame() call,
## we create a data frame with the expected number of rows
temp.info.elements <- data.frame(info = rep(NA, temp.object.length))
}
} else{
temp.info.elements <-
unlist(sapply(object@records, function(x) {
if (length(x@info) != 0) {
paste(names(x@info), collapse = " ")
} else{
NA
}
}))
}
##combine output to a data.frame
return(
data.frame(
id = temp.id,
recordType = temp.recordType,
curveType = temp.curveType,
protocol.step = temp.protocol.step,
n.channels = temp.n.channels,
x.min = temp.x.min,
x.max = temp.x.max,
y.min = temp.y.min,
y.max = temp.y.max,
originator = temp.originator,
.uid = temp.uid,
.pid = temp.pid,
info = temp.info.elements,
stringsAsFactors = FALSE
)
)
})
# length_RLum() -------------------------------------------------------------------------------
#' @describeIn RLum.Analysis
#' Returns the length of the object, i.e., number of stored records.
#'
#' @return
#'
#' **`length_RLum`**
#'
#' Returns the number records in this object.
#'
#' @md
#' @export
setMethod("length_RLum",
"RLum.Analysis",
function(object){
length(object@records)
})
# names_RLum() --------------------------------------------------------------------------------
#' @describeIn RLum.Analysis
#' Returns the names of the [RLum.Data-class] objects objects (same as shown with the show method)
#'
#' @return
#'
#' **`names_RLum`**
#'
#' Returns the names of the record types (`recordType`) in this object.
#'
#' @md
#' @export
setMethod("names_RLum",
"RLum.Analysis",
function(object){
sapply(object@records, function(x) x@recordType)
})
# smooth_RLum() -------------------------------------------------------------------------------
#' @describeIn RLum.Analysis
#'
#' Smoothing of `RLum.Data` objects contained in this `RLum.Analysis` object
#' using the internal function `.smoothing`.
#'
#' @param ... further arguments passed to underlying methods
#'
#' @return
#'
#' **`smooth_RLum`**
#'
#' Same object as input, after smoothing
#'
#' @md
#' @export
setMethod(
f = "smooth_RLum",
signature = "RLum.Analysis",
function(object, ...) {
object@records <- lapply(object@records, function(x){
smooth_RLum(x, ...)
})
return(object)
}
)
# melt_RLum() -------------------------------------------------------------------------------
#' @describeIn RLum.Analysis
#' Melts [RLum.Analysis-class] objects into a flat data.frame to be used
#' in combination with other packages such as `ggplot2`.
#'
#' @return
#'
#' **`melt_RLum`**
#'
#' Flat [data.frame] with `X`, `Y`, `TYPE`, `UID`
#'
#' @md
#' @export
setMethod(
f = "melt_RLum",
signature = "RLum.Analysis",
function(object) {
melt_RLum(object@records)
}
)
## view() -------------------------------------------------------------------
#' @describeIn RLum.Analysis
#'
#' View method for [RLum.Analysis-class] objects
#'
#' @param object an object of class [RLum.Analysis-class]
#'
#' @param ... other arguments that might be passed
#'
#' @keywords internal
#'
#' @md
#' @export
setMethod("view",
signature = "RLum.Analysis",
definition = function(object, ...) {
## set title
name <- list(...)$title
if (is.null(name))
name <- deparse(substitute(object))
## collect info lists from all records
info <- lapply(seq_along(object@records),
function(x) c(aliquot = x, object@records[[x]]@info))
info <- rbindlist(info, fill = TRUE)
## run view
.view(x = info, title = name)
})