1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-25 06:46:11 +01:00

fix first isolate

This commit is contained in:
dr. M.S. (Matthijs) Berends 2023-02-10 13:13:17 +01:00
parent 1a0dc4bf46
commit 70a7ba0206
13 changed files with 222 additions and 56 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.8.2.9112 Version: 1.8.2.9113
Date: 2023-02-09 Date: 2023-02-10
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.9112 # AMR 1.8.2.9113
*(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!)*
@ -34,7 +34,6 @@ The help page for `antibiogram()` extensively elaborates on use cases, and `anti
Furthermore, different plotting methods were implemented to allow for graphical visualisations as well. Furthermore, different plotting methods were implemented to allow for graphical visualisations as well.
### Interpretation of MIC and disk diffusion values ### Interpretation of MIC and disk diffusion values
The clinical breakpoints and intrinsic resistance of EUCAST 2022 and CLSI 2022 have been added for `as.sir()`. EUCAST 2022 (v12.0) is now the new default guideline for all MIC and disks diffusion interpretations, and for `eucast_rules()` to apply EUCAST Expert Rules. The default guideline (EUCAST) can now be changed with the new `AMR_guideline` option, such as: `options(AMR_guideline = "CLSI 2020")`. The clinical breakpoints and intrinsic resistance of EUCAST 2022 and CLSI 2022 have been added for `as.sir()`. EUCAST 2022 (v12.0) is now the new default guideline for all MIC and disks diffusion interpretations, and for `eucast_rules()` to apply EUCAST Expert Rules. The default guideline (EUCAST) can now be changed with the new `AMR_guideline` option, such as: `options(AMR_guideline = "CLSI 2020")`.

View File

@ -33,7 +33,7 @@
#' @param x a [data.frame] containing isolates. Can be left blank for automatic determination, see *Examples*. #' @param x a [data.frame] containing isolates. Can be left blank for automatic determination, see *Examples*.
#' @param col_date column name of the result date (or date that is was received on the lab), defaults to the first column with a date class #' @param col_date column name of the result date (or date that is was received on the lab), defaults to the first column with a date class
#' @param col_patient_id column name of the unique IDs of the patients, defaults to the first column that starts with 'patient' or 'patid' (case insensitive) #' @param col_patient_id column name of the unique IDs of the patients, defaults to the first column that starts with 'patient' or 'patid' (case insensitive)
#' @param col_mo column name of the IDs of the microorganisms (see [as.mo()]), defaults to the first column of class [`mo`]. Values will be coerced using [as.mo()]. #' @param col_mo column name of the names or codes of the microorganisms (see [as.mo()]), defaults to the first column of class [`mo`]. Values will be coerced using [as.mo()].
#' @param col_testcode column name of the test codes. Use `col_testcode = NULL` to **not** exclude certain test codes (such as test codes for screening). In that case `testcodes_exclude` will be ignored. #' @param col_testcode column name of the test codes. Use `col_testcode = NULL` to **not** exclude certain test codes (such as test codes for screening). In that case `testcodes_exclude` will be ignored.
#' @param col_specimen column name of the specimen type or group #' @param col_specimen column name of the specimen type or group
#' @param col_icu column name of the logicals (`TRUE`/`FALSE`) whether a ward or department is an Intensive Care Unit (ICU). This can also be a [logical] vector with the same length as rows in `x`. #' @param col_icu column name of the logicals (`TRUE`/`FALSE`) whether a ward or department is an Intensive Care Unit (ICU). This can also be a [logical] vector with the same length as rows in `x`.
@ -133,7 +133,7 @@
#' # `example_isolates` is a data set available in the AMR package. #' # `example_isolates` is a data set available in the AMR package.
#' # See ?example_isolates. #' # See ?example_isolates.
#' #'
#' example_isolates[first_isolate(), ] #' example_isolates[first_isolate(info = TRUE), ]
#' \donttest{ #' \donttest{
#' # get all first Gram-negatives #' # get all first Gram-negatives
#' example_isolates[which(first_isolate(info = FALSE) & mo_is_gram_negative()), ] #' example_isolates[which(first_isolate(info = FALSE) & mo_is_gram_negative()), ]
@ -141,7 +141,7 @@
#' if (require("dplyr")) { #' if (require("dplyr")) {
#' # filter on first isolates using dplyr: #' # filter on first isolates using dplyr:
#' example_isolates %>% #' example_isolates %>%
#' filter(first_isolate()) #' filter(first_isolate(info = TRUE))
#' } #' }
#' if (require("dplyr")) { #' if (require("dplyr")) {
#' # short-hand version: #' # short-hand version:
@ -152,7 +152,7 @@
#' # flag the first isolates per group: #' # flag the first isolates per group:
#' example_isolates %>% #' example_isolates %>%
#' group_by(ward) %>% #' group_by(ward) %>%
#' mutate(first = first_isolate()) %>% #' mutate(first = first_isolate(info = TRUE)) %>%
#' select(ward, date, patient, mo, first) #' select(ward, date, patient, mo, first)
#' } #' }
#' } #' }
@ -468,14 +468,14 @@ first_isolate <- function(x = NULL,
x$other_pat_or_mo <- !(x$newvar_patient_id == pm_lag(x$newvar_patient_id) & x$newvar_genus_species == pm_lag(x$newvar_genus_species)) x$other_pat_or_mo <- !(x$newvar_patient_id == pm_lag(x$newvar_patient_id) & x$newvar_genus_species == pm_lag(x$newvar_genus_species))
x$episode_group <- paste(x$newvar_patient_id, x$newvar_genus_species) x$episode_group <- paste(x$newvar_patient_id, x$newvar_genus_species)
x$more_than_episode_ago <- unlist( x$more_than_episode_ago <- unlist(
lapply( lapply(
split( split(
x$newvar_date, x$newvar_date,
x$episode_group x$episode_group
), ),
exec_episode, # this will skip meet_criteria() in is_new_episode(), saving time is_new_episode,
type = "logical",
episode_days = episode_days episode_days = episode_days
), ),
use.names = FALSE use.names = FALSE
@ -490,24 +490,16 @@ first_isolate <- function(x = NULL,
ignore_I = ignore_I, ignore_I = ignore_I,
points_threshold = points_threshold points_threshold = points_threshold
) )
x$newvar_first_isolate <- pm_if_else( x$newvar_first_isolate <- x$newvar_row_index_sorted >= row.start &
x$newvar_row_index_sorted >= row.start & x$newvar_row_index_sorted <= row.end &
x$newvar_row_index_sorted <= row.end & x$newvar_genus_species != "" &
x$newvar_genus_species != "" & (x$other_pat_or_mo | x$more_than_episode_ago | x$other_key_ab)
(x$other_pat_or_mo | x$more_than_episode_ago | x$other_key_ab),
TRUE,
FALSE
)
} else { } else {
# no key antibiotics # no key antibiotics
x$newvar_first_isolate <- pm_if_else( x$newvar_first_isolate <- x$newvar_row_index_sorted >= row.start &
x$newvar_row_index_sorted >= row.start & x$newvar_row_index_sorted <= row.end &
x$newvar_row_index_sorted <= row.end & x$newvar_genus_species != "" &
x$newvar_genus_species != "" & (x$other_pat_or_mo | x$more_than_episode_ago)
(x$other_pat_or_mo | x$more_than_episode_ago),
TRUE,
FALSE
)
} }
# first one as TRUE # first one as TRUE
@ -516,14 +508,17 @@ first_isolate <- function(x = NULL,
if (!is.null(col_testcode)) { if (!is.null(col_testcode)) {
x[which(x[, col_testcode] %in% tolower(testcodes_exclude)), "newvar_first_isolate"] <- FALSE x[which(x[, col_testcode] %in% tolower(testcodes_exclude)), "newvar_first_isolate"] <- FALSE
} }
if (!is.null(col_icu)) { if (!is.null(col_icu)) {
if (icu_exclude == TRUE) { if (icu_exclude == TRUE) {
message_("Excluding ", format(sum(col_icu, na.rm = TRUE), big.mark = ","), " isolates from ICU.", if (isTRUE(info)) {
add_fn = font_black, message_("Excluding ", format(sum(col_icu, na.rm = TRUE), big.mark = ","), " isolates from ICU.",
as_note = FALSE add_fn = font_black,
) as_note = FALSE
)
}
x[which(col_icu), "newvar_first_isolate"] <- FALSE x[which(col_icu), "newvar_first_isolate"] <- FALSE
} else { } else if (isTRUE(info)) {
message_("Including isolates from ICU.", message_("Including isolates from ICU.",
add_fn = font_black, add_fn = font_black,
as_note = FALSE as_note = FALSE
@ -532,7 +527,7 @@ first_isolate <- function(x = NULL,
} }
decimal.mark <- getOption("OutDec") decimal.mark <- getOption("OutDec")
big.mark <- ifelse(decimal.mark != ",", ",", ".") big.mark <- ifelse(decimal.mark != ",", ",", " ")
if (isTRUE(info)) { if (isTRUE(info)) {
# print group name if used in dplyr::group_by() # print group name if used in dplyr::group_by()

View File

@ -29,7 +29,7 @@
#' Determine (New) Episodes for Patients #' Determine (New) Episodes for Patients
#' #'
#' These functions determine which items in a vector can be considered (the start of) a new episode, based on the argument `episode_days`. This can be used to determine clinical episodes for any epidemiological analysis. The [get_episode()] function returns the index number of the episode per group, while the [is_new_episode()] function returns values `TRUE`/`FALSE` for where [get_episode()] returns 1, and is thus equal to `get_episode(...) == 1`. #' These functions determine which items in a vector can be considered (the start of) a new episode, based on the argument `episode_days`. This can be used to determine clinical episodes for any epidemiological analysis. The [get_episode()] function returns the index number of the episode per group, while the [is_new_episode()] function returns `TRUE` for every new [get_episode()] index, and is thus equal to `!duplicated(get_episode(...))`.
#' @param x vector of dates (class `Date` or `POSIXt`), will be sorted internally to determine episodes #' @param x vector of dates (class `Date` or `POSIXt`), will be sorted internally to determine episodes
#' @param episode_days required episode length in days, can also be less than a day or `Inf`, see *Details* #' @param episode_days required episode length in days, can also be less than a day or `Inf`, see *Details*
#' @param ... ignored, only in place to allow future extensions #' @param ... ignored, only in place to allow future extensions
@ -83,7 +83,8 @@
#' patient, #' patient,
#' new_index = get_episode(date, 60), #' new_index = get_episode(date, 60),
#' new_logical = is_new_episode(date, 60) #' new_logical = is_new_episode(date, 60)
#' ) #' ) %>%
#' arrange(patient, ward, date)
#' } #' }
#' #'
#' if (require("dplyr")) { #' if (require("dplyr")) {
@ -109,12 +110,7 @@
get_episode <- function(x, episode_days, ...) { get_episode <- function(x, episode_days, ...) {
meet_criteria(x, allow_class = c("Date", "POSIXt"), allow_NA = TRUE) meet_criteria(x, allow_class = c("Date", "POSIXt"), allow_NA = TRUE)
meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = FALSE) meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = FALSE)
exec_episode(x, episode_days, ...)
exec_episode(
x = x,
episode_days = episode_days,
... = ...
)
} }
#' @rdname get_episode #' @rdname get_episode
@ -122,10 +118,10 @@ get_episode <- function(x, episode_days, ...) {
is_new_episode <- function(x, episode_days, ...) { is_new_episode <- function(x, episode_days, ...) {
meet_criteria(x, allow_class = c("Date", "POSIXt"), allow_NA = TRUE) meet_criteria(x, allow_class = c("Date", "POSIXt"), allow_NA = TRUE)
meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = FALSE) meet_criteria(episode_days, allow_class = c("numeric", "integer"), has_length = 1, is_positive = TRUE, is_finite = FALSE)
get_episode(x, episode_days, ...) == 1 !duplicated(exec_episode(x, episode_days, ...))
} }
exec_episode <- function(x, type, episode_days, ...) { exec_episode <- function(x, episode_days, ...) {
x <- as.double(as.POSIXct(x)) # as.POSIXct() required for Date classes x <- as.double(as.POSIXct(x)) # as.POSIXct() required for Date classes
# since x is now in seconds, get seconds from episode_days as well # since x is now in seconds, get seconds from episode_days as well

View File

@ -0,0 +1,175 @@
# ==================================================================== #
# TITLE #
# AMR: An R Package for Working with Antimicrobial Resistance Data #
# #
# SOURCE #
# https://github.com/msberends/AMR #
# #
# CITE AS #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. #
# doi:10.18637/jss.v104.i03 #
# #
# Developed at the University of Groningen and the University Medical #
# Center Groningen in The Netherlands, in collaboration with many #
# colleagues from around the world, see our website. #
# #
# 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. #
# 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. #
# #
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_identical(as.mo("Enterobacter asburiae/cloacae"),
as.mo("Enterobacter asburiae"))
suppressMessages(
add_custom_microorganisms(
data.frame(mo = "ENT_ASB_CLO",
genus = "Enterobacter",
species = "asburiae/cloacae")
)
)
expect_identical(as.character(as.mo("ENT_ASB_CLO")), "ENT_ASB_CLO")
expect_identical(mo_name("ENT_ASB_CLO"), "Enterobacter asburiae/cloacae")
expect_identical(mo_gramstain("ENT_ASB_CLO", language = NULL), "Gram-negative")
# ==================================================================== #
# TITLE #
# AMR: An R Package for Working with Antimicrobial Resistance Data #
# #
# SOURCE #
# https://github.com/msberends/AMR #
# #
# CITE AS #
# Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C #
# (2022). AMR: An R Package for Working with Antimicrobial Resistance #
# Data. Journal of Statistical Software, 104(3), 1-31. #
# doi:10.18637/jss.v104.i03 #
# #
# Developed at the University of Groningen and the University Medical #
# Center Groningen in The Netherlands, in collaboration with many #
# colleagues from around the world, see our website. #
# #
# 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. #
# 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. #
# #
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
#
#
# # Traditional antibiogram ----------------------------------------------
#
# ab1 <- antibiogram(example_isolates,
# antibiotics = c(aminoglycosides(), carbapenems()))
#
# ab2 <- antibiogram(example_isolates,
# antibiotics = aminoglycosides(),
# ab_transform = "atc",
# mo_transform = "gramstain")
#
# ab3 <- antibiogram(example_isolates,
# antibiotics = carbapenems(),
# ab_transform = "name",
# mo_transform = "name")
#
# expect_inherits(ab1, "antibiogram")
# expect_inherits(ab2, "antibiogram")
# expect_inherits(ab3, "antibiogram")
# expect_equal(colnames(ab1), c("Pathogen (N min-max)", "AMK", "GEN", "IPM", "KAN", "MEM", "TOB"))
# expect_equal(colnames(ab2), c("Pathogen (N min-max)", "J01GB01", "J01GB03", "J01GB04", "J01GB06"))
# expect_equal(colnames(ab3), c("Pathogen (N min-max)", "Imipenem", "Meropenem"))
# expect_equal(ab3$Meropenem, c(52, NA, 100, 100, NA))
#
# # Combined antibiogram -------------------------------------------------
#
# # combined antibiotics yield higher empiric coverage
# ab4 <- antibiogram(example_isolates,
# antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
# mo_transform = "gramstain")
#
# ab5 <- antibiogram(example_isolates,
# antibiotics = c("TZP", "TZP+TOB"),
# mo_transform = "gramstain",
# ab_transform = "name",
# sep = " & ",
# add_total_n = FALSE)
#
# expect_inherits(ab4, "antibiogram")
# expect_inherits(ab5, "antibiogram")
# expect_equal(colnames(ab4), c("Pathogen (N min-max)", "TZP", "TZP + GEN", "TZP + TOB"))
# expect_equal(colnames(ab5), c("Pathogen", "Piperacillin/tazobactam", "Piperacillin/tazobactam & Tobramycin"))
#
# # Syndromic antibiogram ------------------------------------------------
#
# # the data set could contain a filter for e.g. respiratory specimens
# ab6 <- antibiogram(example_isolates,
# antibiotics = c(aminoglycosides(), carbapenems()),
# syndromic_group = "ward")
#
# # with a custom language, though this will be determined automatically
# # (i.e., this table will be in Spanish on Spanish systems)
# ex1 <- example_isolates[which(mo_genus() == "Escherichia"), ]
# ab7 <- antibiogram(ex1,
# antibiotics = aminoglycosides(),
# ab_transform = "name",
# syndromic_group = ifelse(ex1$ward == "ICU",
# "UCI", "No UCI"),
# language = "es")
#
# expect_inherits(ab6, "antibiogram")
# expect_inherits(ab7, "antibiogram")
# expect_equal(colnames(ab6), c("Syndromic Group", "Pathogen (N min-max)", "AMK", "GEN", "IPM", "KAN", "MEM", "TOB"))
# expect_equal(colnames(ab7), c("Grupo sindrómico", "Patógeno (N min-max)", "Amikacina", "Gentamicina", "Tobramicina"))
#
# # Weighted-incidence syndromic combination antibiogram (WISCA) ---------
#
# # the data set could contain a filter for e.g. respiratory specimens
# ab8 <- antibiogram(example_isolates,
# antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"),
# mo_transform = "gramstain",
# minimum = 10, # this should be >= 30, but now just as example
# syndromic_group = ifelse(example_isolates$age >= 65 &
# example_isolates$gender == "M",
# "WISCA Group 1", "WISCA Group 2"))
#
# expect_inherits(ab8, "antibiogram")
# expect_equal(colnames(ab8), c("Syndromic Group", "Pathogen (N min-max)", "AMC", "AMC + CIP", "TZP", "TZP + TOB"))
#
# # Generate plots with ggplot2 or base R --------------------------------
#
# pdf(NULL) # prevent Rplots.pdf being created
#
# expect_silent(plot(ab1))
# expect_silent(plot(ab2))
# expect_silent(plot(ab3))
# expect_silent(plot(ab4))
# expect_silent(plot(ab5))
# expect_silent(plot(ab6))
# expect_silent(plot(ab7))
# expect_silent(plot(ab8))
#
# if (AMR:::pkg_is_available("ggplot2")) {
# expect_inherits(autoplot(ab1), "gg")
# expect_inherits(autoplot(ab2), "gg")
# expect_inherits(autoplot(ab3), "gg")
# expect_inherits(autoplot(ab4), "gg")
# expect_inherits(autoplot(ab5), "gg")
# expect_inherits(autoplot(ab6), "gg")
# expect_inherits(autoplot(ab7), "gg")
# expect_inherits(autoplot(ab8), "gg")
# }

View File

@ -110,7 +110,7 @@ not_intrinsic_resistant(
\item{filter}{an \link{expression} to be evaluated in the \link{antibiotics} data set, such as \code{name \%like\% "trim"}} \item{filter}{an \link{expression} to be evaluated in the \link{antibiotics} data set, such as \code{name \%like\% "trim"}}
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{version_expertrules}{the version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be either "3.3", "3.2" or "3.1".} \item{version_expertrules}{the version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be either "3.3", "3.2" or "3.1".}
} }

View File

@ -94,7 +94,7 @@ sir_interpretation_history(clean = FALSE)
\item{include_PKPD}{a \link{logical} to indicate that PK/PD clinical breakpoints must be applied as a last resort, defaults to \code{TRUE}. Can also be set with the option \code{\link[=AMR-options]{AMR_include_PKPD}}.} \item{include_PKPD}{a \link{logical} to indicate that PK/PD clinical breakpoints must be applied as a last resort, defaults to \code{TRUE}. Can also be set with the option \code{\link[=AMR-options]{AMR_include_PKPD}}.}
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{clean}{a \link{logical} to indicate whether previously stored results should be forgotten after returning the 'logbook' with results} \item{clean}{a \link{logical} to indicate whether previously stored results should be forgotten after returning the 'logbook' with results}
} }

View File

@ -23,7 +23,7 @@ bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname, ...)
\arguments{ \arguments{
\item{x}{a data set with antibiotic columns, such as \code{amox}, \code{AMX} and \code{AMC}} \item{x}{a data set with antibiotic columns, such as \code{amox}, \code{AMX} and \code{AMC}}
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{FUN}{the function to call on the \code{mo} column to transform the microorganism codes, defaults to \code{\link[=mo_shortname]{mo_shortname()}}} \item{FUN}{the function to call on the \code{mo} column to transform the microorganism codes, defaults to \code{\link[=mo_shortname]{mo_shortname()}}}

View File

@ -38,7 +38,7 @@ eucast_dosage(ab, administration = "iv", version_breakpoints = 12)
\arguments{ \arguments{
\item{x}{a data set with antibiotic columns, such as \code{amox}, \code{AMX} and \code{AMC}} \item{x}{a data set with antibiotic columns, such as \code{amox}, \code{AMX} and \code{AMC}}
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{info}{a \link{logical} to indicate whether progress should be printed to the console, defaults to only print while in interactive sessions} \item{info}{a \link{logical} to indicate whether progress should be printed to the console, defaults to only print while in interactive sessions}

View File

@ -52,7 +52,7 @@ filter_first_isolate(
\item{col_patient_id}{column name of the unique IDs of the patients, defaults to the first column that starts with 'patient' or 'patid' (case insensitive)} \item{col_patient_id}{column name of the unique IDs of the patients, defaults to the first column that starts with 'patient' or 'patid' (case insensitive)}
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{col_testcode}{column name of the test codes. Use \code{col_testcode = NULL} to \strong{not} exclude certain test codes (such as test codes for screening). In that case \code{testcodes_exclude} will be ignored.} \item{col_testcode}{column name of the test codes. Use \code{col_testcode = NULL} to \strong{not} exclude certain test codes (such as test codes for screening). In that case \code{testcodes_exclude} will be ignored.}
@ -168,7 +168,7 @@ The default method is phenotype-based (using \code{type = "points"}) and episode
# `example_isolates` is a data set available in the AMR package. # `example_isolates` is a data set available in the AMR package.
# See ?example_isolates. # See ?example_isolates.
example_isolates[first_isolate(), ] example_isolates[first_isolate(info = TRUE), ]
\donttest{ \donttest{
# get all first Gram-negatives # get all first Gram-negatives
example_isolates[which(first_isolate(info = FALSE) & mo_is_gram_negative()), ] example_isolates[which(first_isolate(info = FALSE) & mo_is_gram_negative()), ]
@ -176,7 +176,7 @@ example_isolates[which(first_isolate(info = FALSE) & mo_is_gram_negative()), ]
if (require("dplyr")) { if (require("dplyr")) {
# filter on first isolates using dplyr: # filter on first isolates using dplyr:
example_isolates \%>\% example_isolates \%>\%
filter(first_isolate()) filter(first_isolate(info = TRUE))
} }
if (require("dplyr")) { if (require("dplyr")) {
# short-hand version: # short-hand version:
@ -187,7 +187,7 @@ if (require("dplyr")) {
# flag the first isolates per group: # flag the first isolates per group:
example_isolates \%>\% example_isolates \%>\%
group_by(ward) \%>\% group_by(ward) \%>\%
mutate(first = first_isolate()) \%>\% mutate(first = first_isolate(info = TRUE)) \%>\%
select(ward, date, patient, mo, first) select(ward, date, patient, mo, first)
} }
} }

View File

@ -23,7 +23,7 @@ is_new_episode(x, episode_days, ...)
} }
} }
\description{ \description{
These functions determine which items in a vector can be considered (the start of) a new episode, based on the argument \code{episode_days}. This can be used to determine clinical episodes for any epidemiological analysis. The \code{\link[=get_episode]{get_episode()}} function returns the index number of the episode per group, while the \code{\link[=is_new_episode]{is_new_episode()}} function returns values \code{TRUE}/\code{FALSE} for where \code{\link[=get_episode]{get_episode()}} returns 1, and is thus equal to \code{get_episode(...) == 1}. These functions determine which items in a vector can be considered (the start of) a new episode, based on the argument \code{episode_days}. This can be used to determine clinical episodes for any epidemiological analysis. The \code{\link[=get_episode]{get_episode()}} function returns the index number of the episode per group, while the \code{\link[=is_new_episode]{is_new_episode()}} function returns \code{TRUE} for every new \code{\link[=get_episode]{get_episode()}} index, and is thus equal to \code{!duplicated(get_episode(...))}.
} }
\details{ \details{
Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least \code{episode_days} days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least \code{episode_days} days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored. Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least \code{episode_days} days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least \code{episode_days} days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored.
@ -70,7 +70,8 @@ if (require("dplyr")) {
patient, patient,
new_index = get_episode(date, 60), new_index = get_episode(date, 60),
new_logical = is_new_episode(date, 60) new_logical = is_new_episode(date, 60)
) ) \%>\%
arrange(patient, ward, date)
} }
if (require("dplyr")) { if (require("dplyr")) {

View File

@ -35,7 +35,7 @@ antimicrobials_equal(
\arguments{ \arguments{
\item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank to determine automatically} \item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank to determine automatically}
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{universal}{names of \strong{broad-spectrum} antimicrobial drugs, case-insensitive. Set to \code{NULL} to ignore. See \emph{Details} for the default antimicrobial drugs} \item{universal}{names of \strong{broad-spectrum} antimicrobial drugs, case-insensitive. Set to \code{NULL} to ignore. See \emph{Details} for the default antimicrobial drugs}

View File

@ -48,7 +48,7 @@ eucast_exceptional_phenotypes(x = NULL, only_sir_columns = FALSE, ...)
\item{guideline}{a specific guideline to follow, see sections \emph{Supported international / national guidelines} and \emph{Using Custom Guidelines} below. When left empty, the publication by Magiorakos \emph{et al.} (see below) will be followed.} \item{guideline}{a specific guideline to follow, see sections \emph{Supported international / national guidelines} and \emph{Using Custom Guidelines} below. When left empty, the publication by Magiorakos \emph{et al.} (see below) will be followed.}
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
\item{info}{a \link{logical} to indicate whether progress should be printed to the console, defaults to only print while in interactive sessions} \item{info}{a \link{logical} to indicate whether progress should be printed to the console, defaults to only print while in interactive sessions}