documentation, unit tests

This commit is contained in:
dr. M.S. (Matthijs) Berends 2023-01-24 10:20:27 +01:00
parent eef00069fd
commit 830c67f1bf
60 changed files with 45 additions and 7 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.8.2.9099 Version: 1.8.2.9100
Date: 2023-01-23 Date: 2023-01-24
Title: Antimicrobial Resistance Data Analysis Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR) Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by data analysis and to work with microbial and antimicrobial properties by

View File

@ -1,4 +1,4 @@
# AMR 1.8.2.9099 # AMR 1.8.2.9100
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)* *(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*

View File

@ -36,7 +36,7 @@
#' @param ab any (vector of) text that can be coerced to a valid antimicrobial drug code with [as.ab()] #' @param ab any (vector of) text that can be coerced to a valid antimicrobial drug code with [as.ab()]
#' @param uti (Urinary Tract Infection) A vector with [logical]s (`TRUE` or `FALSE`) to specify whether a UTI specific interpretation from the guideline should be chosen. For using [as.sir()] on a [data.frame], this can also be a column containing [logical]s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See *Examples*. #' @param uti (Urinary Tract Infection) A vector with [logical]s (`TRUE` or `FALSE`) to specify whether a UTI specific interpretation from the guideline should be chosen. For using [as.sir()] on a [data.frame], this can also be a column containing [logical]s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See *Examples*.
#' @inheritParams first_isolate #' @inheritParams first_isolate
#' @param guideline defaults to EUCAST `r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))` (the latest implemented EUCAST guideline in the [clinical_breakpoints] data set), but can be set with the [option][options()] `AMR_guideline`. Supports EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`), see *Details*. #' @param guideline defaults to EUCAST `r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))` (the latest implemented EUCAST guideline in the [clinical_breakpoints] data set), but can be set with the option [`AMR_guideline`][AMR-options]. Currently supports EUCAST (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "EUCAST")$guideline)))`) and CLSI (`r min(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`-`r max(as.integer(gsub("[^0-9]", "", subset(clinical_breakpoints, guideline %like% "CLSI")$guideline)))`), see *Details*.
#' @param conserve_capped_values a [logical] to indicate that MIC values starting with `">"` (but not `">="`) must always return "R" , and that MIC values starting with `"<"` (but not `"<="`) must always return "S" #' @param conserve_capped_values a [logical] to indicate that MIC values starting with `">"` (but not `">="`) must always return "R" , and that MIC values starting with `"<"` (but not `"<="`) must always return "S"
#' @param add_intrinsic_resistance *(only useful when using a EUCAST guideline)* a [logical] to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in *Klebsiella* species. Determination is based on the [intrinsic_resistant] data set, that itself is based on `r format_eucast_version_nr(3.3)`. #' @param add_intrinsic_resistance *(only useful when using a EUCAST guideline)* a [logical] to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in *Klebsiella* species. Determination is based on the [intrinsic_resistant] data set, that itself is based on `r format_eucast_version_nr(3.3)`.
#' @param include_PKPD a [logical] to indicate that PK/PD clinical breakpoints must be applied as a last resort, defaults to `TRUE`. Can also be set with the option [`AMR_include_PKPD`][AMR-options]. #' @param include_PKPD a [logical] to indicate that PK/PD clinical breakpoints must be applied as a last resort, defaults to `TRUE`. Can also be set with the option [`AMR_include_PKPD`][AMR-options].

Binary file not shown.

View File

@ -150,7 +150,7 @@ theme_rsi <- function(...) {
# will be exported using s3_register() in R/zzz.R # will be exported using s3_register() in R/zzz.R
pillar_shaft.rsi <- pillar_shaft.sir pillar_shaft.rsi <- pillar_shaft.sir
type_sum.rsi <- function(x, ...) { type_sum.rsi <- function(x, ...) {
deprecation_warning(extra_msg = "* Transform your old 'rsi' class to the new 'sir' class with `as.sir()` using e.g.:\n your_data %>% mutate_if(is.rsi, as.sir)") deprecation_warning(extra_msg = "* The 'rsi' class has been replaced with 'sir'. Transform your 'rsi' columns to 'sir' with `as.sir()`, e.g.:\n your_data %>% mutate_if(is.rsi, as.sir)")
paste0("rsi", font_bold(font_red("[!]"))) paste0("rsi", font_bold(font_red("[!]")))
} }
@ -158,7 +158,7 @@ type_sum.rsi <- function(x, ...) {
#' @export #' @export
#' @noRd #' @noRd
print.rsi <- function(x, ...) { print.rsi <- function(x, ...) {
deprecation_warning(extra_msg = "Transform your old 'rsi' class to the new 'sir' class with `as.sir()`") deprecation_warning(extra_msg = "The 'rsi' class has been replaced with 'sir' - transform your 'rsi' data with `as.sir()`")
cat("Class 'rsi'", font_bold(font_red("[!]\n"))) cat("Class 'rsi'", font_bold(font_red("[!]\n")))
print(as.character(x), quote = FALSE) print(as.character(x), quote = FALSE)
} }
@ -191,6 +191,8 @@ summary.rsi <- summary.sir
#' @export #' @export
unique.rsi <- unique.sir unique.rsi <- unique.sir
# WHEN REMOVING RSI, DON'T FORGET TO REMOVE THE "rsi_df" CLASS FROM R/sir_calc.R
deprecation_warning <- function(old = NULL, new = NULL, extra_msg = NULL) { deprecation_warning <- function(old = NULL, new = NULL, extra_msg = NULL) {
if (is.null(old)) { if (is.null(old)) {
warning_(extra_msg) warning_(extra_msg)

View File

@ -26,3 +26,39 @@
# Visit our website for the full manual and a complete tutorial about # # Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== # # ==================================================================== #
sir <- random_sir(100)
rsi <- sir
class(rsi) <- gsub("sir", "rsi", class(rsi))
mic <- random_mic(100)
disk <- random_disk(100)
expect_identical(summary(sir), summary(rsi))
expect_identical(c(sir), c(rsi))
expect_identical(suppressWarnings(suppressMessages(as.rsi(as.character(rsi)))),
suppressWarnings(suppressMessages(as.sir(as.character(sir)))))
expect_identical(suppressWarnings(suppressMessages(as.rsi(mic, mo = "Escherichia coli", ab = "CIP"))),
suppressWarnings(suppressMessages(as.sir(mic, mo = "Escherichia coli", ab = "CIP"))))
expect_identical(suppressWarnings(suppressMessages(as.rsi(disk, mo = "Escherichia coli", ab = "CIP"))),
suppressWarnings(suppressMessages(as.sir(disk, mo = "Escherichia coli", ab = "CIP"))))
expect_identical(suppressWarnings(suppressMessages(as.rsi(data.frame(CIP = mic, mo = "Escherichia coli")))),
suppressWarnings(suppressMessages(as.sir(data.frame(CIP = mic, mo = "Escherichia coli")))))
expect_identical(suppressWarnings(n_rsi(example_isolates$CIP)),
suppressWarnings(n_sir(example_isolates$CIP)))
expect_identical(suppressWarnings(rsi_df(example_isolates$CIP)),
suppressWarnings(sir_df(example_isolates$CIP)))
expect_identical(suppressWarnings(is.rsi.eligible(example_isolates)),
suppressWarnings(is_sir_eligible(example_isolates)))
if (pkg_is_available("ggplot2", also_load = FALSE)) {
expect_identical(suppressWarnings(ggplot_rsi(example_isolates[, c("CIP", "GEN", "TOB")])),
suppressWarnings(ggplot_sir(example_isolates[, c("CIP", "GEN", "TOB")])))
p <- ggplot2::ggplot(example_isolates[, c("CIP", "GEN", "TOB")])
expect_equal(suppressWarnings(p + geom_rsi() + scale_rsi_colours() + labels_rsi_count() + facet_rsi() + theme_rsi()),
suppressWarnings(p + geom_sir() + scale_sir_colours() + labels_sir_count() + facet_sir() + theme_sir()))
}

0
man/AMR-deprecated.Rd Executable file → Normal file
View File

0
man/AMR.Rd Executable file → Normal file
View File

0
man/WHOCC.Rd Executable file → Normal file
View File

0
man/WHONET.Rd Executable file → Normal file
View File

0
man/ab_from_text.Rd Executable file → Normal file
View File

0
man/ab_property.Rd Executable file → Normal file
View File

0
man/add_custom_antimicrobials.Rd Executable file → Normal file
View File

0
man/add_custom_microorganisms.Rd Executable file → Normal file
View File

0
man/age.Rd Executable file → Normal file
View File

0
man/age_groups.Rd Executable file → Normal file
View File

0
man/antibiotic_class_selectors.Rd Executable file → Normal file
View File

0
man/antibiotics.Rd Executable file → Normal file
View File

0
man/as.ab.Rd Executable file → Normal file
View File

0
man/as.av.Rd Executable file → Normal file
View File

0
man/as.disk.Rd Executable file → Normal file
View File

0
man/as.mic.Rd Executable file → Normal file
View File

0
man/as.mo.Rd Executable file → Normal file
View File

View File

@ -82,7 +82,7 @@ sir_interpretation_history(clean = FALSE)
\item{ab}{any (vector of) text that can be coerced to a valid antimicrobial drug code with \code{\link[=as.ab]{as.ab()}}} \item{ab}{any (vector of) text that can be coerced to a valid antimicrobial drug code with \code{\link[=as.ab]{as.ab()}}}
\item{guideline}{defaults to EUCAST 2022 (the latest implemented EUCAST guideline in the \link{clinical_breakpoints} data set), but can be set with the \link[=options]{option} \code{AMR_guideline}. Supports EUCAST (2013-2022) and CLSI (2013-2022), see \emph{Details}.} \item{guideline}{defaults to EUCAST 2022 (the latest implemented EUCAST guideline in the \link{clinical_breakpoints} data set), but can be set with the option \code{\link[=AMR-options]{AMR_guideline}}. Currently supports EUCAST (2013-2022) and CLSI (2013-2022), see \emph{Details}.}
\item{uti}{(Urinary Tract Infection) A vector with \link{logical}s (\code{TRUE} or \code{FALSE}) to specify whether a UTI specific interpretation from the guideline should be chosen. For using \code{\link[=as.sir]{as.sir()}} on a \link{data.frame}, this can also be a column containing \link{logical}s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See \emph{Examples}.} \item{uti}{(Urinary Tract Infection) A vector with \link{logical}s (\code{TRUE} or \code{FALSE}) to specify whether a UTI specific interpretation from the guideline should be chosen. For using \code{\link[=as.sir]{as.sir()}} on a \link{data.frame}, this can also be a column containing \link{logical}s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See \emph{Examples}.}

0
man/atc_online.Rd Executable file → Normal file
View File

0
man/av_from_text.Rd Executable file → Normal file
View File

0
man/av_property.Rd Executable file → Normal file
View File

0
man/availability.Rd Executable file → Normal file
View File

0
man/bug_drug_combinations.Rd Executable file → Normal file
View File

0
man/count.Rd Executable file → Normal file
View File

0
man/custom_eucast_rules.Rd Executable file → Normal file
View File

0
man/dosage.Rd Executable file → Normal file
View File

0
man/eucast_rules.Rd Executable file → Normal file
View File

0
man/example_isolates.Rd Executable file → Normal file
View File

0
man/example_isolates_unclean.Rd Executable file → Normal file
View File

0
man/first_isolate.Rd Executable file → Normal file
View File

0
man/g.test.Rd Executable file → Normal file
View File

0
man/get_episode.Rd Executable file → Normal file
View File

0
man/ggplot_pca.Rd Executable file → Normal file
View File

0
man/guess_ab_col.Rd Executable file → Normal file
View File

0
man/intrinsic_resistant.Rd Executable file → Normal file
View File

0
man/italicise_taxonomy.Rd Executable file → Normal file
View File

0
man/join.Rd Executable file → Normal file
View File

0
man/key_antimicrobials.Rd Executable file → Normal file
View File

0
man/kurtosis.Rd Executable file → Normal file
View File

0
man/like.Rd Executable file → Normal file
View File

0
man/mdro.Rd Executable file → Normal file
View File

0
man/mean_amr_distance.Rd Executable file → Normal file
View File

0
man/microorganisms.Rd Executable file → Normal file
View File

0
man/microorganisms.codes.Rd Executable file → Normal file
View File

0
man/mo_matching_score.Rd Executable file → Normal file
View File

0
man/mo_property.Rd Executable file → Normal file
View File

0
man/mo_source.Rd Executable file → Normal file
View File

0
man/pca.Rd Executable file → Normal file
View File

0
man/plot.Rd Executable file → Normal file
View File

0
man/proportion.Rd Executable file → Normal file
View File

0
man/random.Rd Executable file → Normal file
View File

0
man/resistance_predict.Rd Executable file → Normal file
View File

0
man/skewness.Rd Executable file → Normal file
View File

0
man/translate.Rd Executable file → Normal file
View File