/
range.R
41 lines (39 loc) · 908 Bytes
/
range.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
#' Mutable ranges
#'
#' Mutable ranges have a two methods (`train` and `reset`), and
#' make it possible to build up complete ranges with multiple passes.
#'
#' @export
Range <- R6::R6Class("Range", list(
range = NULL,
initialize = function() {
self$range <- NULL
}
))
#' @export
#' @rdname Range
DiscreteRange <- R6::R6Class(
"DiscreteRange",
inherit = Range,
list(
factor = NULL,
train = function(x, drop = FALSE, na.rm = FALSE) {
self$factor <- self$factor %||% is.factor(x)
self$range <- train_discrete(x, self$range, drop, na.rm, self$factor)
},
reset = function() {
self$range <- NULL
self$factor <- NULL
}
)
)
#' @export
#' @rdname Range
ContinuousRange <- R6::R6Class(
"ContinuousRange",
inherit = Range,
list(
train = function(x) self$range <- train_continuous(x, self$range),
reset = function() self$range <- NULL
)
)