1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 08:32:04 +02:00

(v1.3.0) v1.3.0

This commit is contained in:
2020-07-29 13:48:50 +02:00
parent de0f7b8950
commit ea4e5e5b81
15 changed files with 68 additions and 73 deletions

68
R/rsi.R
View File

@ -143,6 +143,40 @@ as.rsi <- function(x, ...) {
UseMethod("as.rsi")
}
#' @rdname as.rsi
#' @export
is.rsi <- function(x) {
inherits(x, "rsi")
}
#' @rdname as.rsi
#' @export
is.rsi.eligible <- function(x, threshold = 0.05) {
stop_if(NCOL(x) > 1, "`x` must be a one-dimensional vector.")
if (any(c("logical",
"numeric",
"integer",
"mo",
"Date",
"POSIXct",
"rsi",
"raw",
"hms")
%in% class(x))) {
# no transformation needed
FALSE
} else {
x <- x[!is.na(x) & !is.null(x) & !identical(x, "")]
if (length(x) == 0) {
return(FALSE)
}
checked <- suppressWarnings(as.rsi(x))
outcome <- sum(is.na(checked)) / length(x)
outcome <= threshold
}
}
#' @export
as.rsi.default <- function(x, ...) {
if (is.rsi(x)) {
@ -513,40 +547,6 @@ exec_as.rsi <- function(method, x, mo, ab, guideline, uti, conserve_capped_value
class = c("rsi", "ordered", "factor"))
}
#' @rdname as.rsi
#' @export
is.rsi <- function(x) {
inherits(x, "rsi")
}
#' @rdname as.rsi
#' @export
is.rsi.eligible <- function(x, threshold = 0.05) {
stop_if(NCOL(x) > 1, "`x` must be a one-dimensional vector.")
if (any(c("logical",
"numeric",
"integer",
"mo",
"Date",
"POSIXct",
"rsi",
"raw",
"hms")
%in% class(x))) {
# no transformation needed
FALSE
} else {
x <- x[!is.na(x) & !is.null(x) & !identical(x, "")]
if (length(x) == 0) {
return(FALSE)
}
checked <- suppressWarnings(as.rsi(x))
outcome <- sum(is.na(checked)) / length(x)
outcome <= threshold
}
}
#' @method print rsi
#' @export
#' @noRd