From 29b0ef1089705acb1fc3a4313714d52ac12f326a Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Fri, 18 Apr 2025 16:03:50 +0200 Subject: [PATCH] (v2.1.1.9242) sir log --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/sir.R | 89 +++++++++---------- ....txt => gpt_training_text_v2.1.1.9242.txt} | 4 +- man/as.sir.Rd | 2 +- 5 files changed, 49 insertions(+), 50 deletions(-) rename data-raw/{gpt_training_text_v2.1.1.9241.txt => gpt_training_text_v2.1.1.9242.txt} (99%) diff --git a/DESCRIPTION b/DESCRIPTION index 5079746a0..ec2b8c8db 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 2.1.1.9241 +Version: 2.1.1.9242 Date: 2025-04-18 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index a44d0b2f5..d5b6979a8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.1.1.9241 +# AMR 2.1.1.9242 *(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://amr-for-r.org/#get-this-package).)* diff --git a/R/sir.R b/R/sir.R index aae9bc555..c91dbece9 100755 --- a/R/sir.R +++ b/R/sir.R @@ -111,7 +111,7 @@ #' #' 4. For **interpreting a complete data set**, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running `as.sir(your_data)`. #' -#' **For points 2, 3 and 4: Use [sir_interpretation_history()]** to retrieve a [data.frame] (or [tibble][tibble::tibble()] if the `tibble` package is installed) with all results of the last [as.sir()] call. +#' **For points 2, 3 and 4: Use [sir_interpretation_history()]** to retrieve a [data.frame] with all results of all previous [as.sir()] calls. It also contains notes about interpretation, and the exact input and output values. #' #' ### Supported Guidelines #' @@ -1506,30 +1506,29 @@ as_sir_method <- function(method_short, } if (NROW(breakpoints_current) == 0) { - AMR_env$sir_interpretation_history <- rbind_AMR( - AMR_env$sir_interpretation_history, + out <- data.frame( # recycling 1 to 2 rows does not always seem to work, which is why vectorise_log_entry() was added - data.frame( - datetime = vectorise_log_entry(Sys.time(), length(rows)), - index = rows, - method = vectorise_log_entry(method_coerced, length(rows)), - ab_given = vectorise_log_entry(ab.bak[match(ab_current, df$ab)][1], length(rows)), - mo_given = vectorise_log_entry(mo.bak[match(mo_current, df$mo)][1], length(rows)), - host_given = vectorise_log_entry(host.bak[match(host_current, df$host)][1], length(rows)), - input_given = vectorise_log_entry(as.character(values_bak), length(rows)), - ab = vectorise_log_entry(ab_current, length(rows)), - mo = vectorise_log_entry(mo_current, length(rows)), - host = vectorise_log_entry(host_current, length(rows)), - input = vectorise_log_entry(as.character(values), length(rows)), - outcome = vectorise_log_entry(NA_sir_, length(rows)), - notes = vectorise_log_entry("No breakpoint available", length(rows)), - guideline = vectorise_log_entry(guideline_current, length(rows)), - ref_table = vectorise_log_entry(NA_character_, length(rows)), - uti = vectorise_log_entry(uti_current, length(rows)), - breakpoint_S_R = vectorise_log_entry(NA_character_, length(rows)), - stringsAsFactors = FALSE - ) + datetime = vectorise_log_entry(Sys.time(), length(rows)), + index = rows, + method = vectorise_log_entry(method_coerced, length(rows)), + ab_given = vectorise_log_entry(ab.bak[match(ab_current, df$ab)][1], length(rows)), + mo_given = vectorise_log_entry(mo.bak[match(mo_current, df$mo)][1], length(rows)), + host_given = vectorise_log_entry(host.bak[match(host_current, df$host)][1], length(rows)), + input_given = vectorise_log_entry(as.character(values_bak), length(rows)), + ab = vectorise_log_entry(ab_current, length(rows)), + mo = vectorise_log_entry(mo_current, length(rows)), + host = vectorise_log_entry(host_current, length(rows)), + input = vectorise_log_entry(as.character(values), length(rows)), + outcome = vectorise_log_entry(NA_sir_, length(rows)), + notes = vectorise_log_entry("No breakpoint available", length(rows)), + guideline = vectorise_log_entry(guideline_current, length(rows)), + ref_table = vectorise_log_entry(NA_character_, length(rows)), + uti = vectorise_log_entry(uti_current, length(rows)), + breakpoint_S_R = vectorise_log_entry(NA_character_, length(rows)), + stringsAsFactors = FALSE ) + out <- subset(out, !is.na(input_given)) + AMR_env$sir_interpretation_history <- rbind_AMR(AMR_env$sir_interpretation_history, out) notes <- c(notes, notes_current) next } @@ -1636,6 +1635,7 @@ as_sir_method <- function(method_short, ) } + ## actual interpretation ---- if (method == "mic") { new_sir <- case_when_AMR( is.na(values) ~ NA_sir_, @@ -1668,30 +1668,29 @@ as_sir_method <- function(method_short, # write to verbose output notes_current <- trimws2(notes_current) notes_current[notes_current == ""] <- NA_character_ - AMR_env$sir_interpretation_history <- rbind_AMR( - AMR_env$sir_interpretation_history, + out <- data.frame( # recycling 1 to 2 rows does not always seem to work, which is why vectorise_log_entry() was added - data.frame( - datetime = vectorise_log_entry(Sys.time(), length(rows)), - index = rows, - method = vectorise_log_entry(method_coerced, length(rows)), - ab_given = vectorise_log_entry(ab.bak[match(ab_current, df$ab)][1], length(rows)), - mo_given = vectorise_log_entry(mo.bak[match(mo_current, df$mo)][1], length(rows)), - host_given = vectorise_log_entry(host.bak[match(host_current, df$host)][1], length(rows)), - input_given = vectorise_log_entry(as.character(values_bak), length(rows)), - ab = vectorise_log_entry(breakpoints_current[, "ab", drop = TRUE], length(rows)), - mo = vectorise_log_entry(breakpoints_current[, "mo", drop = TRUE], length(rows)), - host = vectorise_log_entry(breakpoints_current[, "host", drop = TRUE], length(rows)), - input = vectorise_log_entry(as.character(values), length(rows)), - outcome = vectorise_log_entry(as.sir(new_sir), length(rows)), - notes = font_stripstyle(notes_current), # vectorise_log_entry(paste0(font_stripstyle(notes_current), collapse = "\n"), length(rows)), - guideline = vectorise_log_entry(guideline_current, length(rows)), - ref_table = vectorise_log_entry(breakpoints_current[, "ref_tbl", drop = TRUE], length(rows)), - uti = vectorise_log_entry(breakpoints_current[, "uti", drop = TRUE], length(rows)), - breakpoint_S_R = vectorise_log_entry(paste0(breakpoints_current[, "breakpoint_S", drop = TRUE], "-", breakpoints_current[, "breakpoint_R", drop = TRUE]), length(rows)), - stringsAsFactors = FALSE - ) + datetime = vectorise_log_entry(Sys.time(), length(rows)), + index = rows, + method = vectorise_log_entry(method_coerced, length(rows)), + ab_given = vectorise_log_entry(ab.bak[match(ab_current, df$ab)][1], length(rows)), + mo_given = vectorise_log_entry(mo.bak[match(mo_current, df$mo)][1], length(rows)), + host_given = vectorise_log_entry(host.bak[match(host_current, df$host)][1], length(rows)), + input_given = vectorise_log_entry(as.character(values_bak), length(rows)), + ab = vectorise_log_entry(breakpoints_current[, "ab", drop = TRUE], length(rows)), + mo = vectorise_log_entry(breakpoints_current[, "mo", drop = TRUE], length(rows)), + host = vectorise_log_entry(breakpoints_current[, "host", drop = TRUE], length(rows)), + input = vectorise_log_entry(as.character(values), length(rows)), + outcome = vectorise_log_entry(as.sir(new_sir), length(rows)), + notes = font_stripstyle(notes_current), # vectorise_log_entry(paste0(font_stripstyle(notes_current), collapse = "\n"), length(rows)), + guideline = vectorise_log_entry(guideline_current, length(rows)), + ref_table = vectorise_log_entry(breakpoints_current[, "ref_tbl", drop = TRUE], length(rows)), + uti = vectorise_log_entry(breakpoints_current[, "uti", drop = TRUE], length(rows)), + breakpoint_S_R = vectorise_log_entry(paste0(breakpoints_current[, "breakpoint_S", drop = TRUE], "-", breakpoints_current[, "breakpoint_R", drop = TRUE]), length(rows)), + stringsAsFactors = FALSE ) + out <- subset(out, !is.na(input_given)) + AMR_env$sir_interpretation_history <- rbind_AMR(AMR_env$sir_interpretation_history, out) } notes <- c(notes, notes_current) diff --git a/data-raw/gpt_training_text_v2.1.1.9241.txt b/data-raw/gpt_training_text_v2.1.1.9242.txt similarity index 99% rename from data-raw/gpt_training_text_v2.1.1.9241.txt rename to data-raw/gpt_training_text_v2.1.1.9242.txt index 988349482..e60de1ac6 100644 --- a/data-raw/gpt_training_text_v2.1.1.9241.txt +++ b/data-raw/gpt_training_text_v2.1.1.9242.txt @@ -1,6 +1,6 @@ This knowledge base contains all context you must know about the AMR package for R. You are a GPT trained to be an assistant for the AMR package in R. You are an incredible R specialist, especially trained in this package and in the tidyverse. -First and foremost, you are trained on version 2.1.1.9241. Remember this whenever someone asks which AMR package version you’re at. +First and foremost, you are trained on version 2.1.1.9242. Remember this whenever someone asks which AMR package version you’re at. Below are the contents of the NAMESPACE file, the index.md file, and all the man/*.Rd files (documentation) in the package. Every file content is split using 100 hypens. ---------------------------------------------------------------------------------------------------- @@ -3567,7 +3567,7 @@ your_data \%>\% mutate_if(is.disk, as.sir, host = "column_with_animal_species", \item For \strong{interpreting a complete data set}, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running \code{as.sir(your_data)}. } -\strong{For points 2, 3 and 4: Use \code{\link[=sir_interpretation_history]{sir_interpretation_history()}}} to retrieve a \link{data.frame} (or \link[tibble:tibble]{tibble} if the \code{tibble} package is installed) with all results of the last \code{\link[=as.sir]{as.sir()}} call. +\strong{For points 2, 3 and 4: Use \code{\link[=sir_interpretation_history]{sir_interpretation_history()}}} to retrieve a \link{data.frame} with all results of all previous \code{\link[=as.sir]{as.sir()}} calls. It also contains notes about interpretation, and the exact input and output values. } \subsection{Supported Guidelines}{ diff --git a/man/as.sir.Rd b/man/as.sir.Rd index 5a47ad419..ca086d95b 100644 --- a/man/as.sir.Rd +++ b/man/as.sir.Rd @@ -191,7 +191,7 @@ your_data \%>\% mutate_if(is.disk, as.sir, host = "column_with_animal_species", \item For \strong{interpreting a complete data set}, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running \code{as.sir(your_data)}. } -\strong{For points 2, 3 and 4: Use \code{\link[=sir_interpretation_history]{sir_interpretation_history()}}} to retrieve a \link{data.frame} (or \link[tibble:tibble]{tibble} if the \code{tibble} package is installed) with all results of the last \code{\link[=as.sir]{as.sir()}} call. +\strong{For points 2, 3 and 4: Use \code{\link[=sir_interpretation_history]{sir_interpretation_history()}}} to retrieve a \link{data.frame} with all results of all previous \code{\link[=as.sir]{as.sir()}} calls. It also contains notes about interpretation, and the exact input and output values. } \subsection{Supported Guidelines}{