mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 04:02:19 +02:00
(v1.0.0.9003) prepare for short update
This commit is contained in:
25
R/rsi.R
25
R/rsi.R
@ -67,6 +67,8 @@
|
||||
#' NIT = as.mic(32))
|
||||
#' as.rsi(df)
|
||||
#'
|
||||
#' \donttest{
|
||||
#'
|
||||
#' # the dplyr way
|
||||
#' library(dplyr)
|
||||
#' df %>%
|
||||
@ -88,7 +90,8 @@
|
||||
#'
|
||||
#' df %>%
|
||||
#' mutate_at(vars(AMP:NIT), as.rsi, mo = "E. coli", uti = TRUE)
|
||||
#'
|
||||
#' }
|
||||
#'
|
||||
#' # for single values
|
||||
#' as.rsi(x = as.mic(2),
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
@ -199,20 +202,6 @@ as.rsi.default <- function(x, ...) {
|
||||
}
|
||||
}
|
||||
|
||||
#' @importFrom dplyr %>%
|
||||
input_resembles_mic <- function(x) {
|
||||
mic <- x %>%
|
||||
gsub("[^0-9.,]+", "", .) %>%
|
||||
unique()
|
||||
mic_valid <- suppressWarnings(as.mic(mic))
|
||||
result <- sum(!is.na(mic_valid)) / length(mic)
|
||||
if (is.na(result)) {
|
||||
0
|
||||
} else {
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname as.rsi
|
||||
#' @export
|
||||
as.rsi.mic <- function(x, mo, ab = deparse(substitute(x)), guideline = "EUCAST", uti = FALSE, ...) {
|
||||
@ -402,10 +391,14 @@ get_guideline <- function(guideline) {
|
||||
rev() %>%
|
||||
.[1]
|
||||
}
|
||||
if (!guideline_param %like% " ") {
|
||||
# like 'EUCAST2020', should be 'EUCAST 2020'
|
||||
guideline_param <- gsub("([a-z]+)([0-9]+)", "\\1 \\2", guideline_param, ignore.case = TRUE)
|
||||
}
|
||||
|
||||
if (!guideline_param %in% rsi_translation$guideline) {
|
||||
stop(paste0("invalid guideline: '", guideline,
|
||||
"'.\nValid guidelines are: ", paste0("'", rev(sort(unique(rsi_translation$guideline))), "'", collapse = ", ")),
|
||||
"'.\nValid guidelines are: ", paste0("'", unique(rsi_translation$guideline), "'", collapse = ", "), "."),
|
||||
call. = FALSE)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user