1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-27 09:26:11 +01:00
AMR/R/freq.R

55 lines
2.7 KiB
R
Raw Normal View History

# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
2019-01-02 23:24:07 +01:00
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
2019-01-02 23:24:07 +01:00
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
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. #
# #
# This R package was created for academic research and 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. #
# ==================================================================== #
2019-07-29 13:33:48 +02:00
freq_def <- clean:::freq.default
#' @exportMethod freq.mo
2018-07-01 21:40:37 +02:00
#' @importFrom dplyr n_distinct
2019-07-29 13:33:48 +02:00
#' @importFrom clean freq
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, ...) {
# replace with freq.default() if next `clean` version is published on CRAN
freq_def(x = x, ...,
.add_header = list(families = n_distinct(mo_family(x, language = NULL)),
genera = n_distinct(mo_genus(x, language = NULL)),
species = n_distinct(paste(mo_genus(x, language = NULL),
mo_species(x, language = NULL)))))
2019-01-17 12:08:04 +01:00
}
2019-07-29 13:33:48 +02:00
#' @exportMethod freq.rsi
#' @importFrom clean freq
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)
ab <- suppressMessages(suppressWarnings(AMR::as.ab(x_name)))
if (!is.na(ab)) {
freq_def(x = x, ...,
.add_header = list(Drug = paste0(ab_name(ab), " (", ab, ", ", ab_atc(ab), ")"),
group = ab_group(ab),
`%SI` = portion_SI(x, minimum = 0, as_percent = TRUE)))
} else {
2019-07-29 13:33:48 +02:00
freq_def(x = x, ...,
.add_header = list(`%SI` = portion_SI(x, minimum = 0, as_percent = TRUE)))
}
}