Note: some changes in this version were suggested by anonymous reviewers from the journal we submitted our manuscipt about this package to. We are those reviewers very grateful for going through our code so thoroughly!
#' To improve the interpretation of the antibiogram before EUCAST rules are applied, some non-EUCAST rules can applied at default, see Details.
#' @inheritSection lifecycle Stable lifecycle
#' @param x data with antibiotic columns, such as `amox`, `AMX` and `AMC`
#' @param info print progress
#' @param info a logical to indicate whether progress should be printed to the console, defaults to only print while in interactive sessions
#' @param rules a character vector that specifies which rules should be applied. Must be one or more of `"breakpoints"`, `"expert"`, `"other"`, `"all"`, and defaults to `c("breakpoints", "expert")`. The default value can be set to another value, e.g. using `options(AMR_eucastrules = "all")`.
#' @param verbose a [logical] to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a data set in logbook form with extensive info about which rows and columns would be effected and in which way. Using Verbose mode takes a lot more time.
#' @param version_breakpoints the version number to use for the EUCAST Clinical Breakpoints guideline. Currently supported: `r paste0(names(EUCAST_VERSION_BREAKPOINTS), collapse = ", ")`.
@ -132,7 +132,7 @@ eucast_rules <- function(x,
...){
x_deparsed<-deparse(substitute(x))
if (length(x_deparsed)>0||!all(x_deparsed%like%"[a-z]")){
if (length(x_deparsed)>1||!all(x_deparsed%like%"[a-z]+")){
#' Determine which isolates are multidrug-resistant organisms (MDRO) according to international and national guidelines.
#' @inheritSection lifecycle Maturing lifecycle
#' @param guideline a specific guideline to follow. When left empty, the publication by Magiorakos *et al.* (2012, Clinical Microbiology and Infection) will be followed, please see *Details*.
#' @param info a logical to indicate whether progress should be printed to the console
#' @inheritParams eucast_rules
#' @param pct_required_classes minimal required percentage of antimicrobial classes that must be available per isolate, rounded down. For example, with the default guideline, 17 antimicrobial classes must be available for *S. aureus*. Setting this `pct_required_classes` argument to `0.5` (default) means that for every *S. aureus* isolate at least 8 different classes must be available. Any lower number of available classes will return `NA` for that isolate.
#' @param combine_SI a [logical] to indicate whether all values of S and I must be merged into one, so resistance is only considered when isolates are R, not I. As this is the default behaviour of the [mdro()] function, it follows the redefinition by EUCAST about the interpretation of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. When using `combine_SI = FALSE`, resistance is considered when isolates are R or I.
cat(font_blue(strwrap(c("Matching scores are based on human pathogenic prevalence and the resemblance between the input and the full taxonomic name. Please see ?mo_matching_score.")),collapse="\n"))
cat(font_blue(strwrap("Matching scores are based on human pathogenic prevalence and the resemblance between the input and the full taxonomic name. Please see ?mo_matching_score.",
#' @details The reference file can be a text file separated with commas (CSV) or tabs or pipes, an Excel file (either 'xls' or 'xlsx' format) or an R object file (extension '.rds'). To use an Excel file, you will need to have the `readxl` package installed.
#'
#' [set_mo_source()] will check the file for validity: it must be a [data.frame], must have a column named `"mo"` which contains values from [`microorganisms$mo`][microorganisms] and must have a reference column with your own defined values. If all tests pass, [set_mo_source()] will read the file into R and export it to `"~/.mo_source.rds"` after the user **specifically confirms and allows** that this file will be created. For this reason, this function only works in interactive sessions.
#' [set_mo_source()] will check the file for validity: it must be a [data.frame], must have a column named `"mo"` which contains values from [`microorganisms$mo`][microorganisms] and must have a reference column with your own defined values. If all tests pass, [set_mo_source()] will read the file into R and will ask to export it to `"~/.mo_source.rds"`. The CRAN policy disallows packages to write to the file system, although '*exceptions may be allowed in interactive sessions if the package obtains confirmation from the user*'. For this reason, this function only works in interactive sessions so that the user can **specifically confirm and allow** that this file will be created.
#'
#' The created compressed data file `"~/.mo_source.rds"` will be used at default for MO determination (function [as.mo()] and consequently all `mo_*` functions like [mo_genus()] and [mo_gramstain()]). The location of the original file will be saved as an R option with `options(mo_source = path)`. Its timestamp will be saved with `options(mo_source_datetime = ...)`.
<p><strong>Note:</strong> values on this page will change with every website update since they are based on randomly created values and the page was written in <ahref="https://rmarkdown.rstudio.com/">R Markdown</a>. However, the methodology remains unchanged. This page was generated on 03 September 2020.</p>
<p><strong>Note:</strong> values on this page will change with every website update since they are based on randomly created values and the page was written in <ahref="https://rmarkdown.rstudio.com/">R Markdown</a>. However, the methodology remains unchanged. This page was generated on 30 September 2020.</p>
<p>Because the amoxicillin (column <code>AMX</code>) and amoxicillin/clavulanic acid (column <code>AMC</code>) in our data were generated randomly, some rows will undoubtedly contain AMX = S and AMC = R, which is technically impossible. The <code><ahref="../reference/eucast_rules.html">eucast_rules()</a></code> fixes this:</p>
<spanclass="co"># NOTE: Using column `date` as input for `col_date`.</span>
<spanclass="co"># NOTE: Using column `patient_id` as input for `col_patient_id`.</span>
</pre></div>
<p>So only 28.6% is suitable for resistance analysis! We can now filter on it with the <code><ahref="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
<p>So only 28.5% is suitable for resistance analysis! We can now filter on it with the <code><ahref="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
<p>We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient M8, sorted on date:</p>
<p>We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient Z5, sorted on date:</p>
<tableclass="table">
<thead><trclass="header">
<thalign="center">isolate</th>
@ -548,76 +549,76 @@ Longest: 1</p>
<tbody>
<trclass="odd">
<tdalign="center">1</td>
<tdalign="center">2010-01-28</td>
<tdalign="center">M8</td>
<tdalign="center">2010-02-11</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="even">
<tdalign="center">2</td>
<tdalign="center">2010-05-23</td>
<tdalign="center">M8</td>
<tdalign="center">2010-04-11</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
</tr>
<trclass="odd">
<tdalign="center">3</td>
<tdalign="center">2010-07-11</td>
<tdalign="center">M8</td>
<tdalign="center">2010-05-31</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">I</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
</tr>
<trclass="even">
<tdalign="center">4</td>
<tdalign="center">2010-10-01</td>
<tdalign="center">M8</td>
<tdalign="center">2011-03-29</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="odd">
<tdalign="center">5</td>
<tdalign="center">2010-12-02</td>
<tdalign="center">M8</td>
<tdalign="center">2011-04-23</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
</tr>
<trclass="even">
<tdalign="center">6</td>
<tdalign="center">2010-12-23</td>
<tdalign="center">M8</td>
<tdalign="center">2011-05-06</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
</tr>
<trclass="odd">
<tdalign="center">7</td>
<tdalign="center">2011-01-16</td>
<tdalign="center">M8</td>
<tdalign="center">2011-09-05</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
@ -625,19 +626,19 @@ Longest: 1</p>
</tr>
<trclass="even">
<tdalign="center">8</td>
<tdalign="center">2011-03-14</td>
<tdalign="center">M8</td>
<tdalign="center">2011-09-29</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">TRUE</td>
<tdalign="center">FALSE</td>
</tr>
<trclass="odd">
<tdalign="center">9</td>
<tdalign="center">2011-04-02</td>
<tdalign="center">M8</td>
<tdalign="center">2011-11-16</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
@ -647,13 +648,13 @@ Longest: 1</p>
</tr>
<trclass="even">
<tdalign="center">10</td>
<tdalign="center">2011-04-05</td>
<tdalign="center">M8</td>
<tdalign="center">2011-11-26</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">FALSE</td>
</tr>
</tbody>
@ -686,35 +687,35 @@ Longest: 1</p>
<tbody>
<trclass="odd">
<tdalign="center">1</td>
<tdalign="center">2010-01-28</td>
<tdalign="center">M8</td>
<tdalign="center">2010-02-11</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">TRUE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="even">
<tdalign="center">2</td>
<tdalign="center">2010-05-23</td>
<tdalign="center">M8</td>
<tdalign="center">2010-04-11</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="odd">
<tdalign="center">3</td>
<tdalign="center">2010-07-11</td>
<tdalign="center">M8</td>
<tdalign="center">2010-05-31</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">I</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
@ -722,97 +723,97 @@ Longest: 1</p>
</tr>
<trclass="even">
<tdalign="center">4</td>
<tdalign="center">2010-10-01</td>
<tdalign="center">M8</td>
<tdalign="center">2011-03-29</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="odd">
<tdalign="center">5</td>
<tdalign="center">2010-12-02</td>
<tdalign="center">M8</td>
<tdalign="center">2011-04-23</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="even">
<tdalign="center">6</td>
<tdalign="center">2010-12-23</td>
<tdalign="center">M8</td>
<tdalign="center">2011-05-06</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="odd">
<tdalign="center">7</td>
<tdalign="center">2011-01-16</td>
<tdalign="center">M8</td>
<tdalign="center">2011-09-05</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="even">
<tdalign="center">8</td>
<tdalign="center">2011-03-14</td>
<tdalign="center">M8</td>
<tdalign="center">2011-09-29</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">TRUE</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="odd">
<tdalign="center">9</td>
<tdalign="center">2011-04-02</td>
<tdalign="center">M8</td>
<tdalign="center">2011-11-16</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">FALSE</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
</tr>
<trclass="even">
<tdalign="center">10</td>
<tdalign="center">2011-04-05</td>
<tdalign="center">M8</td>
<tdalign="center">2011-11-26</td>
<tdalign="center">Z5</td>
<tdalign="center">B_ESCHR_COLI</td>
<tdalign="center">R</td>
<tdalign="center">R</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">S</td>
<tdalign="center">R</td>
<tdalign="center">FALSE</td>
<tdalign="center">TRUE</td>
</tr>
</tbody>
</table>
<p>Instead of 2, now 8 isolates are flagged. In total, 79.1% of all isolates are marked โfirst weightedโ - 50.5% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.</p>
<p>Instead of 2, now 10 isolates are flagged. In total, 78.6% of all isolates are marked โfirst weightedโ - 50.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.</p>
<p>As with <code><ahref="../reference/first_isolate.html">filter_first_isolate()</a></code>, thereโs a shortcut for this new algorithm too:</p>