From 7a6fce4eb848d0e02e9f35244b75d80a7f545c69 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Mon, 26 Aug 2019 16:02:03 +0200 Subject: [PATCH] (v0.7.1.9062) mo/ab assignment improvements --- DESCRIPTION | 2 +- NEWS.md | 79 ++++---- R/ab.R | 22 +-- R/misc.R | 8 + R/mo.R | 36 ++-- R/portion.R | 39 ++-- _pkgdown.yml | 1 + docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 376 ++++++++++++++++++------------------ docs/reference/count.html | 43 ++--- docs/reference/index.html | 8 +- docs/reference/portion.html | 43 ++--- man/count.Rd | 39 ++-- man/portion.Rd | 39 ++-- tests/testthat/test-ab.R | 9 +- tests/testthat/test-mo.R | 9 + 19 files changed, 383 insertions(+), 378 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 54006011..255d5700 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 0.7.1.9061 +Version: 0.7.1.9062 Date: 2019-08-26 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 7a2c02fc..c0e20796 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,12 +1,27 @@ -# AMR 0.7.1.9061 +# AMR 0.7.1.9062 ### Breaking -* Function `freq()` has moved to a new package, [`clean`](https://github.com/msberends/clean) ([CRAN link](https://cran.r-project.org/package=clean)). The `freq()` function still works, since it is re-exported from the `clean` package to this `AMR` package. Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. Therefore, a new package was created for data cleaning and checking and it perfectly fits the `freq()` function. The [`clean`](https://github.com/msberends/clean) package is available on CRAN and will be installed automatically when updating the `AMR` package, that now imports it. In a later stage, the `skewness()` and `kurtosis()` functions will be moved to the `clean` package too. * Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`: ```r first_isolate(..., include_unknown = TRUE) ``` - For WHONET users, this means that all records with organism code `"con"` (*contamination*) will be excluded at default, since `as.mo("con") = "UNKNOWN"`. The function always shows a note with the number of 'unknown' microorganisms that were included or excluded. + For WHONET users, this means that all records/isolates with organism code `"con"` (*contamination*) will be excluded at default, since `as.mo("con") = "UNKNOWN"`. The function always shows a note with the number of 'unknown' microorganisms that were included or excluded. +* For code consistency, classes `ab` and `mo` will now be preserved in any subsetting or assignment. For the sake of data integrity, this means that invalid assignments will now result in `NA`: + ```r + # how it works in base R: + x <- factor("A") + x[1] <- "B" + #> Warning message: + #> invalid factor level, NA generated + + # how it now works similarly for classes 'mo' and 'ab': + x <- as.mo("E. coli") + x[1] <- "testvalue" + #> Warning message: + #> invalid microbial code, NA generated + ``` + This is important, because a value like `"testvalue"` could never be understood by e.g. `mo_name()`, although the class would suggest a valid microbial code. +* Function `freq()` has moved to a new package, [`clean`](https://github.com/msberends/clean) ([CRAN link](https://cran.r-project.org/package=clean)), since creating frequency tables actually does not fit the scope of this package. The `freq()` function still works, since it is re-exported from the `clean` package (which will be installed automatically upon updating this `AMR` package). ### New * Function `bug_drug_combinations()` to quickly get a `data.frame` with the antimicrobial resistance of any bug-drug combination in a data set: @@ -24,35 +39,36 @@ ```r format(x) ``` -* Additional way to calculate co-resistance, i.e. when using multiple antibiotics as input for `portion_*` functions or `count_*` functions. This can be used to determine the empiric susceptibily of a combination therapy. A new parameter `only_all_tested` (**which defaults to `FALSE`**) replaces the old `also_single_tested` and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on the `portion` and `count` help pages), where the %SI is being determined: +* Additional way to calculate co-resistance, i.e. when using multiple antimicrobials as input for `portion_*` functions or `count_*` functions. This can be used to determine the empiric susceptibily of a combination therapy. A new parameter `only_all_tested` (**which defaults to `FALSE`**) replaces the old `also_single_tested` and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on the `portion` and `count` help pages), where the %SI is being determined: ```r - # ------------------------------------------------------------------------- - # only_all_tested = FALSE only_all_tested = TRUE - # Antibiotic Antibiotic ----------------------- ----------------------- - # A B include as include as include as include as - # numerator denominator numerator denominator - # ---------- ---------- ---------- ----------- ---------- ----------- - # S S X X X X - # I S X X X X - # R S X X X X - # not tested S X X - - - # S I X X X X - # I I X X X X - # R I X X X X - # not tested I X X - - - # S R X X X X - # I R X X X X - # R R - X - X - # not tested R - - - - - # S not tested X X - - - # I not tested X X - - - # R not tested - - - - - # not tested not tested - - - - - # ------------------------------------------------------------------------- + # -------------------------------------------------------------------- + # only_all_tested = FALSE only_all_tested = TRUE + # ----------------------- ----------------------- + # Drug A Drug B include as include as include as include as + # numerator denominator numerator denominator + # -------- -------- ---------- ----------- ---------- ----------- + # S or I S or I X X X X + # R S or I X X X X + # S or I X X - - + # S or I R X X X X + # R R - X - X + # R - - - - + # S or I X X - - + # R - - - - + # - - - - + # -------------------------------------------------------------------- ``` Since this is a major change, usage of the old `also_single_tested` will throw an informative error that it has been replaced by `only_all_tested`. +* `tibble` printing support for classes `rsi`, `mic`, `disk`, `ab` `mo`. When using `tibble`s containing antimicrobial columns, values `S` will print in green, values `I` will print in yellow and values `R` will print in red. Microbial IDs (class `mo`) will emphasise on the genus and species, not on the kingdom. + ```r + # (run this on your own console, as this page does not support colour printing) + library(dplyr) + septic_patients %>% + select(mo:AMC) %>% + as_tibble() + ``` ### Changed * Function: `eucast_rules()` @@ -62,14 +78,6 @@ * Using Verbose mode (i.e. `eucast_rules(..., verbose = TRUE)`) returns more informative and readable output * Using factors as input now adds missing factors levels when the function changes antibiotic results * Improved the internal auto-guessing function for determining antibiotics in your data set (`AMR:::get_column_abx()`) -* Added tibble printing support for classes `rsi`, `mic`, `disk`, `ab` `mo`. When using tibbles containing antibiotic columns, values `S` will print in green, values `I` will print in yellow and values `R` will print in red. Microbial IDs (class `mo`) will emphasise on the genus and species, not on the kingdom. - ```r - # (run this on your own console, as this page does not support colour printing) - library(dplyr) - septic_patients %>% - select(mo:AMC) %>% - as_tibble() - ``` * Removed class `atc` - using `as.atc()` is now deprecated in favour of `ab_atc()` and this will return a character, not the `atc` class anymore * Removed deprecated functions `abname()`, `ab_official()`, `atc_name()`, `atc_official()`, `atc_property()`, `atc_tradenames()`, `atc_trivial_nl()` * Fix and speed improvement for `mo_shortname()` @@ -86,7 +94,6 @@ * The `antibiotics` data set is now sorted by name and all cephalosporins now have their generation between brackets * Speed improvement for `guess_ab_col()` which is now 30 times faster for antibiotic abbreviations * Improved `filter_ab_class()` to be more reliable and to support 5th generation cephalosporins -* Classes `ab` and `mo` will now be preserved in any subsetting * Function `availability()` now uses `portion_R()` instead of `portion_IR()`, to comply with EUCAST insights #### Other diff --git a/R/ab.R b/R/ab.R index ecac120d..2a61333d 100755 --- a/R/ab.R +++ b/R/ab.R @@ -287,14 +287,6 @@ as.data.frame.ab <- function (x, ...) { attributes(y) <- attributes(x) y } -#' @exportMethod [<-.ab -#' @export -#' @noRd -"[<-.ab" <- function(value) { - y <- NextMethod() - attributes(y) <- attributes(value) - y -} #' @exportMethod [[.ab #' @export #' @noRd @@ -303,13 +295,21 @@ as.data.frame.ab <- function (x, ...) { attributes(y) <- attributes(x) y } +#' @exportMethod [<-.ab +#' @export +#' @noRd +"[<-.ab" <- function(i, j, ..., value) { + y <- NextMethod() + attributes(y) <- attributes(i) + class_integrity_check(y, "antimicrobial code", AMR::antibiotics$ab) +} #' @exportMethod [[<-.ab #' @export #' @noRd "[[<-.ab" <- function(i, j, ..., value) { y <- NextMethod() - attributes(y) <- attributes(value) - y + attributes(y) <- attributes(i) + class_integrity_check(y, "antimicrobial code", AMR::antibiotics$ab) } #' @exportMethod c.ab #' @export @@ -317,7 +317,7 @@ as.data.frame.ab <- function (x, ...) { c.ab <- function(x, ...) { y <- NextMethod() attributes(y) <- attributes(x) - y + class_integrity_check(y, "antimicrobial code", AMR::antibiotics$ab) } #' @importFrom pillar type_sum diff --git a/R/misc.R b/R/misc.R index d9fca3bc..a5b05ac4 100755 --- a/R/misc.R +++ b/R/misc.R @@ -190,3 +190,11 @@ translate_AMR <- function(from, language = get_locale(), only_unknown = FALSE) { x, ifelse(!is.na(y), y, NA)) } + +class_integrity_check <- function(value, type, check_vector) { + if (!all(value[!is.na(value)] %in% check_vector)) { + warning(paste0("invalid ", type, ", NA generated"), call. = FALSE) + value[!value %in% check_vector] <- NA + } + value +} diff --git a/R/mo.R b/R/mo.R index 84640cd7..da05eed9 100755 --- a/R/mo.R +++ b/R/mo.R @@ -1693,17 +1693,15 @@ type_sum.mo <- function(x) { #' @export pillar_shaft.mo <- function(x, ...) { out <- format(x) - # grey out the kingdom (part before first "_") - first_parts <- unlist(lapply(gregexpr(pattern = '_', x[!is.na(x)], fixed = TRUE), min)) - first_parts[first_parts < 0] <- 0 - out[!is.na(x)] <- paste0(pillar::style_subtle(substr(x[!is.na(x)], 0, first_parts)), - substr(x[!is.na(x)], first_parts + 1, nchar(x))) + # grey out the kingdom (part until first "_") + out[!is.na(x)] <- gsub("^([A-Z]+_)(.*)", paste0(pillar::style_subtle("\\1"), "\\2"), out[!is.na(x)]) + # and grey out every _ + out[!is.na(x)] <- gsub("_", pillar::style_subtle("_"), out[!is.na(x)]) + # markup NA and UNKNOWN out[is.na(x)] <- pillar::style_na(" NA") out[x == "UNKNOWN"] <- pillar::style_na(" UNKNOWN") - out <- gsub("_", pillar::style_subtle("_"), out) - pillar::new_pillar_shaft_simple(out, align = "left", min_width = 12) } @@ -1746,14 +1744,6 @@ as.data.frame.mo <- function(x, ...) { attributes(y) <- attributes(x) y } -#' @exportMethod [<-.mo -#' @export -#' @noRd -"[<-.mo" <- function(i, j, ..., value) { - y <- NextMethod() - attributes(y) <- attributes(value) - y -} #' @exportMethod [[.mo #' @export #' @noRd @@ -1762,13 +1752,21 @@ as.data.frame.mo <- function(x, ...) { attributes(y) <- attributes(x) y } +#' @exportMethod [<-.mo +#' @export +#' @noRd +"[<-.mo" <- function(i, j, ..., value) { + y <- NextMethod() + attributes(y) <- attributes(i) + class_integrity_check(y, "microbial code", AMR::microorganisms$mo) +} #' @exportMethod [[<-.mo #' @export #' @noRd -"[[<-.mo" <- function(value) { +"[[<-.mo" <- function(i, j, ..., value) { y <- NextMethod() - attributes(y) <- attributes(value) - y + attributes(y) <- attributes(i) + class_integrity_check(y, "microbial code", AMR::microorganisms$mo) } #' @exportMethod c.mo #' @export @@ -1776,7 +1774,7 @@ as.data.frame.mo <- function(x, ...) { c.mo <- function(x, ...) { y <- NextMethod() attributes(y) <- attributes(x) - y + class_integrity_check(y, "microbial code", AMR::microorganisms$mo) } #' @rdname as.mo diff --git a/R/portion.R b/R/portion.R index 798c3afa..9e6c9cf4 100755 --- a/R/portion.R +++ b/R/portion.R @@ -45,29 +45,22 @@ #' When using more than one variable for \code{...} (= combination therapy)), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how \code{portion_SI} works to calculate the \%SI: #' #' \preformatted{ -#' ------------------------------------------------------------------------- -#' only_all_tested = FALSE only_all_tested = TRUE -#' Antibiotic Antibiotic ----------------------- ----------------------- -#' A B include as include as include as include as -#' numerator denominator numerator denominator -#' ---------- ---------- ---------- ----------- ---------- ----------- -#' S S X X X X -#' I S X X X X -#' R S X X X X -#' not tested S X X - - -#' S I X X X X -#' I I X X X X -#' R I X X X X -#' not tested I X X - - -#' S R X X X X -#' I R X X X X -#' R R - X - X -#' not tested R - - - - -#' S not tested X X - - -#' I not tested X X - - -#' R not tested - - - - -#' not tested not tested - - - - -#' ------------------------------------------------------------------------- +#' -------------------------------------------------------------------- +#' only_all_tested = FALSE only_all_tested = TRUE +#' ----------------------- ----------------------- +#' Drug A Drug B include as include as include as include as +#' numerator denominator numerator denominator +#' -------- -------- ---------- ----------- ---------- ----------- +#' S or I S or I X X X X +#' R S or I X X X X +#' S or I X X - - +#' S or I R X X X X +#' R R - X - X +#' R - - - - +#' S or I X X - - +#' R - - - - +#' - - - - +#' -------------------------------------------------------------------- #' } #' #' Please note that, in combination therapies, for \code{only_all_tested = TRUE} applies that: diff --git a/_pkgdown.yml b/_pkgdown.yml index fbeee742..8a8c5027 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -127,6 +127,7 @@ reference: resistance or susceptibility, or make plots. contents: - "`availability`" + - "`bug_drug_combinations`" - "`count`" - "`portion`" - "`filter_ab_class`" diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 26409b80..8922f06f 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9061 + 0.7.1.9062 diff --git a/docs/articles/index.html b/docs/articles/index.html index 24631ab7..b6a42ac0 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9061 + 0.7.1.9062 diff --git a/docs/authors.html b/docs/authors.html index f5b9f309..8057b85b 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9061 + 0.7.1.9062 diff --git a/docs/index.html b/docs/index.html index 87c88c4d..c60b4b04 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9061 + 0.7.1.9062 diff --git a/docs/news/index.html b/docs/news/index.html index 02f37f64..0e77ecff 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9061 + 0.7.1.9062 @@ -225,20 +225,33 @@ -
+

-AMR 0.7.1.9061 Unreleased +AMR 0.7.1.9062 Unreleased

Breaking

    -
  • Function freq() has moved to a new package, clean (CRAN link). The freq() function still works, since it is re-exported from the clean package to this AMR package. Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. Therefore, a new package was created for data cleaning and checking and it perfectly fits the freq() function. The clean package is available on CRAN and will be installed automatically when updating the AMR package, that now imports it. In a later stage, the skewness() and kurtosis() functions will be moved to the clean package too.
  • Determination of first isolates now excludes all ‘unknown’ microorganisms at default, i.e. microbial code "UNKNOWN". They can be included with the new parameter include_unknown:

    first_isolate(..., include_unknown = TRUE)
    -

    For WHONET users, this means that all records with organism code "con" (contamination) will be excluded at default, since as.mo("con") = "UNKNOWN". The function always shows a note with the number of ‘unknown’ microorganisms that were included or excluded.

    -
  • +For WHONET users, this means that all records/isolates with organism code "con" (contamination) will be excluded at default, since as.mo("con") = "UNKNOWN". The function always shows a note with the number of ‘unknown’ microorganisms that were included or excluded. +
  • +

    For code consistency, classes ab and mo will now be preserved in any subsetting or assignment. For the sake of data integrity, this means that invalid assignments will now result in NA:

    + +This is important, because a value like "testvalue" could never be understood by e.g. mo_name(), although the class would suggest a valid microbial code.
  • +
  • Function freq() has moved to a new package, clean (CRAN link), since creating frequency tables actually does not fit the scope of this package. The freq() function still works, since it is re-exported from the clean package (which will be installed automatically upon updating this AMR package).

@@ -247,43 +260,43 @@
@@ -302,14 +315,6 @@
  • Improved the internal auto-guessing function for determining antibiotics in your data set (AMR:::get_column_abx())
  • -
  • -

    Added tibble printing support for classes rsi, mic, disk, ab mo. When using tibbles containing antibiotic columns, values S will print in green, values I will print in yellow and values R will print in red. Microbial IDs (class mo) will emphasise on the genus and species, not on the kingdom.

    - -
  • Removed class atc - using as.atc() is now deprecated in favour of ab_atc() and this will return a character, not the atc class anymore
  • Removed deprecated functions abname(), ab_official(), atc_name(), atc_official(), atc_property(), atc_tradenames(), atc_trivial_nl()
  • @@ -331,8 +336,7 @@
  • The antibiotics data set is now sorted by name and all cephalosporins now have their generation between brackets
  • Speed improvement for guess_ab_col() which is now 30 times faster for antibiotic abbreviations
  • Improved filter_ab_class() to be more reliable and to support 5th generation cephalosporins
  • -
  • Classes ab and mo will now be preserved in any subsetting
  • -
  • Function availability() now uses portion_R() instead of portion_IR(), to comply with EUCAST insights

  • +
  • Function availability() now uses portion_R() instead of portion_IR(), to comply with EUCAST insights
  • @@ -353,14 +357,14 @@

    All these lead to the microbial ID of E. coli:

    - +
  • Function mo_info() as an analogy to ab_info(). The mo_info() prints a list with the full taxonomy, authors, and the URL to the online database of a microorganism
  • Function mo_synonyms() to get all previously accepted taxonomic names of a microorganism

  • @@ -482,14 +486,14 @@ Please
    septic_patients %>% 
    -  freq(age) %>% 
    -  boxplot()
    -# grouped boxplots:
    -septic_patients %>% 
    -  group_by(hospital_id) %>% 
    -  freq(age) %>%
    -  boxplot()

    + @@ -574,32 +578,32 @@ This data is updated annually - check the included version with the new function
  • New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:

    - +

    The antibiotics data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in the antibiotics data set. For example:

    - +
  • All ab_* functions are deprecated and replaced by atc_* functions:

    - + These functions use as.atc() internally. The old atc_property has been renamed atc_online_property(). This is done for two reasons: firstly, not all ATC codes are of antibiotics (ab) but can also be of antivirals or antifungals. Secondly, the input must have class atc or must be coerable to this class. Properties of these classes should start with the same class name, analogous to as.mo() and e.g. mo_genus.
  • New functions set_mo_source() and get_mo_source() to use your own predefined MO codes as input for as.mo() and consequently all mo_* functions
  • Support for the upcoming dplyr version 0.8.0
  • @@ -611,20 +615,20 @@ These functions use as.atc()New function age_groups() to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic antimicrobial resistance analysis per age group.
  • New function ggplot_rsi_predict() as well as the base R plot() function can now be used for resistance prediction calculated with resistance_predict():

    -
    x <- resistance_predict(septic_patients, col_ab = "amox")
    -plot(x)
    -ggplot_rsi_predict(x)
    +
    x <- resistance_predict(septic_patients, col_ab = "amox")
    +plot(x)
    +ggplot_rsi_predict(x)
  • Functions filter_first_isolate() and filter_first_weighted_isolate() to shorten and fasten filtering on data sets with antimicrobial results, e.g.:

    - +

    is equal to:

    -
    septic_patients %>%
    -  mutate(only_firsts = first_isolate(septic_patients, ...)) %>%
    -  filter(only_firsts == TRUE) %>%
    -  select(-only_firsts)
    +
    septic_patients %>%
    +  mutate(only_firsts = first_isolate(septic_patients, ...)) %>%
    +  filter(only_firsts == TRUE) %>%
    +  select(-only_firsts)
  • New function availability() to check the number of available (non-empty) results in a data.frame
  • @@ -653,33 +657,33 @@ These functions use as.atc()
  • Now handles incorrect spelling, like i instead of y and f instead of ph:

    - +
  • Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default allow_uncertain = TRUE is equal to uncertainty level 2. Run ?as.mo for more info about these levels.

    -
    # equal:
    -as.mo(..., allow_uncertain = TRUE)
    -as.mo(..., allow_uncertain = 2)
    -
    -# also equal:
    -as.mo(..., allow_uncertain = FALSE)
    -as.mo(..., allow_uncertain = 0)
    +
    # equal:
    +as.mo(..., allow_uncertain = TRUE)
    +as.mo(..., allow_uncertain = 2)
    +
    +# also equal:
    +as.mo(..., allow_uncertain = FALSE)
    +as.mo(..., allow_uncertain = 0)
    Using as.mo(..., allow_uncertain = 3) could lead to very unreliable results.
  • Implemented the latest publication of Becker et al. (2019), for categorising coagulase-negative Staphylococci
  • All microbial IDs that found are now saved to a local file ~/.Rhistory_mo. Use the new function clean_mo_history() to delete this file, which resets the algorithms.
  • Incoercible results will now be considered ‘unknown’, MO code UNKNOWN. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:

    - +
  • Fix for vector containing only empty values
  • Finds better results when input is in other languages
  • @@ -725,19 +729,19 @@ Using as.mo(..., allow_uncertain = 3)
  • Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:

    - +
  • Header info is now available as a list, with the header function
  • The parameter header is now set to TRUE at default, even for markdown
  • @@ -812,10 +816,10 @@ Using as.mo(..., allow_uncertain = 3)Fewer than 3 characters as input for as.mo will return NA
  • Function as.mo (and all mo_* wrappers) now supports genus abbreviations with “species” attached

    -
    as.mo("E. species")        # B_ESCHR
    -mo_fullname("E. spp.")     # "Escherichia species"
    -as.mo("S. spp")            # B_STPHY
    -mo_fullname("S. species")  # "Staphylococcus species"
    +
    as.mo("E. species")        # B_ESCHR
    +mo_fullname("E. spp.")     # "Escherichia species"
    +as.mo("S. spp")            # B_STPHY
    +mo_fullname("S. species")  # "Staphylococcus species"
  • Added parameter combine_IR (TRUE/FALSE) to functions portion_df and count_df, to indicate that all values of I and R must be merged into one, so the output only consists of S vs. IR (susceptible vs. non-susceptible)
  • Fix for portion_*(..., as_percent = TRUE) when minimal number of isolates would not be met
  • @@ -828,15 +832,15 @@ Using as.mo(..., allow_uncertain = 3)
  • Support for grouping variables, test with:

    -
    septic_patients %>% 
    -  group_by(hospital_id) %>% 
    -  freq(gender)
    +
    septic_patients %>% 
    +  group_by(hospital_id) %>% 
    +  freq(gender)
  • Support for (un)selecting columns:

    -
    septic_patients %>% 
    -  freq(hospital_id) %>% 
    -  select(-count, -cum_count) # only get item, percent, cum_percent
    +
    septic_patients %>% 
    +  freq(hospital_id) %>% 
    +  select(-count, -cum_count) # only get item, percent, cum_percent
  • Check for hms::is.hms
  • @@ -916,18 +920,18 @@ Using as.mo(..., allow_uncertain = 3)

    They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:

    -
    mo_gramstain("E. coli")
    -# [1] "Gram negative"
    -mo_gramstain("E. coli", language = "de") # German
    -# [1] "Gramnegativ"
    -mo_gramstain("E. coli", language = "es") # Spanish
    -# [1] "Gram negativo"
    -mo_fullname("S. group A", language = "pt") # Portuguese
    -# [1] "Streptococcus grupo A"
    +
    mo_gramstain("E. coli")
    +# [1] "Gram negative"
    +mo_gramstain("E. coli", language = "de") # German
    +# [1] "Gramnegativ"
    +mo_gramstain("E. coli", language = "es") # Spanish
    +# [1] "Gram negativo"
    +mo_fullname("S. group A", language = "pt") # Portuguese
    +# [1] "Streptococcus grupo A"

    Furthermore, former taxonomic names will give a note about the current taxonomic name:

    - +
  • Functions count_R, count_IR, count_I, count_SI and count_S to selectively count resistant or susceptible isolates
  • @@ -1252,7 +1256,7 @@ Using as.mo(..., allow_uncertain = 3)

    Contents

    @@ -318,29 +318,22 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_

    When using more than one variable for ... (= combination therapy)), use only_all_tested to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how portion_SI works to calculate the %SI:

    --------------------------------------------------------------------------
    -                        only_all_tested = FALSE   only_all_tested = TRUE
    -Antibiotic  Antibiotic  -----------------------   -----------------------
    -    A           B       include as  include as    include as  include as
    -                        numerator   denominator   numerator   denominator
    -----------  ----------  ----------  -----------   ----------  -----------
    -    S           S           X            X             X            X
    -    I           S           X            X             X            X
    -    R           S           X            X             X            X
    -not tested      S           X            X             -            -
    -    S           I           X            X             X            X
    -    I           I           X            X             X            X
    -    R           I           X            X             X            X
    -not tested      I           X            X             -            -
    -    S           R           X            X             X            X
    -    I           R           X            X             X            X
    -    R           R           -            X             -            X
    -not tested      R           -            -             -            -
    -    S       not tested      X            X             -            -
    -    I       not tested      X            X             -            -
    -    R       not tested      -            -             -            -
    -not tested  not tested      -            -             -            -
    --------------------------------------------------------------------------
    +--------------------------------------------------------------------
    +                    only_all_tested = FALSE  only_all_tested = TRUE
    +                    -----------------------  -----------------------
    + Drug A    Drug B   include as  include as   include as  include as
    +                    numerator   denominator  numerator   denominator
    +--------  --------  ----------  -----------  ----------  -----------
    + S or I    S or I       X            X            X            X
    +   R       S or I       X            X            X            X
    +  <NA>     S or I       X            X            -            -
    + S or I      R          X            X            X            X
    +   R         R          -            X            -            X
    +  <NA>       R          -            -            -            -
    + S or I     <NA>        X            X            -            -
    +   R        <NA>        -            -            -            -
    +  <NA>      <NA>        -            -            -            -
    +--------------------------------------------------------------------
     

    Please note that, in combination therapies, for only_all_tested = TRUE applies that:

        count_S()  +  count_I()  +  count_R()  == count_all()
    @@ -448,7 +441,7 @@ not tested  not tested      -            -             -            -