2018-04-18 12:24:54 +02:00
|
|
|
# ==================================================================== #
|
|
|
|
# TITLE #
|
|
|
|
# Antimicrobial Resistance (AMR) Analysis #
|
|
|
|
# #
|
2019-01-02 23:24:07 +01:00
|
|
|
# SOURCE #
|
|
|
|
# https://gitlab.com/msberends/AMR #
|
2018-04-18 12:24:54 +02:00
|
|
|
# #
|
|
|
|
# LICENCE #
|
2020-01-05 17:22:09 +01:00
|
|
|
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
2018-04-18 12:24:54 +02:00
|
|
|
# #
|
2019-01-02 23:24:07 +01:00
|
|
|
# This R package is free software; you can freely use and distribute #
|
|
|
|
# it for both personal and commercial purposes under the terms of the #
|
|
|
|
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
|
|
|
# the Free Software Foundation. #
|
|
|
|
# #
|
2020-01-05 17:22:09 +01:00
|
|
|
# We created this package for both routine data analysis and academic #
|
|
|
|
# research and it was publicly released in the hope that it will be #
|
|
|
|
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
|
2019-04-05 18:47:39 +02:00
|
|
|
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
2018-04-18 12:24:54 +02:00
|
|
|
# ==================================================================== #
|
|
|
|
|
2019-11-03 22:24:42 +01:00
|
|
|
#' @importFrom cleaner freq
|
2019-08-25 22:53:22 +02:00
|
|
|
#' @export
|
2019-11-03 22:24:42 +01:00
|
|
|
cleaner::freq
|
2019-08-25 22:53:22 +02:00
|
|
|
|
2019-07-29 13:33:48 +02:00
|
|
|
#' @exportMethod freq.mo
|
2020-05-16 13:05:47 +02:00
|
|
|
#' @importFrom cleaner freq.default
|
2018-07-01 21:40:37 +02:00
|
|
|
#' @export
|
2019-01-17 12:08:04 +01:00
|
|
|
#' @noRd
|
2019-07-29 13:33:48 +02:00
|
|
|
freq.mo <- function(x, ...) {
|
2019-09-22 17:19:59 +02:00
|
|
|
x_noNA <- as.mo(x[!is.na(x)]) # as.mo() to get the newest mo codes
|
2019-08-30 14:50:56 +02:00
|
|
|
grams <- mo_gramstain(x_noNA, language = NULL)
|
2019-09-30 16:45:36 +02:00
|
|
|
digits <- list(...)$digits
|
|
|
|
if (is.null(digits)) {
|
|
|
|
digits <- 2
|
|
|
|
}
|
2019-08-25 22:53:22 +02:00
|
|
|
freq.default(x = x, ...,
|
2019-08-30 14:50:56 +02:00
|
|
|
.add_header = list(`Gram-negative` = paste0(format(sum(grams == "Gram-negative", na.rm = TRUE),
|
|
|
|
big.mark = ",",
|
|
|
|
decimal.mark = "."),
|
2019-09-30 16:45:36 +02:00
|
|
|
" (", percentage(sum(grams == "Gram-negative", na.rm = TRUE) / length(grams), digits = digits),
|
2019-09-22 17:19:59 +02:00
|
|
|
")"),
|
2019-08-30 14:50:56 +02:00
|
|
|
`Gram-positive` = paste0(format(sum(grams == "Gram-positive", na.rm = TRUE),
|
|
|
|
big.mark = ",",
|
|
|
|
decimal.mark = "."),
|
2019-09-30 16:45:36 +02:00
|
|
|
" (", percentage(sum(grams == "Gram-positive", na.rm = TRUE) / length(grams), digits = digits),
|
2019-09-22 17:19:59 +02:00
|
|
|
")"),
|
2019-11-29 19:43:23 +01:00
|
|
|
`No of genera` = n_distinct(mo_genus(x_noNA, language = NULL)),
|
|
|
|
`No of species` = n_distinct(paste(mo_genus(x_noNA, language = NULL),
|
2019-08-30 14:50:56 +02:00
|
|
|
mo_species(x_noNA, language = NULL)))))
|
2019-01-17 12:08:04 +01:00
|
|
|
}
|
|
|
|
|
2019-07-29 13:33:48 +02:00
|
|
|
#' @exportMethod freq.rsi
|
2019-11-03 22:24:42 +01:00
|
|
|
#' @importFrom cleaner freq.default
|
2018-07-09 14:02:58 +02:00
|
|
|
#' @export
|
2018-07-08 22:14:55 +02:00
|
|
|
#' @noRd
|
2019-07-29 13:33:48 +02:00
|
|
|
freq.rsi <- function(x, ...) {
|
|
|
|
x_name <- deparse(substitute(x))
|
|
|
|
x_name <- gsub(".*[$]", "", x_name)
|
2020-02-14 19:54:13 +01:00
|
|
|
ab <- suppressMessages(suppressWarnings(as.ab(x_name)))
|
2019-07-29 13:33:48 +02:00
|
|
|
if (!is.na(ab)) {
|
2019-08-25 22:53:22 +02:00
|
|
|
freq.default(x = x, ...,
|
|
|
|
.add_header = list(Drug = paste0(ab_name(ab), " (", ab, ", ", ab_atc(ab), ")"),
|
|
|
|
group = ab_group(ab),
|
2020-02-14 19:54:13 +01:00
|
|
|
`%SI` = susceptibility(x, minimum = 0, as_percent = TRUE)))
|
2019-06-07 22:47:37 +02:00
|
|
|
} else {
|
2019-08-25 22:53:22 +02:00
|
|
|
freq.default(x = x, ...,
|
2020-02-14 19:54:13 +01:00
|
|
|
.add_header = list(`%SI` = susceptibility(x, minimum = 0, as_percent = TRUE)))
|
2019-06-07 22:47:37 +02:00
|
|
|
}
|
|
|
|
}
|