mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 08:32:04 +02:00
(v0.7.1.9035) cephalosporins and unit tests
This commit is contained in:
2
R/ab.R
2
R/ab.R
@ -233,7 +233,7 @@ as.ab <- function(x) {
|
||||
}
|
||||
|
||||
if (length(x_unknown) > 0) {
|
||||
warning("These values could not be coerced to a valid antibiotic ID: ",
|
||||
warning("These values could not be coerced to a valid antimicrobial ID: ",
|
||||
paste('"', sort(unique(x_unknown)), '"', sep = "", collapse = ', '),
|
||||
".",
|
||||
call. = FALSE)
|
||||
|
@ -29,6 +29,5 @@
|
||||
#' @rdname AMR-deprecated
|
||||
as.atc <- function(x) {
|
||||
.Deprecated("ab_atc", package = "AMR")
|
||||
ab_atc(x)
|
||||
AMR::ab_atc(x)
|
||||
}
|
||||
|
||||
|
@ -669,7 +669,7 @@ eucast_rules <- function(x,
|
||||
suppressWarnings(
|
||||
all_staph <- AMR::microorganisms %>%
|
||||
filter(genus == "Staphylococcus") %>%
|
||||
mutate(CNS_CPS = mo_fullname(mo, Becker = "all"))
|
||||
mutate(CNS_CPS = mo_name(mo, Becker = "all"))
|
||||
)
|
||||
if (eucast_rules_df[i, 3] %like% "coagulase-") {
|
||||
eucast_rules_df[i, 3] <- paste0("^(",
|
||||
|
@ -21,14 +21,16 @@
|
||||
|
||||
#' Translate strings from AMR package
|
||||
#'
|
||||
#' For language-dependent output of AMR functions, like \code{\link{mo_fullname}} and \code{\link{mo_type}}.
|
||||
#' For language-dependent output of AMR functions, like \code{\link{mo_name}}, \code{\link{mo_type}} and \code{\link{ab_name}}.
|
||||
#' @details Strings will be translated to foreign languages if they are defined in a local translation file. Additions to this file can be suggested at our repository. The file can be found here: \url{https://gitlab.com/msberends/AMR/blob/master/data-raw/translations.tsv}.
|
||||
#'
|
||||
#' Currently supported languages can be found if running: \code{unique(AMR:::translations_file$lang)}.
|
||||
#'
|
||||
#' Please suggest your own translations \href{https://gitlab.com/msberends/AMR/issues/new?issue[title]=Translation\%20suggestion}{by creating a new issue on our repository}.
|
||||
#'
|
||||
#' This file will be read by all functions where a translated output can be desired, like all \code{\link{mo_property}} functions (\code{\link{mo_fullname}}, \code{\link{mo_type}}, etc.).
|
||||
#'
|
||||
#' The system language will be used at default, if supported, using \code{\link{get_locale}}. The system language can be overwritten with \code{\link{getOption}("AMR_locale")}.
|
||||
#' The system language will be used at default, if that language is supported. The system language can be overwritten with \code{\link{getOption}("AMR_locale")}.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @rdname translate
|
||||
#' @name translate
|
||||
@ -39,27 +41,27 @@
|
||||
#' # with get_locale()
|
||||
#'
|
||||
#' # English
|
||||
#' mo_fullname("CoNS", language = "en")
|
||||
#' mo_name("CoNS", language = "en")
|
||||
#' #> "Coagulase-negative Staphylococcus (CoNS)"
|
||||
#'
|
||||
#' # German
|
||||
#' mo_fullname("CoNS", language = "de")
|
||||
#' mo_name("CoNS", language = "de")
|
||||
#' #> "Koagulase-negative Staphylococcus (KNS)"
|
||||
#'
|
||||
#' # Dutch
|
||||
#' mo_fullname("CoNS", language = "nl")
|
||||
#' mo_name("CoNS", language = "nl")
|
||||
#' #> "Coagulase-negatieve Staphylococcus (CNS)"
|
||||
#'
|
||||
#' # Spanish
|
||||
#' mo_fullname("CoNS", language = "es")
|
||||
#' mo_name("CoNS", language = "es")
|
||||
#' #> "Staphylococcus coagulasa negativo (SCN)"
|
||||
#'
|
||||
#' # Italian
|
||||
#' mo_fullname("CoNS", language = "it")
|
||||
#' mo_name("CoNS", language = "it")
|
||||
#' #> "Staphylococcus negativo coagulasi (CoNS)"
|
||||
#'
|
||||
#' # Portuguese
|
||||
#' mo_fullname("CoNS", language = "pt")
|
||||
#' mo_name("CoNS", language = "pt")
|
||||
#' #> "Staphylococcus coagulase negativo (CoNS)"
|
||||
get_locale <- function() {
|
||||
if (getOption("AMR_locale", "en") != "en") {
|
||||
|
2
R/like.R
2
R/like.R
@ -28,7 +28,7 @@
|
||||
#' @rdname like
|
||||
#' @export
|
||||
#' @details Using RStudio? This function can also be inserted from the Addins menu and can have its own Keyboard Shortcut like Ctrl+Shift+L or Cmd+Shift+L (see Tools > Modify Keyboard Shortcuts...).
|
||||
#' @source Idea from the \href{https://github.com/Rdatatable/data.table/blob/master/R/like.R}{\code{like} function from the \code{data.table} package}, but made it case insensitive at default and let it support multiple patterns.
|
||||
#' @source Idea from the \href{https://github.com/Rdatatable/data.table/blob/master/R/like.R}{\code{like} function from the \code{data.table} package}, but made it case insensitive at default and let it support multiple patterns. Also, if the regex fails the first time, it tries again with \code{perl = TRUE}.
|
||||
#' @seealso \code{\link[base]{grep}}
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
|
42
R/misc.R
42
R/misc.R
@ -29,48 +29,6 @@ addin_insert_like <- function() {
|
||||
rstudioapi::insertText(" %like% ")
|
||||
}
|
||||
|
||||
# No export, no Rd
|
||||
# works exactly like round(), but rounds `round(44.55, 1)` as 44.6 instead of 44.5
|
||||
# and adds decimal zeroes until `digits` is reached when force_zero = TRUE
|
||||
round2 <- function(x, digits = 0, force_zero = TRUE) {
|
||||
# https://stackoverflow.com/a/12688836/4575331
|
||||
val <- (trunc((abs(x) * 10 ^ digits) + 0.5) / 10 ^ digits) * sign(x)
|
||||
if (digits > 0 & force_zero == TRUE) {
|
||||
val[val != as.integer(val)] <- paste0(val[val != as.integer(val)],
|
||||
strrep("0", max(0, digits - nchar(gsub(".*[.](.*)$", "\\1", val[val != as.integer(val)])))))
|
||||
}
|
||||
val
|
||||
}
|
||||
|
||||
# Coefficient of variation (CV)
|
||||
cv <- function(x, na.rm = TRUE) {
|
||||
stats::sd(x, na.rm = na.rm) / base::abs(base::mean(x, na.rm = na.rm))
|
||||
}
|
||||
|
||||
# Coefficient of dispersion, or coefficient of quartile variation (CQV).
|
||||
# (Bonett et al., 2006: Confidence interval for a coefficient of quartile variation).
|
||||
cqv <- function(x, na.rm = TRUE) {
|
||||
fives <- stats::fivenum(x, na.rm = na.rm)
|
||||
(fives[4] - fives[2]) / (fives[4] + fives[2])
|
||||
}
|
||||
|
||||
# show bytes as kB/MB/GB
|
||||
# size_humanreadable(123456) # 121 kB
|
||||
# size_humanreadable(12345678) # 11.8 MB
|
||||
size_humanreadable <- function(bytes, decimals = 1) {
|
||||
bytes <- bytes %>% as.double()
|
||||
# Adapted from:
|
||||
# http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
|
||||
size <- c('B','kB','MB','GB','TB','PB','EB','ZB','YB')
|
||||
factor <- floor((nchar(bytes) - 1) / 3)
|
||||
# added slight improvement; no decimals for B and kB:
|
||||
decimals <- rep(decimals, length(bytes))
|
||||
decimals[size[factor + 1] %in% c('B', 'kB')] <- 0
|
||||
|
||||
out <- paste(sprintf(paste0("%.", decimals, "f"), bytes / (1024 ^ factor)), size[factor + 1])
|
||||
out
|
||||
}
|
||||
|
||||
percent_clean <- clean:::percent
|
||||
# No export, no Rd
|
||||
percent <- function(x, round = 1, force_zero = FALSE, decimal.mark = getOption("OutDec"), big.mark = ",", ...) {
|
||||
|
5
R/mo.R
5
R/mo.R
@ -477,7 +477,8 @@ exec_as.mo <- function(x,
|
||||
# translate to English for supported languages of mo_property
|
||||
x <- gsub("(gruppe|groep|grupo|gruppo|groupe)", "group", x, ignore.case = TRUE)
|
||||
x <- gsub("(hefe|gist|gisten|levadura|lievito|fermento|levure)[a-z]*", "yeast", x, ignore.case = TRUE)
|
||||
x <- gsub("(schimmels?|mofo|molde|stampo|moisissure)[a-z]*", "fungus", x, ignore.case = TRUE)
|
||||
x <- gsub("(schimmels?|mofo|molde|stampo|moisissure|fungi)[a-z]*", "fungus", x, ignore.case = TRUE)
|
||||
x <- gsub("Fungus[ph|f]rya", "Fungiphrya", x, ignore.case = TRUE)
|
||||
# remove non-text in case of "E. coli" except dots and spaces
|
||||
x <- gsub("[^.a-zA-Z0-9/ \\-]+", "", x)
|
||||
# replace minus by a space
|
||||
@ -1216,7 +1217,7 @@ exec_as.mo <- function(x,
|
||||
}
|
||||
return(found[1L])
|
||||
}
|
||||
if (b.x_trimmed %like% "fungus") {
|
||||
if (b.x_trimmed %like% "(fungus|fungi)" & !b.x_trimmed %like% "Fungiphrya") {
|
||||
found <- "F_FUNGUS"
|
||||
found_result <- found
|
||||
found <- microorganismsDT[mo == found, ..property][[1]]
|
||||
|
@ -318,7 +318,7 @@ mo_synonyms <- function(x, ...) {
|
||||
}
|
||||
})
|
||||
if (length(syns) > 1) {
|
||||
names(syns) <- mo_fullname(x)
|
||||
names(syns) <- mo_name(x)
|
||||
result <- syns
|
||||
} else {
|
||||
result <- unlist(syns)
|
||||
@ -340,7 +340,7 @@ mo_info <- function(x, language = get_locale(), ...) {
|
||||
url = unname(mo_url(y, open = FALSE)),
|
||||
ref = mo_ref(y))))
|
||||
if (length(info) > 1) {
|
||||
names(info) <- mo_fullname(x)
|
||||
names(info) <- mo_name(x)
|
||||
result <- info
|
||||
} else {
|
||||
result <- info[[1L]]
|
||||
@ -368,7 +368,7 @@ mo_url <- function(x, open = FALSE, ...) {
|
||||
NA_character_))
|
||||
|
||||
u <- df$url
|
||||
names(u) <- AMR::mo_fullname(mo)
|
||||
names(u) <- AMR::mo_name(mo)
|
||||
if (open == TRUE) {
|
||||
if (length(u) > 1) {
|
||||
warning("only the first URL will be opened, as `browseURL()` only suports one string.")
|
||||
|
8
R/rsi.R
8
R/rsi.R
@ -25,14 +25,14 @@
|
||||
#' @rdname as.rsi
|
||||
#' @param x vector of values (for class \code{mic}: an MIC value in mg/L, for class \code{disk}: a disk diffusion radius in millimeters)
|
||||
#' @param mo a microorganism code, generated with \code{\link{as.mo}}
|
||||
#' @param ab an antibiotic code, generated with \code{\link{as.ab}}
|
||||
#' @param ab an antimicrobial code, generated with \code{\link{as.ab}}
|
||||
#' @inheritParams first_isolate
|
||||
#' @param guideline defaults to the latest included EUCAST guideline, run \code{unique(AMR::rsi_translation$guideline)} for all options
|
||||
#' @param threshold maximum fraction of \code{x} that is allowed to fail transformation, see Examples
|
||||
#' @param threshold maximum fraction of invalid antimicrobial interpretations of \code{x}, see Examples
|
||||
#' @param ... parameters passed on to methods
|
||||
#' @details Run \code{unique(AMR::rsi_translation$guideline)} for a list of all supported guidelines.
|
||||
#'
|
||||
#' After using \code{as.rsi}, you can use \code{\link{eucast_rules}} to (1) apply inferred susceptibility and resistance based on results of other antibiotics and (2) apply intrinsic resistance based on taxonomic properties of a microorganism.
|
||||
#' After using \code{as.rsi}, you can use \code{\link{eucast_rules}} to (1) apply inferred susceptibility and resistance based on results of other antimicrobials and (2) apply intrinsic resistance based on taxonomic properties of a microorganism.
|
||||
#'
|
||||
#' The function \code{is.rsi.eligible} returns \code{TRUE} when a columns contains at most 5\% invalid antimicrobial interpretations (not S and/or I and/or R), and \code{FALSE} otherwise. The threshold of 5\% can be set with the \code{threshold} parameter.
|
||||
#' @section Interpretation of S, I and R:
|
||||
@ -265,7 +265,7 @@ as.rsi.data.frame <- function(x, col_mo = NULL, guideline = "EUCAST", ...) {
|
||||
|
||||
ab_cols <- colnames(x)[sapply(x, function(y) is.mic(y) | is.disk(y))]
|
||||
if (length(ab_cols) == 0) {
|
||||
stop("No columns with MIC values or disk zones found in this data set. Use as.mic or as.disk to transform antibiotic columns.", call. = FALSE)
|
||||
stop("No columns with MIC values or disk zones found in this data set. Use as.mic or as.disk to transform antimicrobial columns.", call. = FALSE)
|
||||
}
|
||||
|
||||
# try to find columns based on type
|
||||
|
BIN
R/sysdata.rda
BIN
R/sysdata.rda
Binary file not shown.
Reference in New Issue
Block a user