(v1.8.1.9005) as.rsi() fix for EUCAST

This commit is contained in:
2022-05-10 17:01:37 +02:00
parent d4e22069bc
commit 680e8e7a41
21 changed files with 7475 additions and 7454 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.8.1.9004 Version: 1.8.1.9005
Date: 2022-05-09 Date: 2022-05-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
+3 -2
View File
@@ -1,7 +1,8 @@
# `AMR` 1.8.1.9004 # `AMR` 1.8.1.9005
## <small>Last updated: 9 May 2022</small> ## <small>Last updated: 10 May 2022</small>
### Changed ### Changed
* Fix for `as.rsi()` on certain EUCAST breakpoints for MIC values
* Removed `as.integer()` for MIC values, since MIC are not integer values and running `table()` on MIC values consequently failed for not being able to retrieve the level position (as that's how normally `as.integer()` on `factor`s work) * Removed `as.integer()` for MIC values, since MIC are not integer values and running `table()` on MIC values consequently failed for not being able to retrieve the level position (as that's how normally `as.integer()` on `factor`s work)
* `droplevels()` on MIC will now return a common `factor` at default and will lose the `<mic>` class. Use `droplevels(..., as.mic = TRUE)` to keep the `<mic>` class. * `droplevels()` on MIC will now return a common `factor` at default and will lose the `<mic>` class. Use `droplevels(..., as.mic = TRUE)` to keep the `<mic>` class.
* Small fix for using `ab_from_text()` * Small fix for using `ab_from_text()`
+7 -5
View File
@@ -818,18 +818,20 @@ exec_as.rsi <- function(method,
if (is.na(x[i]) | (is.na(get_record$breakpoint_S) & is.na(get_record$breakpoint_R))) { if (is.na(x[i]) | (is.na(get_record$breakpoint_S) & is.na(get_record$breakpoint_R))) {
new_rsi[i] <- NA_character_ new_rsi[i] <- NA_character_
} else if (method == "mic") { } else if (method == "mic") {
new_rsi[i] <- quick_case_when(isTRUE(conserve_capped_values) & x[i] %like% "^<[0-9]" ~ "S", new_rsi[i] <- quick_case_when(isTRUE(conserve_capped_values) & isTRUE(x[i] %like% "^<[0-9]") ~ "S",
isTRUE(conserve_capped_values) & x[i] %like% "^>[0-9]" ~ "R", isTRUE(conserve_capped_values) & isTRUE(x[i] %like% "^>[0-9]") ~ "R",
# these basically call `<=.mic()` and `>=.mic()`: # these basically call `<=.mic()` and `>=.mic()`:
x[i] <= get_record$breakpoint_S ~ "S", isTRUE(x[i] <= get_record$breakpoint_S) ~ "S",
x[i] >= get_record$breakpoint_R ~ "R", guideline_coerced %like% "EUCAST" & isTRUE(x[i] > get_record$breakpoint_R) ~ "R",
guideline_coerced %like% "CLSI" & isTRUE(x[i] >= get_record$breakpoint_R) ~ "R",
# return "I" when not match the bottom or top # return "I" when not match the bottom or top
!is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I", !is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I",
# and NA otherwise # and NA otherwise
TRUE ~ NA_character_) TRUE ~ NA_character_)
} else if (method == "disk") { } else if (method == "disk") {
new_rsi[i] <- quick_case_when(isTRUE(as.double(x[i]) >= as.double(get_record$breakpoint_S)) ~ "S", new_rsi[i] <- quick_case_when(isTRUE(as.double(x[i]) >= as.double(get_record$breakpoint_S)) ~ "S",
isTRUE(as.double(x[i]) <= as.double(get_record$breakpoint_R)) ~ "R", guideline_coerced %like% "EUCAST" & isTRUE(as.double(x[i]) < as.double(get_record$breakpoint_R)) ~ "R",
guideline_coerced %like% "CLSI" & isTRUE(as.double(x[i]) <= as.double(get_record$breakpoint_R)) ~ "R",
# return "I" when not match the bottom or top # return "I" when not match the bottom or top
!is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I", !is.na(get_record$breakpoint_S) & !is.na(get_record$breakpoint_R) ~ "I",
# and NA otherwise # and NA otherwise
Binary file not shown.
+14 -1
View File
@@ -128,11 +128,24 @@ rsi_translation[which(rsi_translation$breakpoint_R == 257), "breakpoint_R"] <- m
rsi_translation[which(rsi_translation$breakpoint_R == 513), "breakpoint_R"] <- m[which(m == 512) + 1] rsi_translation[which(rsi_translation$breakpoint_R == 513), "breakpoint_R"] <- m[which(m == 512) + 1]
rsi_translation[which(rsi_translation$breakpoint_R == 1025), "breakpoint_R"] <- m[which(m == 1024) + 1] rsi_translation[which(rsi_translation$breakpoint_R == 1025), "breakpoint_R"] <- m[which(m == 1024) + 1]
# WHONET adds one log2 level to the R breakpoint for their software, e.g. in AMC in Enterobacterales:
# EUCAST 2021 guideline: S <= 8 and R > 8
# WHONET file: S <= 8 and R >= 16
# this will make an MIC of 12 I, which should be R, so:
eucast_mics <- which(rsi_translation$guideline %like% "EUCAST" &
rsi_translation$method == "MIC" &
log2(as.double(rsi_translation$breakpoint_R)) - log2(as.double(rsi_translation$breakpoint_S)) != 0)
rsi_translation[eucast_mics, "breakpoint_R"] <- 2 ^ (log2(as.double(rsi_translation[eucast_mics, "breakpoint_R", drop = TRUE])) - 1)
eucast_disks <- which(rsi_translation$guideline %like% "EUCAST" &
rsi_translation$method == "DISK" &
rsi_translation$breakpoint_S - rsi_translation$breakpoint_R != 0)
rsi_translation[eucast_disks, "breakpoint_R"] <- rsi_translation[eucast_disks, "breakpoint_R", drop = TRUE] + 1
# Greek symbols and EM dash symbols are not allowed by CRAN, so replace them with ASCII: # Greek symbols and EM dash symbols are not allowed by CRAN, so replace them with ASCII:
rsi_translation$disk_dose <- gsub("μ", "u", rsi_translation$disk_dose, fixed = TRUE) rsi_translation$disk_dose <- gsub("μ", "u", rsi_translation$disk_dose, fixed = TRUE)
rsi_translation$disk_dose <- gsub("", "-", rsi_translation$disk_dose, fixed = TRUE) rsi_translation$disk_dose <- gsub("", "-", rsi_translation$disk_dose, fixed = TRUE)
# save to package # save to package
usethis::use_data(rsi_translation, overwrite = TRUE) usethis::use_data(rsi_translation, overwrite = TRUE, compress = "xz")
rm(rsi_translation) rm(rsi_translation)
devtools::load_all(".") devtools::load_all(".")
+1 -1
View File
@@ -1 +1 @@
d8083b68d4e492ea8e87c1eae4da4196 657a743283954b40bb68fd3b965462a2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+7428 -7428
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -43,7 +43,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="https://msberends.github.io/AMR/index.html">AMR (for R)</a> <a class="navbar-link" href="https://msberends.github.io/AMR/index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9005</span>
</span> </span>
</div> </div>
+1 -1
View File
@@ -17,7 +17,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9005</span>
</span> </span>
</div> </div>
+4 -4
View File
@@ -44,7 +44,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9005</span>
</span> </span>
</div> </div>
@@ -190,7 +190,7 @@
<div class="page-header toc-ignore"> <div class="page-header toc-ignore">
<h1 data-toc-skip>Data sets for download / own use</h1> <h1 data-toc-skip>Data sets for download / own use</h1>
<h4 data-toc-skip class="date">09 May 2022</h4> <h4 data-toc-skip class="date">10 May 2022</h4>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/datasets.Rmd" class="external-link"><code>vignettes/datasets.Rmd</code></a></small> <small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/datasets.Rmd" class="external-link"><code>vignettes/datasets.Rmd</code></a></small>
<div class="hidden name"><code>datasets.Rmd</code></div> <div class="hidden name"><code>datasets.Rmd</code></div>
@@ -1168,8 +1168,8 @@ column names:<br><em>guideline</em>, <em>method</em>, <em>site</em>, <em>mo</em>
<em>breakpoint_S</em>, <em>breakpoint_R</em> and <em>uti</em>.</p> <em>breakpoint_S</em>, <em>breakpoint_R</em> and <em>uti</em>.</p>
<p>This data set is in R available as <code>rsi_translation</code>, <p>This data set is in R available as <code>rsi_translation</code>,
after you load the <code>AMR</code> package.</p> after you load the <code>AMR</code> package.</p>
<p>It was last updated on 14 December 2021 21:59:33 UTC. Find more info <p>It was last updated on 10 May 2022 13:51:53 UTC. Find more info about
about the structure of this data set <a href="https://msberends.github.io/AMR/reference/rsi_translation.html">here</a>.</p> the structure of this data set <a href="https://msberends.github.io/AMR/reference/rsi_translation.html">here</a>.</p>
<p><strong>Direct download links:</strong></p> <p><strong>Direct download links:</strong></p>
<ul> <ul>
<li>Download as <a href="https://github.com/msberends/AMR/raw/main/data-raw/../data-raw/rsi_translation.rds" class="external-link">R <li>Download as <a href="https://github.com/msberends/AMR/raw/main/data-raw/../data-raw/rsi_translation.rds" class="external-link">R
+1 -1
View File
@@ -17,7 +17,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9005</span>
</span> </span>
</div> </div>
+1 -1
View File
@@ -47,7 +47,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9005</span>
</span> </span>
</div> </div>
+7 -6
View File
@@ -17,7 +17,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9005</span>
</span> </span>
</div> </div>
@@ -157,13 +157,14 @@
</div> </div>
<div class="section level2"> <div class="section level2">
<h2 class="page-header" data-toc-text="1.8.1.9004" id="amr-1819004"> <h2 class="page-header" data-toc-text="1.8.1.9005" id="amr-1819005">
<code>AMR</code> 1.8.1.9004<a class="anchor" aria-label="anchor" href="#amr-1819004"></a></h2> <code>AMR</code> 1.8.1.9005<a class="anchor" aria-label="anchor" href="#amr-1819005"></a></h2>
<div class="section level3"> <div class="section level3">
<h3 id="last-updated-may-1-8-1-9004"><small>Last updated: 9 May 2022</small><a class="anchor" aria-label="anchor" href="#last-updated-may-1-8-1-9004"></a></h3> <h3 id="last-updated-may-1-8-1-9005"><small>Last updated: 10 May 2022</small><a class="anchor" aria-label="anchor" href="#last-updated-may-1-8-1-9005"></a></h3>
<div class="section level4"> <div class="section level4">
<h4 id="changed-1-8-1-9004">Changed<a class="anchor" aria-label="anchor" href="#changed-1-8-1-9004"></a></h4> <h4 id="changed-1-8-1-9005">Changed<a class="anchor" aria-label="anchor" href="#changed-1-8-1-9005"></a></h4>
<ul><li>Removed <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> for MIC values, since MIC are not integer values and running <code><a href="https://rdrr.io/r/base/table.html" class="external-link">table()</a></code> on MIC values consequently failed for not being able to retrieve the level position (as thats how normally <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> on <code>factor</code>s work)</li> <ul><li>Fix for <code><a href="../reference/as.rsi.html">as.rsi()</a></code> on certain EUCAST breakpoints for MIC values</li>
<li>Removed <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> for MIC values, since MIC are not integer values and running <code><a href="https://rdrr.io/r/base/table.html" class="external-link">table()</a></code> on MIC values consequently failed for not being able to retrieve the level position (as thats how normally <code><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer()</a></code> on <code>factor</code>s work)</li>
<li> <li>
<code><a href="https://rdrr.io/r/base/droplevels.html" class="external-link">droplevels()</a></code> on MIC will now return a common <code>factor</code> at default and will lose the <code>&lt;mic&gt;</code> class. Use <code>droplevels(..., as.mic = TRUE)</code> to keep the <code>&lt;mic&gt;</code> class.</li> <code><a href="https://rdrr.io/r/base/droplevels.html" class="external-link">droplevels()</a></code> on MIC will now return a common <code>factor</code> at default and will lose the <code>&lt;mic&gt;</code> class. Use <code>droplevels(..., as.mic = TRUE)</code> to keep the <code>&lt;mic&gt;</code> class.</li>
<li>Small fix for using <code><a href="../reference/ab_from_text.html">ab_from_text()</a></code> <li>Small fix for using <code><a href="../reference/ab_from_text.html">ab_from_text()</a></code>
+1 -1
View File
@@ -17,7 +17,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9005</span>
</span> </span>
</div> </div>
+4
View File
@@ -23,6 +23,10 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== # # ==================================================================== #
# we must only have EUCAST and CLSI, because otherwise the rules in as.rsi() will fail
expect_identical(unique(gsub("[^A-Z]", "", AMR::rsi_translation$guideline)),
c("EUCAST", "CLSI"))
expect_true(as.rsi("S") < as.rsi("I")) expect_true(as.rsi("S") < as.rsi("I"))
expect_true(as.rsi("I") < as.rsi("R")) expect_true(as.rsi("I") < as.rsi("R"))
expect_true(is.rsi(as.rsi("S"))) expect_true(is.rsi(as.rsi("S")))