1
0
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:
2018-11-02 14:55:29 +01:00
parent 40a159e78d
commit d0bc05e5b1
4 changed files with 57 additions and 17 deletions

23
R/rsi.R
View File

@ -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