mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 12:31:58 +02:00
freq update
This commit is contained in:
38
R/data.R
38
R/data.R
@ -42,13 +42,14 @@
|
||||
#' \item{\code{useful_gramnegative}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)}
|
||||
#' \item{\code{useful_grampositive}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)}
|
||||
#' }
|
||||
#' @source - World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
|
||||
#' @source World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
|
||||
#'
|
||||
#' Table antibiotic coding EARSS (from WHONET 5.3): \url{http://www.madsonline.dk/Tutorials/landskoder_antibiotika_WM.pdf}
|
||||
#'
|
||||
#' EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes Tables. Version 3.1, 2016: \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}
|
||||
#'
|
||||
#' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}
|
||||
#' @inheritSection WHOCC WHOCC
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @seealso \code{\link{microorganisms}}
|
||||
# use this later to further fill AMR::antibiotics
|
||||
@ -203,6 +204,41 @@
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
"septic_patients"
|
||||
|
||||
#' Data set with 500 isolates - WHONET example
|
||||
#'
|
||||
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The data itself was based on our \code{\link{septic_patients}} data set.
|
||||
#' @format A \code{\link{data.frame}} with 500 observations and 53 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{Identification number}}{ID of the sample}
|
||||
#' \item{\code{Specimen number}}{ID of the specimen}
|
||||
#' \item{\code{Organism}}{Microorganisms, can be coerced with \code{\link{as.mo}}}
|
||||
#' \item{\code{Country}}{Country of origin}
|
||||
#' \item{\code{Laboratory}}{Name of laboratory}
|
||||
#' \item{\code{Last name}}{Last name of patient}
|
||||
#' \item{\code{First name}}{Initial of patient}
|
||||
#' \item{\code{Sex}}{Gender of patient}
|
||||
#' \item{\code{Age}}{Age of patient}
|
||||
#' \item{\code{Age category}}{Age group, can also be looked up using \code{\link{age_groups}}}
|
||||
#' \item{\code{Date of admission}}{Date of hospital admission}
|
||||
#' \item{\code{Specimen date}}{Date when specimen was received at laboratory}
|
||||
#' \item{\code{Specimen type}}{Specimen type or group}
|
||||
#' \item{\code{Specimen type (Numeric)}}{Translation of \code{"Specimen type"}}
|
||||
#' \item{\code{Reason}}{Reason of request with Differential Diagnosis}
|
||||
#' \item{\code{Isolate number}}{ID of isolate}
|
||||
#' \item{\code{Organism type}}{Type of microorganism, can also be looked up using \code{\link{mo_type}}}
|
||||
#' \item{\code{Serotype}}{Serotype of microorganism}
|
||||
#' \item{\code{Beta-lactamase}}{Microorganism produces beta-lactamase?}
|
||||
#' \item{\code{ESBL}}{Microorganism produces extended spectrum beta-lactamase?}
|
||||
#' \item{\code{Carbapenemase}}{Microorganism produces carbapenemase?}
|
||||
#' \item{\code{MRSA screening test}}{Microorganism is possible MRSA?}
|
||||
#' \item{\code{Inducible clindamycin resistance}}{Clindamycin can be induced?}
|
||||
#' \item{\code{Comment}}{Other comments}
|
||||
#' \item{\code{Date of data entry}}{Date this data was entered in WHONET}
|
||||
#' \item{\code{AMP_ND10:CIP_EE}}{27 different antibiotics. You can lookup the abbreviatons in the \code{\link{antibiotics}} data set, or use e.g. \code{\link{atc_name}("AMP")} to get the official name immediately.}
|
||||
#' }
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
"WHONET"
|
||||
|
||||
#' Supplementary Data
|
||||
#'
|
||||
#' These \code{\link{data.table}s} are transformed from the \code{\link{microorganisms}} and \code{\link{microorganisms}} data sets to improve speed of \code{\link{as.mo}}. They are meant for internal use only, and are only mentioned here for reference.
|
||||
|
@ -206,7 +206,14 @@ first_isolate <- function(tbl,
|
||||
|
||||
# -- patient id
|
||||
if (is.null(col_patient_id)) {
|
||||
if (all(c("First name", "Last name", "Sex", "Identification number") %in% colnames(tbl))) {
|
||||
# WHONET support
|
||||
tbl <- tbl %>% mutate(patient_id = paste(`First name`, `Last name`, Sex))
|
||||
col_patient_id <- "patient_id"
|
||||
message(blue(paste0("NOTE: Using combined columns ", bold("`First name`, `Last name` and `Sex`"), " as input for `col_patient_id`.")))
|
||||
} else {
|
||||
col_patient_id <- search_type_in_df(tbl = tbl, type = "patient_id")
|
||||
}
|
||||
}
|
||||
if (is.null(col_patient_id)) {
|
||||
stop("`col_patient_id` must be set.", call. = FALSE)
|
||||
|
34
R/freq.R
34
R/freq.R
@ -71,7 +71,7 @@
|
||||
#' @importFrom utils browseVignettes
|
||||
#' @importFrom hms is.hms
|
||||
#' @importFrom crayon red green silver
|
||||
#' @importFrom rlang enquos eval_tidy as_name
|
||||
#' @importFrom rlang enquos eval_tidy as_label
|
||||
#' @keywords summary summarise frequency freq
|
||||
#' @rdname freq
|
||||
#' @name freq
|
||||
@ -206,6 +206,7 @@ frequency_tbl <- function(x,
|
||||
# x_haslevels <- !is.null(levels(x))
|
||||
x.name <- NULL
|
||||
cols <- NULL
|
||||
cols.names <- NULL
|
||||
if (any(class(x) == "list")) {
|
||||
cols <- names(x)
|
||||
x <- as.data.frame(x, stringsAsFactors = FALSE)
|
||||
@ -224,9 +225,19 @@ frequency_tbl <- function(x,
|
||||
if (is.null(x.name)) {
|
||||
x.name <- deparse(substitute(x))
|
||||
}
|
||||
if (x.name == ".") {
|
||||
x.name <- NULL
|
||||
if (x.name %like% "(%>%)") {
|
||||
x.name <- x.name %>% strsplit("%>%", fixed = TRUE) %>% unlist() %>% .[1] %>% trimws()
|
||||
}
|
||||
if (x.name == ".") {
|
||||
x.name <- "a data.frame"
|
||||
}
|
||||
x.name <- paste0("`", x.name, "`")
|
||||
x.name.dims <- x %>%
|
||||
dim() %>%
|
||||
format(decimal.mark = decimal.mark, big.mark = big.mark) %>%
|
||||
trimws() %>%
|
||||
paste(collapse = " x ")
|
||||
x.name <- paste0(x.name, " (", x.name.dims, ")")
|
||||
|
||||
x.group <- group_vars(x)
|
||||
if (length(x.group) > 1) {
|
||||
@ -238,24 +249,19 @@ frequency_tbl <- function(x,
|
||||
|
||||
if (length(user_exprs) > 0) {
|
||||
new_list <- list(0)
|
||||
|
||||
for (i in 1:length(user_exprs)) {
|
||||
new_list[[i]] <- eval_tidy(user_exprs[[i]], data = x)
|
||||
this_name <- try( as_name(user_exprs[[i]]) , silent = TRUE)
|
||||
if (class(this_name) == "try-error") {
|
||||
this_name <- paste0("V", i)
|
||||
}
|
||||
cols <- c(cols, this_name)
|
||||
cols <- c(cols, as_label(user_exprs[[i]]))
|
||||
}
|
||||
|
||||
if (length(new_list) == 1 & length(x.group) == 0) {
|
||||
# is now character
|
||||
x <- new_list[[1]]
|
||||
df <- NULL
|
||||
cols <- NULL
|
||||
} else {
|
||||
# create data frame
|
||||
df <- as.data.frame(new_list, col.names = paste0("V", 1:length(new_list)), stringsAsFactors = FALSE)
|
||||
df <- as.data.frame(new_list, col.names = cols, stringsAsFactors = FALSE)
|
||||
cols.names <- colnames(df)
|
||||
}
|
||||
} else {
|
||||
# complete data frame
|
||||
@ -264,7 +270,7 @@ frequency_tbl <- function(x,
|
||||
|
||||
# support grouping variables
|
||||
if (length(x.group) > 0) {
|
||||
x.group_cols <- c(x.group, cols)
|
||||
x.group_cols <- c(x.group, cols.names)
|
||||
x <- bind_cols(x, df)
|
||||
# if (droplevels == TRUE) {
|
||||
# x <- x %>% mutate_at(vars(x.group_cols), droplevels)
|
||||
@ -302,11 +308,10 @@ frequency_tbl <- function(x,
|
||||
# no groups, multiple values like: septic_patients %>% freq(mo, mo_genus(mo))
|
||||
x <- df
|
||||
df <- NULL
|
||||
cols <- NULL
|
||||
}
|
||||
}
|
||||
if (length(cols) > 0 & is.data.frame(x)) {
|
||||
x <- x[, cols]
|
||||
x <- x[, cols.names]
|
||||
}
|
||||
|
||||
} else if (any(class(x) == "table")) {
|
||||
@ -328,6 +333,7 @@ frequency_tbl <- function(x,
|
||||
x <- x %>% pull(1)
|
||||
} else if (ncol(x) < 10) {
|
||||
mult.columns <- ncol(x)
|
||||
# paste old columns together
|
||||
x <- do.call(paste, c(x[colnames(x)], sep = sep))
|
||||
} else {
|
||||
stop("A maximum of 9 columns can be analysed at the same time.", call. = FALSE)
|
||||
|
5
R/misc.R
5
R/misc.R
@ -152,7 +152,10 @@ search_type_in_df <- function(tbl, type) {
|
||||
# -- date
|
||||
if (type == "date") {
|
||||
for (i in 1:ncol(tbl)) {
|
||||
if ("Date" %in% class(tbl %>% pull(i)) | "POSIXct" %in% class(tbl %>% pull(i))) {
|
||||
if (any(colnames(tbl) %like% "^(Specimen date)")) {
|
||||
# WHONET support
|
||||
found <- colnames(tbl)[colnames(tbl) %like% "^(Specimen date)"][1]
|
||||
} else if ("Date" %in% class(tbl %>% pull(i)) | "POSIXct" %in% class(tbl %>% pull(i))) {
|
||||
found <- colnames(tbl)[i]
|
||||
break
|
||||
}
|
||||
|
27
R/zzz.R
27
R/zzz.R
@ -21,19 +21,34 @@
|
||||
|
||||
#' The \code{AMR} Package
|
||||
#'
|
||||
#' Welcome to the \code{AMR} package. This page gives some additional contact information about the authors.
|
||||
#' Welcome to the \code{AMR} package.
|
||||
#' @details
|
||||
#' This package was intended to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial properties by using evidence-based methods.
|
||||
#' \code{AMR} is a free and open-source R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial properties by using evidence-based methods. It supports any table format, including WHONET/EARS-Net data.
|
||||
#'
|
||||
#' This package was created for both academic research and routine analysis by PhD students of the Faculty of Medical Sciences of the University of Groningen and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG).
|
||||
#' @section Read more on our website!:
|
||||
#' \if{html}{\figure{logo.png}{options: height=40px style=margin-bottom:5px} \cr}
|
||||
#' On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a omprehensive tutorial} about how to conduct AMR analysis and find \href{https://msberends.gitlab.io/AMR/reference}{the complete documentation of all functions}, which reads a lot easier than in R.
|
||||
#' We created this package for both academic research and routine analysis at the Faculty of Medical Sciences of the University of Groningen and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation.
|
||||
#'
|
||||
#' This package can be used for:
|
||||
#' \itemize{
|
||||
#' \item{Calculating antimicrobial resistance}
|
||||
#' \item{Predicting antimicrobial resistance using regression models}
|
||||
#' \item{Getting properties for any microorganism (like Gram stain, species, genus or family)}
|
||||
#' \item{Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name)}
|
||||
#' \item{Plotting antimicrobial resistance}
|
||||
#' \item{Determining first isolates to be used for AMR analysis}
|
||||
#' \item{Applying EUCAST rules}
|
||||
#' \item{Determining multi-drug resistance organisms (MDRO)}
|
||||
#' \item{Descriptive statistics: frequency tables, kurtosis and skewness}
|
||||
#' }
|
||||
#' @section Authors:
|
||||
#' Matthijs S. Berends[1,2] Christian F. Luz[1], Erwin E.A. Hassing[2], Corinna Glasner[1], Alex W. Friedrich[1], Bhanu N.M. Sinha[1] \cr
|
||||
#'
|
||||
#' [1] Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - \url{rug.nl} \url{umcg.nl} \cr
|
||||
#' [2] Certe Medical Diagnostics & Advice, Groningen, the Netherlands - \url{certe.nl}
|
||||
|
||||
#' @section Read more on our website!:
|
||||
#' \if{html}{\figure{logo.png}{options: height=40px style=margin-bottom:5px} \cr}
|
||||
#' On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}.
|
||||
|
||||
#' @section Contact us:
|
||||
#' For suggestions, comments or questions, please contact us at:
|
||||
#'
|
||||
|
Reference in New Issue
Block a user