From b9342d103e6b6339d491dbc14aa9aa0789a46291 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Thu, 6 Oct 2022 11:33:30 +0200 Subject: [PATCH] fix documentation --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- R/aa_helper_functions.R | 7 +++++-- R/mo.R | 11 +++++++---- R/mo_property.R | 43 ++++++++++++++++++----------------------- inst/tinytest/test-mo.R | 16 ++++++++------- man/as.mo.Rd | 5 ++--- man/mo_property.Rd | 43 ++++++++++++++++++----------------------- 8 files changed, 64 insertions(+), 67 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 17d61a8e..d5546329 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.8.2.9004 -Date: 2022-10-05 +Version: 1.8.2.9006 +Date: 2022-10-06 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NEWS.md b/NEWS.md index f95edaaf..fa62c76d 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.8.2.9004 +# AMR 1.8.2.9006 This version will eventually become v2.0! We're happy to reach a new major milestone soon! diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 21ecbe09..5113ede2 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -1174,6 +1174,7 @@ font_stripstyle <- function(x) { progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) { if (print == FALSE || n < n_min) { + # create fake/empty object pb <- list() pb$tick <- function() { invisible() @@ -1183,16 +1184,17 @@ progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) { } set_clean_class(pb, new_class = "txtProgressBar") } else if (n >= n_min) { - # rely on the progress package if it is available - it has a more verbose output + # use `progress`, which also has a timer progress_bar <- import_fn("progress_bar", "progress", error_on_fail = FALSE) if (!is.null(progress_bar)) { # so we use progress::progress_bar # a close() method was also added, see below this function pb <- progress_bar$new( - format = "[:bar] :percent (:current/:total)", + format = "(:spin) [:bar] :percent (:current/:total,:eta)", total = n ) } else { + # use base R pb <- utils::txtProgressBar(max = n, style = 3) pb$tick <- function() { pb$up(pb$getVal() + 1) @@ -1206,6 +1208,7 @@ progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) { #' @export #' @noRd close.progress_bar <- function(con, ...) { + # for progress::progress_bar$new() con$terminate() } diff --git a/R/mo.R b/R/mo.R index a3d8a453..3ea26185 100755 --- a/R/mo.R +++ b/R/mo.R @@ -113,9 +113,8 @@ #' "staaur", #' "S. aureus", #' "S aureus", -#' "Staphylococcus aureus", -#' "Staphylococcus aureus (MRSA,", -#' "Zthafilokkoockus oureuz", # handles incorrect spelling +#' "Sthafilokkockus aureus", # handles incorrect spelling +#' "Staphylococcus aureus (MRSA)", #' "MRSA", # Methicillin Resistant S. aureus #' "VISA", # Vancomycin Intermediate S. aureus #' "VRSA", # Vancomycin Resistant S. aureus @@ -822,6 +821,7 @@ print.mo_uncertainties <- function(x, ...) { txt <- paste(txt, paste0( paste0( + "", strrep(font_grey("-"), times = options()$width), "\n", '"', x[i, ]$original_input, '"', " -> ", paste0( @@ -844,7 +844,10 @@ print.mo_uncertainties <- function(x, ...) { candidates, sep = "\n" ) - txt <- paste0(gsub("\n\n", "\n", txt), "\n\n") + txt <- gsub("[\n]+", "\n", txt) + # remove first and last break + txt <- gsub("(^[\n]|[\n]$)", "", txt) + txt <- paste0("\n", txt, "\n") } cat(txt) } diff --git a/R/mo_property.R b/R/mo_property.R index 5580e540..34ddcb36 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -98,6 +98,7 @@ #' mo_authors("Klebsiella pneumoniae") #' mo_year("Klebsiella pneumoniae") #' mo_lpsn("Klebsiella pneumoniae") +#' mo_gbif("Klebsiella pneumoniae") #' #' # abbreviations known in the field ----------------------------------------- #' mo_genus("MRSA") @@ -109,20 +110,15 @@ #' mo_species("EHEC") #' #' # known subspecies --------------------------------------------------------- -#' mo_name("doylei") -#' mo_genus("doylei") -#' mo_species("doylei") -#' mo_subspecies("doylei") -#' #' mo_fullname("K. pneu rh") #' mo_shortname("K. pneu rh") #' #' \donttest{ #' # Becker classification, see ?as.mo ---------------------------------------- -#' mo_fullname("S. epi") -#' mo_fullname("S. epi", Becker = TRUE) -#' mo_shortname("S. epi") -#' mo_shortname("S. epi", Becker = TRUE) +#' mo_fullname("Staph. epi") +#' mo_fullname("Staph. epi", Becker = TRUE) +#' mo_shortname("Staph. epi") +#' mo_shortname("Staph. epi", Becker = TRUE) #' #' # Lancefield classification, see ?as.mo ------------------------------------ #' mo_fullname("S. pyo") @@ -132,23 +128,19 @@ #' #' #' # language support -------------------------------------------------------- -#' mo_gramstain("Klebsiella pneumoniae", language = "de") -#' mo_gramstain("Klebsiella pneumoniae", language = "nl") -#' mo_gramstain("Klebsiella pneumoniae", language = "es") +#' mo_gramstain("Klebsiella pneumoniae", language = "de") # German +#' mo_gramstain("Klebsiella pneumoniae", language = "nl") # Dutch +#' mo_gramstain("Klebsiella pneumoniae", language = "es") # Spanish +#' mo_gramstain("Klebsiella pneumoniae", language = "el") # Greek +#' mo_gramstain("Klebsiella pneumoniae", language = "uk") # Ukrainian #' #' # mo_type is equal to mo_kingdom, but mo_kingdom will remain official #' mo_kingdom("Klebsiella pneumoniae") #' mo_type("Klebsiella pneumoniae") -#' mo_type("Klebsiella pneumoniae") +#' mo_type("Klebsiella pneumoniae", language = "nl") #' -#' mo_fullname("S. pyogenes", -#' Lancefield = TRUE, -#' language = "de" -#' ) -#' mo_fullname("S. pyogenes", -#' Lancefield = TRUE, -#' language = "nl" -#' ) +#' mo_fullname("S. pyogenes", Lancefield = TRUE, language = "de") +#' mo_fullname("S. pyogenes", Lancefield = TRUE, language = "uk") #' #' #' # other -------------------------------------------------------------------- @@ -158,10 +150,13 @@ #' # gram stains and intrinsic resistance can be used as a filter in dplyr verbs #' if (require("dplyr")) { #' example_isolates %>% -#' filter(mo_is_gram_positive()) -#' +#' filter(mo_is_gram_positive()) %>% +#' count(mo_genus(), count = TRUE) +#' } +#' if (require("dplyr")) { #' example_isolates %>% -#' filter(mo_is_intrinsic_resistant(ab = "vanco")) +#' filter(mo_is_intrinsic_resistant(ab = "vanco")) %>% +#' count(mo_genus(), count = TRUE) #' } #' #' diff --git a/inst/tinytest/test-mo.R b/inst/tinytest/test-mo.R index 7cb766f8..1a76745c 100644 --- a/inst/tinytest/test-mo.R +++ b/inst/tinytest/test-mo.R @@ -84,18 +84,20 @@ expect_equal(as.character(as.mo(c("Gram negative", "Gram positive"))), c("B_GRAM expect_identical( suppressWarnings(as.character( as.mo(c( - "stau", + "stau", # WHONET code "STAU", "staaur", "S. aureus", "S aureus", - "Sthafilokkockus aureus", - "Staphylococcus aureus", - "MRSA", - "VISA" - ), minimum_matching_score = 0) + "Sthafilokkockus aureus", # handles incorrect spelling + "Staphylococcus aureus (MRSA)", + "MRSA", # Methicillin Resistant S. aureus + "VISA", # Vancomycin Intermediate S. aureus + "VRSA", # Vancomycin Resistant S. aureus + 115329001 # SNOMED CT code + )) )), - rep("B_STPHY_AURS", 9) + rep("B_STPHY_AURS", 11) ) expect_identical( as.character( diff --git a/man/as.mo.Rd b/man/as.mo.Rd index 0821acbd..df30b91f 100644 --- a/man/as.mo.Rd +++ b/man/as.mo.Rd @@ -170,9 +170,8 @@ as.mo(c( "staaur", "S. aureus", "S aureus", - "Staphylococcus aureus", - "Staphylococcus aureus (MRSA,", - "Zthafilokkoockus oureuz", # handles incorrect spelling + "Sthafilokkockus aureus", # handles incorrect spelling + "Staphylococcus aureus (MRSA)", "MRSA", # Methicillin Resistant S. aureus "VISA", # Vancomycin Intermediate S. aureus "VRSA", # Vancomycin Resistant S. aureus diff --git a/man/mo_property.Rd b/man/mo_property.Rd index 0e107686..afe1cd5e 100644 --- a/man/mo_property.Rd +++ b/man/mo_property.Rd @@ -383,6 +383,7 @@ mo_ref("Klebsiella pneumoniae") mo_authors("Klebsiella pneumoniae") mo_year("Klebsiella pneumoniae") mo_lpsn("Klebsiella pneumoniae") +mo_gbif("Klebsiella pneumoniae") # abbreviations known in the field ----------------------------------------- mo_genus("MRSA") @@ -394,20 +395,15 @@ mo_genus("EHEC") mo_species("EHEC") # known subspecies --------------------------------------------------------- -mo_name("doylei") -mo_genus("doylei") -mo_species("doylei") -mo_subspecies("doylei") - mo_fullname("K. pneu rh") mo_shortname("K. pneu rh") \donttest{ # Becker classification, see ?as.mo ---------------------------------------- -mo_fullname("S. epi") -mo_fullname("S. epi", Becker = TRUE) -mo_shortname("S. epi") -mo_shortname("S. epi", Becker = TRUE) +mo_fullname("Staph. epi") +mo_fullname("Staph. epi", Becker = TRUE) +mo_shortname("Staph. epi") +mo_shortname("Staph. epi", Becker = TRUE) # Lancefield classification, see ?as.mo ------------------------------------ mo_fullname("S. pyo") @@ -417,23 +413,19 @@ mo_shortname("S. pyo", Lancefield = TRUE) # language support -------------------------------------------------------- -mo_gramstain("Klebsiella pneumoniae", language = "de") -mo_gramstain("Klebsiella pneumoniae", language = "nl") -mo_gramstain("Klebsiella pneumoniae", language = "es") +mo_gramstain("Klebsiella pneumoniae", language = "de") # German +mo_gramstain("Klebsiella pneumoniae", language = "nl") # Dutch +mo_gramstain("Klebsiella pneumoniae", language = "es") # Spanish +mo_gramstain("Klebsiella pneumoniae", language = "el") # Greek +mo_gramstain("Klebsiella pneumoniae", language = "uk") # Ukrainian # mo_type is equal to mo_kingdom, but mo_kingdom will remain official mo_kingdom("Klebsiella pneumoniae") mo_type("Klebsiella pneumoniae") -mo_type("Klebsiella pneumoniae") +mo_type("Klebsiella pneumoniae", language = "nl") -mo_fullname("S. pyogenes", - Lancefield = TRUE, - language = "de" -) -mo_fullname("S. pyogenes", - Lancefield = TRUE, - language = "nl" -) +mo_fullname("S. pyogenes", Lancefield = TRUE, language = "de") +mo_fullname("S. pyogenes", Lancefield = TRUE, language = "uk") # other -------------------------------------------------------------------- @@ -443,10 +435,13 @@ mo_is_yeast(c("Candida", "Trichophyton", "Klebsiella")) # gram stains and intrinsic resistance can be used as a filter in dplyr verbs if (require("dplyr")) { example_isolates \%>\% - filter(mo_is_gram_positive()) - + filter(mo_is_gram_positive()) \%>\% + count(mo_genus(), count = TRUE) +} +if (require("dplyr")) { example_isolates \%>\% - filter(mo_is_intrinsic_resistant(ab = "vanco")) + filter(mo_is_intrinsic_resistant(ab = "vanco")) \%>\% + count(mo_genus(), count = TRUE) }