mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 01:22:25 +02:00
speed improvement is.rsi.eligible
This commit is contained in:
23
R/rsi.R
23
R/rsi.R
@ -98,16 +98,19 @@ is.rsi <- function(x) {
|
||||
#' @export
|
||||
#' @importFrom dplyr %>%
|
||||
is.rsi.eligible <- function(x) {
|
||||
# remove all but a-z
|
||||
distinct_val <- x %>% unique() %>% sort() %>% as.character() %>% gsub("(\\W|\\d)+", "", .)
|
||||
# remove NAs and empty values
|
||||
distinct_val <- distinct_val[!is.na(distinct_val) & trimws(distinct_val) != ""]
|
||||
# get RSI class
|
||||
distinct_val_rsi <- as.character(suppressWarnings(as.rsi(distinct_val)))
|
||||
|
||||
# is not empty and identical to new class
|
||||
length(distinct_val) > 0 &
|
||||
identical(distinct_val, distinct_val_rsi)
|
||||
if (is.logical(x)
|
||||
| is.numeric(x)
|
||||
| is.mo(x)
|
||||
| identical(class(x), "Date")
|
||||
| identical(levels(x), c("S", "I", "R"))) {
|
||||
# no transformation needed
|
||||
FALSE
|
||||
} else {
|
||||
# check all but a-z
|
||||
x <- unique(gsub("[^RSIrsi]+", "", unique(x)))
|
||||
all(x %in% c("R", "I", "S", "", NA_character_)) &
|
||||
!all(x %in% c("", NA_character_))
|
||||
}
|
||||
}
|
||||
|
||||
#' @exportMethod print.rsi
|
||||
|
Reference in New Issue
Block a user