diff --git a/DESCRIPTION b/DESCRIPTION index 0dc6a5bd..fd701a9e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9091 -Date: 2019-09-30 +Version: 0.7.1.9092 +Date: 2019-10-04 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), @@ -34,17 +34,15 @@ Depends: R (>= 3.1.0) Imports: backports, - clean (>= 1.1.0.9000), + clean (>= 1.1.0), crayon (>= 1.3.0), data.table (>= 1.9.0), dplyr (>= 0.7.0), ggplot2, - hms, knitr (>= 1.0.0), microbenchmark, pillar, rlang (>= 0.3.1), - scales, tidyr (>= 0.7.0) Suggests: covr (>= 3.0.1), diff --git a/NAMESPACE b/NAMESPACE index a0f3b09f..f288e834 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -233,7 +233,6 @@ exportMethods(summary.mo) exportMethods(summary.rsi) importFrom(clean,freq) importFrom(clean,freq.default) -importFrom(clean,percentage) importFrom(clean,top_freq) importFrom(crayon,bgGreen) importFrom(crayon,bgRed) diff --git a/NEWS.md b/NEWS.md index f6da67e1..3237ced7 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 0.7.1.9091 -Last updated: 30-Sep-2019 +# AMR 0.7.1.9092 +Last updated: 04-Oct-2019 ### Breaking * 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`: @@ -94,6 +94,7 @@ * Added support for unknown yeasts and fungi * Changed most microorganism IDs to improve readability. For example, the old code `B_ENTRC_FAE` could have been both *E. faecalis* and *E. faecium*. Its new code is `B_ENTRC_FCLS` and *E. faecium* has become `B_ENTRC_FACM`. Also, the Latin character æ (ae) is now preserved at the start of each genus and species abbreviation. For example, the old code for *Aerococcus urinae* was `B_ARCCC_NAE`. This is now `B_AERCC_URIN`. **IMPORTANT:** Old microorganism IDs are still supported, but support will be dropped in a future version. Use `as.mo()` on your old codes to transform them to the new format. Using functions from the `mo_*` family (like `mo_name()` and `mo_gramstain()`) on old codes, will throw a warning. +* More intelligent guessing for `as.ab()` * Renamed data set `septic_patients` to `example_isolates` * Function `eucast_rules()`: * Fixed a bug for *Yersinia pseudotuberculosis* diff --git a/R/ab.R b/R/ab.R index 2a61333d..2dd16249 100755 --- a/R/ab.R +++ b/R/ab.R @@ -23,6 +23,7 @@ #' #' Use this function to determine the antibiotic code of one or more antibiotics. The data set \code{\link{antibiotics}} will be searched for abbreviations, official names and synonyms (brand names). #' @param x character vector to determine to antibiotic ID +#' @param ... arguments passed on to internal functions #' @rdname as.ab #' @keywords atc #' @inheritSection WHOCC WHOCC @@ -57,7 +58,7 @@ #' # they use as.ab() internally: #' ab_name("J01FA01") # "Erythromycin" #' ab_name("eryt") # "Erythromycin" -as.ab <- function(x) { +as.ab <- function(x, ...) { if (is.ab(x)) { return(x) } @@ -69,6 +70,9 @@ as.ab <- function(x) { } x_bak <- x + # remove diacritics + x <- iconv(x, from = "UTF-8", to = "ASCII//TRANSLIT") + x <- gsub('"', "", x, fixed = TRUE) # remove suffices x_bak_clean <- gsub("_(mic|rsi|dis[ck])$", "", x, ignore.case = TRUE) # remove disk concentrations, like LVX_NM -> LVX @@ -76,9 +80,15 @@ as.ab <- function(x) { # remove part between brackets if that's followed by another string x_bak_clean <- gsub("(.*)+ [(].*[)]", "\\1", x_bak_clean) # keep only a-Z, 0-9, space, slash and dash - x_bak_clean <- gsub("[^A-Z0-9 /-]", "", x_bak_clean, ignore.case = TRUE) + # x_bak_clean <- gsub("[^A-Z0-9 /-]", "", x_bak_clean, ignore.case = TRUE) # keep only max 1 space x_bak_clean <- trimws(gsub(" +", " ", x_bak_clean, ignore.case = TRUE)) + # non-character, space or number should be a slash + x_bak_clean <- gsub("[^A-Za-z0-9 ]", "/", x_bak_clean) + # spaces around non-characters must be removed: amox + clav -> amox/clav + x_bak_clean <- gsub("(.*[a-zA-Z0-9]) ([^a-zA-Z0-9].*)", "\\1\\2", x_bak_clean) + x_bak_clean <- gsub("(.*[^a-zA-Z0-9]) ([a-zA-Z0-9].*)", "\\1\\2", x_bak_clean) + x <- unique(x_bak_clean) x_new <- rep(NA_character_, length(x)) x_unknown <- character(0) @@ -181,6 +191,7 @@ as.ab <- function(x) { x_spelling <- gsub("(o\\+n|o\\+ne\\+)$", "o+ne*", x_spelling) # replace multiple same characters to single one with '+', like "ll" -> "l+" x_spelling <- gsub("(.)\\1+", "\\1+", x_spelling) + # try if name starts with it found <- AMR::antibiotics[which(AMR::antibiotics$name %like% paste0("^", x_spelling)),]$ab if (length(found) > 0) { @@ -217,7 +228,44 @@ as.ab <- function(x) { next } } - + + if (!isFALSE(list(...)$initial_search)) { + # transform back from other languages and try again + x_translated <- paste(lapply(strsplit(x[i], "[^a-zA-Z0-9 ]"), + function(y) { + for (i in 1:length(y)) { + y[i] <- ifelse(tolower(y[i]) %in% tolower(translations_file$replacement), + translations_file[which(tolower(translations_file$replacement) == tolower(y[i]) & + !isFALSE(translations_file$fixed)), "pattern"], + y[i]) + } + y + })[[1]], + collapse = "/") + x_translated_guess <- suppressWarnings(as.ab(x_translated, initial_search = FALSE)) + if (!is.na(x_translated_guess)) { + x_new[i] <- x_translated_guess + next + } + # now also try to coerce brandname combinations like "Amoxy/clavulanic acid" + x_translated <- paste(lapply(strsplit(x_translated, "[^a-zA-Z0-9 ]"), + function(y) { + for (i in 1:length(y)) { + y_name <- suppressWarnings(ab_name(y[i], language = NULL, initial_search = FALSE)) + y[i] <- ifelse(!is.na(y_name), + y_name, + y[i]) + } + y + })[[1]], + collapse = "/") + x_translated_guess <- suppressWarnings(as.ab(x_translated, initial_search = FALSE)) + if (!is.na(x_translated_guess)) { + x_new[i] <- x_translated_guess + next + } + } + # not found x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1]) } diff --git a/R/ab_property.R b/R/ab_property.R index 15246f17..614ab3ec 100644 --- a/R/ab_property.R +++ b/R/ab_property.R @@ -188,7 +188,7 @@ ab_validate <- function(x, property, ...) { error = function(e) stop(e$message, call. = FALSE)) if (!all(x %in% AMR::antibiotics[, property])) { - x <- data.frame(ab = AMR::as.ab(x), stringsAsFactors = FALSE) %>% + x <- data.frame(ab = AMR::as.ab(x, ...), stringsAsFactors = FALSE) %>% left_join(AMR::antibiotics, by = "ab") %>% pull(property) } diff --git a/R/availability.R b/R/availability.R index 7a830d55..a5df554f 100644 --- a/R/availability.R +++ b/R/availability.R @@ -27,7 +27,7 @@ #' @details The function returns a \code{data.frame} with columns \code{"resistant"} and \code{"visual_resistance"}. The values in that columns are calculated with \code{\link{portion_R}}. #' @return \code{data.frame} with column names of \code{tbl} as row names #' @inheritSection AMR Read more on our website! -#' @importFrom clean percentage +# @importFrom clean percentage #' @export #' @examples #' availability(example_isolates) diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R index 088d58b3..1fd726a3 100644 --- a/R/bug_drug_combinations.R +++ b/R/bug_drug_combinations.R @@ -33,7 +33,7 @@ #' @inheritParams base::formatC #' @importFrom dplyr %>% rename group_by select mutate filter pull #' @importFrom tidyr spread -#' @importFrom clean freq percentage +# @importFrom clean freq percentage #' @details The function \code{format} calculates the resistance per bug-drug combination. Use \code{combine_IR = FALSE} (default) to test R vs. S+I and \code{combine_IR = TRUE} to test R+I vs. S. #' #' The language of the output can be overwritten with \code{options(AMR_locale)}, please see \link{translate}. diff --git a/R/first_isolate.R b/R/first_isolate.R index 9b4becd3..3e2aa3d9 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -75,7 +75,7 @@ #' @export #' @importFrom dplyr arrange_at lag between row_number filter mutate arrange pull ungroup #' @importFrom crayon blue bold silver -#' @importFrom clean percentage +# @importFrom clean percentage #' @return Logical vector #' @source Methodology of this function is based on: \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}. #' @inheritSection AMR Read more on our website! diff --git a/R/freq.R b/R/freq.R index 62aa56f7..120b9697 100755 --- a/R/freq.R +++ b/R/freq.R @@ -25,7 +25,8 @@ clean::freq #' @exportMethod freq.mo #' @importFrom dplyr n_distinct -#' @importFrom clean freq.default percentage +#' @importFrom clean freq.default +# @importFrom clean percentage #' @export #' @noRd freq.mo <- function(x, ...) { diff --git a/R/ggplot_rsi.R b/R/ggplot_rsi.R index cfb1ec5d..fca3c869 100755 --- a/R/ggplot_rsi.R +++ b/R/ggplot_rsi.R @@ -337,7 +337,7 @@ facet_rsi <- function(facet = c("interpretation", "antibiotic"), nrow = NULL) { } #' @rdname ggplot_rsi -#' @importFrom clean percentage +# @importFrom clean percentage #' @export scale_y_percent <- function(breaks = seq(0, 1, 0.1), limits = NULL) { stopifnot_installed_package("ggplot2") @@ -387,7 +387,7 @@ theme_rsi <- function() { #' @rdname ggplot_rsi #' @importFrom dplyr mutate %>% group_by_at -#' @importFrom clean percentage +# @importFrom clean percentage #' @export labels_rsi_count <- function(position = NULL, x = "antibiotic", diff --git a/R/misc.R b/R/misc.R index 70753c68..3408f1ee 100755 --- a/R/misc.R +++ b/R/misc.R @@ -127,3 +127,45 @@ class_integrity_check <- function(value, type, check_vector) { } value } + + + + +# Percentages ------------------------------------------------------------- +# Can all be removed when clean 1.2.0 is on CRAN + +getdecimalplaces <- function(x, minimum = 0, maximum = 3) { + if (maximum < minimum) { + maximum <- minimum + } + if (minimum > maximum) { + minimum <- maximum + } + max_places <- max(unlist(lapply(strsplit(sub('0+$', '', + as.character(x * 100)), ".", fixed = TRUE), + function(y) ifelse(length(y) == 2, nchar(y[2]), 0))), na.rm = TRUE) + max(min(max_places, + maximum, na.rm = TRUE), + minimum, na.rm = TRUE) +} + +round2 <- function(x, digits = 0, force_zero = TRUE) { + # https://stackoverflow.com/a/12688836/4575331 + val <- (trunc((abs(x) * 10 ^ digits) + 0.5) / 10 ^ digits) * sign(x) + if (digits > 0 & force_zero == TRUE) { + val[val != as.integer(val)] <- paste0(val[val != as.integer(val)], + strrep("0", max(0, digits - nchar(gsub(".*[.](.*)$", "\\1", val[val != as.integer(val)]))))) + } + val +} + +percentage <- function(x, digits = NULL, ...) { + if (is.null(digits)) { + digits <- getdecimalplaces(x, minimum = 0, maximum = 1) + } + # round right: percentage(0.4455) should return "44.6%", not "44.5%" + x <- as.numeric(round2(x, digits = digits + 2)) + x_formatted <- format(as.double(x) * 100, scientific = FALSE, digits = digits, nsmall = digits, ...) + x_formatted[!is.na(x)] <- paste0(x_formatted[!is.na(x)], "%") + x_formatted +} diff --git a/R/mo.R b/R/mo.R index a712f6bd..d4f8ca1a 100755 --- a/R/mo.R +++ b/R/mo.R @@ -268,7 +268,7 @@ is.mo <- function(x) { #' @importFrom dplyr %>% pull left_join n_distinct progress_estimated filter distinct #' @importFrom data.table data.table as.data.table setkey #' @importFrom crayon magenta red blue silver italic -#' @importFrom clean percentage +# @importFrom clean percentage # param property a column name of AMR::microorganisms # param initial_search logical - is FALSE when coming from uncertain tries, which uses exec_as.mo internally too # param dyslexia_mode logical - also check for characters that resemble others diff --git a/R/portion.R b/R/portion.R index bffd5ed0..7357eb32 100755 --- a/R/portion.R +++ b/R/portion.R @@ -26,7 +26,7 @@ #' \code{portion_R} and \code{portion_IR} can be used to calculate resistance, \code{portion_S} and \code{portion_SI} can be used to calculate susceptibility.\cr #' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See Examples. #' @param minimum the minimum allowed number of available (tested) isolates. Any isolate count lower than \code{minimum} will return \code{NA} with a warning. The default number of \code{30} isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see Source. -#' @param as_percent a logical to indicate whether the output must be returned as a hundred fold with \% sign (a character) using\code{\link[clean]{percentage}}. A value of \code{0.123456} will then be returned as \code{"12.3\%"}. +#' @param as_percent a logical to indicate whether the output must be returned as a hundred fold with \% sign (a character). A value of \code{0.123456} will then be returned as \code{"12.3\%"}. #' @param only_all_tested (for combination therapies, i.e. using more than one variable for \code{...}) a logical to indicate that isolates must be tested for all antibiotics, see section \emph{Combination therapy} below #' @param data a \code{data.frame} containing columns with class \code{rsi} (see \code{\link{as.rsi}}) #' @param translate_ab a column name of the \code{\link{antibiotics}} data set to translate the antibiotic abbreviations to, using \code{\link{ab_property}} diff --git a/R/rsi_calc.R b/R/rsi_calc.R index 0947eef4..673fbcc6 100755 --- a/R/rsi_calc.R +++ b/R/rsi_calc.R @@ -39,7 +39,7 @@ dots2vars <- function(...) { } #' @importFrom dplyr %>% pull all_vars any_vars filter_all funs mutate_all -#' @importFrom clean percentage +# @importFrom clean percentage rsi_calc <- function(..., ab_result, minimum = 0, diff --git a/data/antibiotics.rda b/data/antibiotics.rda index aef6b59d..169e04d2 100755 Binary files a/data/antibiotics.rda and b/data/antibiotics.rda differ diff --git a/docs/404.html b/docs/404.html index 74fd8376..5df817b2 100644 --- a/docs/404.html +++ b/docs/404.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9091 + 0.7.1.9092 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 8d0f7a2c..d13acc85 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9091 + 0.7.1.9092 diff --git a/docs/articles/index.html b/docs/articles/index.html index d29c7f1c..b5bbc7ce 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9091 + 0.7.1.9092 diff --git a/docs/authors.html b/docs/authors.html index 5a58e51a..106d680b 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9091 + 0.7.1.9092 diff --git a/docs/index.html b/docs/index.html index c4a8c384..68a074cc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 0.7.1.9091 + 0.7.1.9092 diff --git a/docs/news/index.html b/docs/news/index.html index dd2a53ef..ddf79212 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9091 + 0.7.1.9092 @@ -231,11 +231,11 @@ -
+

-AMR 0.7.1.9091 Unreleased +AMR 0.7.1.9092 Unreleased

-

Last updated: 30-Sep-2019

+

Last updated: 04-Oct-2019

Breaking

@@ -336,6 +336,8 @@ Since this is a major change, usage of the old also_single_tested w
  • Changed most microorganism IDs to improve readability. For example, the old code B_ENTRC_FAE could have been both E. faecalis and E. faecium. Its new code is B_ENTRC_FCLS and E. faecium has become B_ENTRC_FACM. Also, the Latin character æ (ae) is now preserved at the start of each genus and species abbreviation. For example, the old code for Aerococcus urinae was B_ARCCC_NAE. This is now B_AERCC_URIN. IMPORTANT: Old microorganism IDs are still supported, but support will be dropped in a future version. Use as.mo() on your old codes to transform them to the new format. Using functions from the mo_* family (like mo_name() and mo_gramstain()) on old codes, will throw a warning.
  • +
  • More intelligent guessing for as.ab() +
  • Renamed data set septic_patients to example_isolates
  • Function eucast_rules(): @@ -1288,7 +1290,7 @@ Using as.mo(..., allow_uncertain = 3)

    Contents

  • @@ -189,7 +194,6 @@ - -
    +
    @@ -229,15 +234,13 @@
    -

    Use this function to determine the antibiotic code of one or more antibiotics. The data set antibiotics will be searched for abbreviations, official names and synonyms (brand names).

    -
    -
    as.ab(x)
    +    
    as.ab(x, ...)
     
     is.ab(x)
    - +

    Arguments

    @@ -245,46 +248,46 @@ + + + +
    x

    character vector to determine to antibiotic ID

    ...

    arguments passed on to internal functions

    - +

    Value

    Character (vector) with class "ab". Unknown values will return NA.

    -

    Details

    All entries in the antibiotics data set have three different identifiers: a human readable EARS-Net code (column ab, used by ECDC and WHONET), an ATC code (column atc, used by WHO), and a CID code (column cid, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem.

    Use the ab_property functions to get properties based on the returned antibiotic ID, see Examples.

    -

    Source

    -

    World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: https://www.whocc.no/atc_ddd_index/

    + +

    World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: https://www.whocc.no/atc_ddd_index/

    WHONET 2019 software: http://www.whonet.org/software.html

    European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: http://ec.europa.eu/health/documents/community-register/html/atc.htm

    -

    WHOCC

    -


    + +


    This package contains all ~450 antimicrobial drugs and their Anatomical Therapeutic Chemical (ATC) codes, ATC groups and Defined Daily Dose (DDD) from the World Health Organization Collaborating Centre for Drug Statistics Methodology (WHOCC, https://www.whocc.no) and the Pharmaceuticals Community Register of the European Commission (http://ec.europa.eu/health/documents/community-register/html/atc.htm).

    These have become the gold standard for international drug utilisation monitoring and research.

    The WHOCC is located in Oslo at the Norwegian Institute of Public Health and funded by the Norwegian government. The European Commission is the executive of the European Union and promotes its general interest.

    NOTE: The WHOCC copyright does not allow use for commercial purposes, unlike any other info from this package. See https://www.whocc.no/copyright_disclaimer/.

    -

    Read more on our website!

    -

    On our website https://msberends.gitlab.io/AMR you can find a tutorial about how to conduct AMR analysis, the complete documentation of all functions (which reads a lot easier than here in R) and an example analysis using WHONET data.

    - + +

    On our website https://msberends.gitlab.io/AMR you can find a tutorial about how to conduct AMR analysis, the complete documentation of all functions (which reads a lot easier than here in R) and an example analysis using WHONET data.

    See also

    antibiotics for the dataframe that is being used to determine ATCs.

    -

    Examples

    -
    # NOT RUN {
    -# These examples all return "ERY", the ID of Erythromycin:
    +    
    # These examples all return "ERY", the ID of Erythromycin:
     as.ab("J01FA01")
     as.ab("J 01 FA 01")
     as.ab("Erythromycin")
    @@ -299,40 +302,34 @@ This package contains all ~450 antimicrobial drugs and their An
     # Use ab_* functions to get a specific properties (see ?ab_property);
     # they use as.ab() internally:
     ab_name("J01FA01")    # "Erythromycin"
    -ab_name("eryt")       # "Erythromycin"
    -# }
    +ab_name("eryt") # "Erythromycin"
    + @@ -355,6 +352,8 @@ This package contains all ~450 antimicrobial drugs and their An + + diff --git a/docs/reference/index.html b/docs/reference/index.html index 9bcad9df..d330c5a6 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -84,7 +84,7 @@ AMR (for R) - 0.7.1.9091 + 0.7.1.9092 diff --git a/docs/reference/portion.html b/docs/reference/portion.html index b40651ae..1c87d2e8 100644 --- a/docs/reference/portion.html +++ b/docs/reference/portion.html @@ -86,7 +86,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port AMR (for R) - 0.7.1.9091 + 0.7.1.9092 @@ -275,7 +275,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port as_percent -

    a logical to indicate whether the output must be returned as a hundred fold with % sign (a character) usingpercentage. A value of 0.123456 will then be returned as "12.3%".

    +

    a logical to indicate whether the output must be returned as a hundred fold with % sign (a character). A value of 0.123456 will then be returned as "12.3%".

    only_all_tested diff --git a/man/as.ab.Rd b/man/as.ab.Rd index 6c2b735a..ab111a78 100644 --- a/man/as.ab.Rd +++ b/man/as.ab.Rd @@ -5,12 +5,14 @@ \alias{is.ab} \title{Transform to antibiotic ID} \usage{ -as.ab(x) +as.ab(x, ...) is.ab(x) } \arguments{ \item{x}{character vector to determine to antibiotic ID} + +\item{...}{arguments passed on to internal functions} } \value{ Character (vector) with class \code{"ab"}. Unknown values will return \code{NA}. diff --git a/man/portion.Rd b/man/portion.Rd index f81d52c9..eedfb654 100644 --- a/man/portion.Rd +++ b/man/portion.Rd @@ -44,7 +44,7 @@ rsi_df(data, translate_ab = "name", language = get_locale(), \item{minimum}{the minimum allowed number of available (tested) isolates. Any isolate count lower than \code{minimum} will return \code{NA} with a warning. The default number of \code{30} isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see Source.} -\item{as_percent}{a logical to indicate whether the output must be returned as a hundred fold with \% sign (a character) using\code{\link[clean]{percentage}}. A value of \code{0.123456} will then be returned as \code{"12.3\%"}.} +\item{as_percent}{a logical to indicate whether the output must be returned as a hundred fold with \% sign (a character). A value of \code{0.123456} will then be returned as \code{"12.3\%"}.} \item{only_all_tested}{(for combination therapies, i.e. using more than one variable for \code{...}) a logical to indicate that isolates must be tested for all antibiotics, see section \emph{Combination therapy} below} diff --git a/tests/testthat/test-ab.R b/tests/testthat/test-ab.R index 11354ac7..9fff9f13 100755 --- a/tests/testthat/test-ab.R +++ b/tests/testthat/test-ab.R @@ -53,6 +53,9 @@ test_that("as.ab works", { expect_equal(suppressWarnings(as.character(as.ab(c("Bacteria", "Bacterial")))), c(NA, "TMP")) + + expect_equal(as.character(as.ab("Amoxy + clavulaanzuur")), + "AMC") # assigning and subsetting x <- antibiotics$ab diff --git a/tests/testthat/test-misc.R b/tests/testthat/test-misc.R index 8702b1ab..9eeec400 100755 --- a/tests/testthat/test-misc.R +++ b/tests/testthat/test-misc.R @@ -21,6 +21,16 @@ context("misc.R") +test_that("percentages works", { + expect_equal(percentage(0.25), "25%") + expect_equal(percentage(0.5), "50%") + expect_equal(percentage(0.500, digits = 1), "50.0%") + expect_equal(percentage(0.1234), "12.3%") + # round up 0.5 + expect_equal(percentage(0.0054), "0.5%") + expect_equal(percentage(0.0055), "0.6%") +}) + test_that("functions missing in older R versions work", { expect_equal(strrep("A", 5), "AAAAA") expect_equal(strrep(c("A", "B"), c(5, 2)), c("AAAAA", "BB"))