fix documentation

This commit is contained in:
dr. M.S. (Matthijs) Berends 2022-10-06 11:33:30 +02:00
parent 0d8b098220
commit b9342d103e
8 changed files with 64 additions and 67 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.8.2.9004 Version: 1.8.2.9006
Date: 2022-10-05 Date: 2022-10-06
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.9004 # AMR 1.8.2.9006
This version will eventually become v2.0! We're happy to reach a new major milestone soon! This version will eventually become v2.0! We're happy to reach a new major milestone soon!

View File

@ -1174,6 +1174,7 @@ font_stripstyle <- function(x) {
progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) { progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) {
if (print == FALSE || n < n_min) { if (print == FALSE || n < n_min) {
# create fake/empty object
pb <- list() pb <- list()
pb$tick <- function() { pb$tick <- function() {
invisible() invisible()
@ -1183,16 +1184,17 @@ progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) {
} }
set_clean_class(pb, new_class = "txtProgressBar") set_clean_class(pb, new_class = "txtProgressBar")
} else if (n >= n_min) { } 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) progress_bar <- import_fn("progress_bar", "progress", error_on_fail = FALSE)
if (!is.null(progress_bar)) { if (!is.null(progress_bar)) {
# so we use progress::progress_bar # so we use progress::progress_bar
# a close() method was also added, see below this function # a close() method was also added, see below this function
pb <- progress_bar$new( pb <- progress_bar$new(
format = "[:bar] :percent (:current/:total)", format = "(:spin) [:bar] :percent (:current/:total,:eta)",
total = n total = n
) )
} else { } else {
# use base R
pb <- utils::txtProgressBar(max = n, style = 3) pb <- utils::txtProgressBar(max = n, style = 3)
pb$tick <- function() { pb$tick <- function() {
pb$up(pb$getVal() + 1) pb$up(pb$getVal() + 1)
@ -1206,6 +1208,7 @@ progress_ticker <- function(n = 1, n_min = 0, print = TRUE, ...) {
#' @export #' @export
#' @noRd #' @noRd
close.progress_bar <- function(con, ...) { close.progress_bar <- function(con, ...) {
# for progress::progress_bar$new()
con$terminate() con$terminate()
} }

11
R/mo.R
View File

@ -113,9 +113,8 @@
#' "staaur", #' "staaur",
#' "S. aureus", #' "S. aureus",
#' "S aureus", #' "S aureus",
#' "Staphylococcus aureus", #' "Sthafilokkockus aureus", # handles incorrect spelling
#' "Staphylococcus aureus (MRSA,", #' "Staphylococcus aureus (MRSA)",
#' "Zthafilokkoockus oureuz", # handles incorrect spelling
#' "MRSA", # Methicillin Resistant S. aureus #' "MRSA", # Methicillin Resistant S. aureus
#' "VISA", # Vancomycin Intermediate S. aureus #' "VISA", # Vancomycin Intermediate S. aureus
#' "VRSA", # Vancomycin Resistant S. aureus #' "VRSA", # Vancomycin Resistant S. aureus
@ -822,6 +821,7 @@ print.mo_uncertainties <- function(x, ...) {
txt <- paste(txt, txt <- paste(txt,
paste0( paste0(
paste0( paste0(
"", strrep(font_grey("-"), times = options()$width), "\n",
'"', x[i, ]$original_input, '"', '"', x[i, ]$original_input, '"',
" -> ", " -> ",
paste0( paste0(
@ -844,7 +844,10 @@ print.mo_uncertainties <- function(x, ...) {
candidates, candidates,
sep = "\n" 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) cat(txt)
} }

View File

@ -98,6 +98,7 @@
#' mo_authors("Klebsiella pneumoniae") #' mo_authors("Klebsiella pneumoniae")
#' mo_year("Klebsiella pneumoniae") #' mo_year("Klebsiella pneumoniae")
#' mo_lpsn("Klebsiella pneumoniae") #' mo_lpsn("Klebsiella pneumoniae")
#' mo_gbif("Klebsiella pneumoniae")
#' #'
#' # abbreviations known in the field ----------------------------------------- #' # abbreviations known in the field -----------------------------------------
#' mo_genus("MRSA") #' mo_genus("MRSA")
@ -109,20 +110,15 @@
#' mo_species("EHEC") #' mo_species("EHEC")
#' #'
#' # known subspecies --------------------------------------------------------- #' # known subspecies ---------------------------------------------------------
#' mo_name("doylei")
#' mo_genus("doylei")
#' mo_species("doylei")
#' mo_subspecies("doylei")
#'
#' mo_fullname("K. pneu rh") #' mo_fullname("K. pneu rh")
#' mo_shortname("K. pneu rh") #' mo_shortname("K. pneu rh")
#' #'
#' \donttest{ #' \donttest{
#' # Becker classification, see ?as.mo ---------------------------------------- #' # Becker classification, see ?as.mo ----------------------------------------
#' mo_fullname("S. epi") #' mo_fullname("Staph. epi")
#' mo_fullname("S. epi", Becker = TRUE) #' mo_fullname("Staph. epi", Becker = TRUE)
#' mo_shortname("S. epi") #' mo_shortname("Staph. epi")
#' mo_shortname("S. epi", Becker = TRUE) #' mo_shortname("Staph. epi", Becker = TRUE)
#' #'
#' # Lancefield classification, see ?as.mo ------------------------------------ #' # Lancefield classification, see ?as.mo ------------------------------------
#' mo_fullname("S. pyo") #' mo_fullname("S. pyo")
@ -132,23 +128,19 @@
#' #'
#' #'
#' # language support -------------------------------------------------------- #' # language support --------------------------------------------------------
#' mo_gramstain("Klebsiella pneumoniae", language = "de") #' mo_gramstain("Klebsiella pneumoniae", language = "de") # German
#' mo_gramstain("Klebsiella pneumoniae", language = "nl") #' mo_gramstain("Klebsiella pneumoniae", language = "nl") # Dutch
#' mo_gramstain("Klebsiella pneumoniae", language = "es") #' 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_type is equal to mo_kingdom, but mo_kingdom will remain official
#' mo_kingdom("Klebsiella pneumoniae") #' mo_kingdom("Klebsiella pneumoniae")
#' mo_type("Klebsiella pneumoniae") #' mo_type("Klebsiella pneumoniae")
#' mo_type("Klebsiella pneumoniae") #' mo_type("Klebsiella pneumoniae", language = "nl")
#' #'
#' mo_fullname("S. pyogenes", #' mo_fullname("S. pyogenes", Lancefield = TRUE, language = "de")
#' Lancefield = TRUE, #' mo_fullname("S. pyogenes", Lancefield = TRUE, language = "uk")
#' language = "de"
#' )
#' mo_fullname("S. pyogenes",
#' Lancefield = TRUE,
#' language = "nl"
#' )
#' #'
#' #'
#' # other -------------------------------------------------------------------- #' # other --------------------------------------------------------------------
@ -158,10 +150,13 @@
#' # gram stains and intrinsic resistance can be used as a filter in dplyr verbs #' # gram stains and intrinsic resistance can be used as a filter in dplyr verbs
#' if (require("dplyr")) { #' if (require("dplyr")) {
#' example_isolates %>% #' example_isolates %>%
#' filter(mo_is_gram_positive()) #' filter(mo_is_gram_positive()) %>%
#' #' count(mo_genus(), count = TRUE)
#' }
#' if (require("dplyr")) {
#' example_isolates %>% #' example_isolates %>%
#' filter(mo_is_intrinsic_resistant(ab = "vanco")) #' filter(mo_is_intrinsic_resistant(ab = "vanco")) %>%
#' count(mo_genus(), count = TRUE)
#' } #' }
#' #'
#' #'

View File

@ -84,18 +84,20 @@ expect_equal(as.character(as.mo(c("Gram negative", "Gram positive"))), c("B_GRAM
expect_identical( expect_identical(
suppressWarnings(as.character( suppressWarnings(as.character(
as.mo(c( as.mo(c(
"stau", "stau", # WHONET code
"STAU", "STAU",
"staaur", "staaur",
"S. aureus", "S. aureus",
"S aureus", "S aureus",
"Sthafilokkockus aureus", "Sthafilokkockus aureus", # handles incorrect spelling
"Staphylococcus aureus", "Staphylococcus aureus (MRSA)",
"MRSA", "MRSA", # Methicillin Resistant S. aureus
"VISA" "VISA", # Vancomycin Intermediate S. aureus
), minimum_matching_score = 0) "VRSA", # Vancomycin Resistant S. aureus
115329001 # SNOMED CT code
))
)), )),
rep("B_STPHY_AURS", 9) rep("B_STPHY_AURS", 11)
) )
expect_identical( expect_identical(
as.character( as.character(

View File

@ -170,9 +170,8 @@ as.mo(c(
"staaur", "staaur",
"S. aureus", "S. aureus",
"S aureus", "S aureus",
"Staphylococcus aureus", "Sthafilokkockus aureus", # handles incorrect spelling
"Staphylococcus aureus (MRSA,", "Staphylococcus aureus (MRSA)",
"Zthafilokkoockus oureuz", # handles incorrect spelling
"MRSA", # Methicillin Resistant S. aureus "MRSA", # Methicillin Resistant S. aureus
"VISA", # Vancomycin Intermediate S. aureus "VISA", # Vancomycin Intermediate S. aureus
"VRSA", # Vancomycin Resistant S. aureus "VRSA", # Vancomycin Resistant S. aureus

View File

@ -383,6 +383,7 @@ mo_ref("Klebsiella pneumoniae")
mo_authors("Klebsiella pneumoniae") mo_authors("Klebsiella pneumoniae")
mo_year("Klebsiella pneumoniae") mo_year("Klebsiella pneumoniae")
mo_lpsn("Klebsiella pneumoniae") mo_lpsn("Klebsiella pneumoniae")
mo_gbif("Klebsiella pneumoniae")
# abbreviations known in the field ----------------------------------------- # abbreviations known in the field -----------------------------------------
mo_genus("MRSA") mo_genus("MRSA")
@ -394,20 +395,15 @@ mo_genus("EHEC")
mo_species("EHEC") mo_species("EHEC")
# known subspecies --------------------------------------------------------- # known subspecies ---------------------------------------------------------
mo_name("doylei")
mo_genus("doylei")
mo_species("doylei")
mo_subspecies("doylei")
mo_fullname("K. pneu rh") mo_fullname("K. pneu rh")
mo_shortname("K. pneu rh") mo_shortname("K. pneu rh")
\donttest{ \donttest{
# Becker classification, see ?as.mo ---------------------------------------- # Becker classification, see ?as.mo ----------------------------------------
mo_fullname("S. epi") mo_fullname("Staph. epi")
mo_fullname("S. epi", Becker = TRUE) mo_fullname("Staph. epi", Becker = TRUE)
mo_shortname("S. epi") mo_shortname("Staph. epi")
mo_shortname("S. epi", Becker = TRUE) mo_shortname("Staph. epi", Becker = TRUE)
# Lancefield classification, see ?as.mo ------------------------------------ # Lancefield classification, see ?as.mo ------------------------------------
mo_fullname("S. pyo") mo_fullname("S. pyo")
@ -417,23 +413,19 @@ mo_shortname("S. pyo", Lancefield = TRUE)
# language support -------------------------------------------------------- # language support --------------------------------------------------------
mo_gramstain("Klebsiella pneumoniae", language = "de") mo_gramstain("Klebsiella pneumoniae", language = "de") # German
mo_gramstain("Klebsiella pneumoniae", language = "nl") mo_gramstain("Klebsiella pneumoniae", language = "nl") # Dutch
mo_gramstain("Klebsiella pneumoniae", language = "es") 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_type is equal to mo_kingdom, but mo_kingdom will remain official
mo_kingdom("Klebsiella pneumoniae") mo_kingdom("Klebsiella pneumoniae")
mo_type("Klebsiella pneumoniae") mo_type("Klebsiella pneumoniae")
mo_type("Klebsiella pneumoniae") mo_type("Klebsiella pneumoniae", language = "nl")
mo_fullname("S. pyogenes", mo_fullname("S. pyogenes", Lancefield = TRUE, language = "de")
Lancefield = TRUE, mo_fullname("S. pyogenes", Lancefield = TRUE, language = "uk")
language = "de"
)
mo_fullname("S. pyogenes",
Lancefield = TRUE,
language = "nl"
)
# other -------------------------------------------------------------------- # 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 # gram stains and intrinsic resistance can be used as a filter in dplyr verbs
if (require("dplyr")) { if (require("dplyr")) {
example_isolates \%>\% example_isolates \%>\%
filter(mo_is_gram_positive()) filter(mo_is_gram_positive()) \%>\%
count(mo_genus(), count = TRUE)
}
if (require("dplyr")) {
example_isolates \%>\% example_isolates \%>\%
filter(mo_is_intrinsic_resistant(ab = "vanco")) filter(mo_is_intrinsic_resistant(ab = "vanco")) \%>\%
count(mo_genus(), count = TRUE)
} }