From c2a93b46db193c9ad1c1dfcaf22aab6d20c2bd48 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Mon, 22 Oct 2018 12:32:59 +0200 Subject: [PATCH] breaks param, tidyr dep change, freq markdown --- DESCRIPTION | 15 +++-- NEWS.md | 8 ++- R/abname.R | 23 ++++---- R/atc.R | 8 ++- R/freq.R | 111 +++++++---------------------------- R/ggplot_rsi.R | 10 ++-- README.md | 14 +++-- man/as.atc.Rd | 1 + man/freq.Rd | 26 +++----- man/ggplot_rsi.Rd | 11 ++-- tests/testthat/test-abname.R | 5 +- 11 files changed, 86 insertions(+), 146 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 54bff7fd..4ac31f72 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.4.0.9005 -Date: 2018-10-19 +Version: 0.4.0.9006 +Date: 2018-10-22 Title: Antimicrobial Resistance Analysis Authors@R: c( person( @@ -38,10 +38,9 @@ Authors@R: c( email = "b.sinha@umcg.nl", role = "ths", comment = c(ORCID = "0000-0003-1634-0010"))) -Description: Functions to simplify the analysis of Antimicrobial Resistance (AMR) - of microbial isolates, by using new S3 classes and applying EUCAST expert rules - on antibiograms according to Leclercq (2013) - . +Description: Functions to simplify the analysis and prediction of Antimicrobial + Resistance (AMR) and work with microbial and antimicrobial properties by using + evidence-based methods. Depends: R (>= 3.1.0) Imports: @@ -54,14 +53,14 @@ Imports: knitr (>= 1.0.0), rlang (>= 0.2.0), rvest (>= 0.3.2), + tidyr (>= 0.7.0), xml2 (>= 1.0.0) Suggests: covr (>= 3.0.1), ggplot2, rmarkdown, rstudioapi, - testthat (>= 1.0.2), - tidyr + testthat (>= 1.0.2) VignetteBuilder: knitr URL: https://github.com/msberends/AMR BugReports: https://github.com/msberends/AMR/issues diff --git a/NEWS.md b/NEWS.md index 7a0ba270..40b7f01a 100755 --- a/NEWS.md +++ b/NEWS.md @@ -17,25 +17,29 @@ * Fix for `portion_*(..., as_percent = TRUE)` when minimal amount of isolates would not be met * Added parameter `also_single_tested` for `portion_*` and `count_*` functions to also include cases where not all antibiotics were tested but at least one of the tested antibiotics includes the target antimicribial interpretation, see `?portion` * Using `portion_*` functions now throws a warning when total available isolate is below parameter `minimum` -* Functions `as.mo`, `as.rsi` and `as.mic` will not set package name as attribute anymore +* Functions `as.mo`, `as.rsi`, `as.mic` and `as.atc` will not set package name as attribute anymore * Data set `septic_patients` is now a `data.frame`, not a tibble anymore * Check for `hms::is.hms` in frequency tables (`freq()`) * New parameter `header` for frequency tables to turn them off (default when `markdown = TRUE`) +* Freq now prints in markdown at default in non-interactive sessions * Removed diacritics from all authors (columns `microorganisms$ref` and `microorganisms.old$ref`) to comply with CRAN policy to only allow ASCII characters * Fix for `mo_property` not working properly * Fix for `EUCAST_rules` where some Streptococci would become ceftazidime R in EUCAST rule 4.5 * Support for class `difftime` in frequency tables * Support for named vectors of class `mo`, useful for `top_freq()` +* `ggplot_rsi` and `scale_y_percent` have `breaks` parameter * AI improvements for `as.mo`: * `"CRS"` -> *Stenotrophomonas maltophilia* * `"CRSM"` -> *Stenotrophomonas maltophilia* * `"MSSA"` -> *Staphylococcus aureus* * `"MSSE"` -> *Staphylococcus epidermidis* * Fix for `join` functions -* In `g.test`, when `sum(x)` is below 1000, suggest Fisher's Exact Test +* In `g.test`, when `sum(x)` is below 1000 or any of the expected values is below 5, Fisher's Exact Test will be suggested +* `ab_name` will try to fall back on `as.atc` when no results are found #### Other * New dependency on package `crayon`, to support formatted text in the console +* Dependency `tidyr` is now mandatory (went to `Import` field) since `portion_df` and `count_df` rely on it * Updated vignettes to comply with README diff --git a/R/abname.R b/R/abname.R index 7105ba75..333a0e63 100644 --- a/R/abname.R +++ b/R/abname.R @@ -133,18 +133,19 @@ abname <- function(abcode, abcode[i] <- abx[which(abx[,from] == abcode[i]),] %>% pull(to) %>% .[1] } - # when nothing found, try first chars of official name - # if (is.na(abcode[i])) { - # abcode[i] <- antibiotics %>% - # filter(official %like% paste0('^', abcode.bak[i])) %>% - # pull(to) %>% - # .[1] - # next - # } - if (is.na(abcode[i]) | length(abcode[i] == 0)) { - abcode[i] <- abcode.bak[i] - warning('Code "', abcode.bak[i], '" not found in antibiotics list.', call. = FALSE) + # try as.atc + try(suppressWarnings( + abcode[i] <- as.atc(abcode[i]) + ), silent = TRUE) + if (is.na(abcode[i])) { + # still not found + abcode[i] <- abcode.bak[i] + warning('Code "', abcode.bak[i], '" not found in antibiotics list.', call. = FALSE) + } else { + # fill in the found ATC code + abcode[i] <- abname(abcode[i], from = "atc", to = to) + } } } diff --git a/R/atc.R b/R/atc.R index d27e408f..562b6b2c 100755 --- a/R/atc.R +++ b/R/atc.R @@ -37,6 +37,7 @@ #' as.atc("J01FA01") #' as.atc("Erythromycin") #' as.atc("eryt") +#' as.atc(" eryt 123") #' as.atc("ERYT") #' as.atc("ERY") #' as.atc("Erythrocin") # Trade name @@ -50,6 +51,10 @@ as.atc <- function(x) { x.new <- rep(NA_character_, length(x)) + x <- trimws(x, which = "both") + # keep only a-z when it's not an ATC code + x[!x %like% "[A-Z][0-9]{2}[A-Z]{2}[0-9]{2}"] <- gsub("[^a-zA-Z]+", "", x[!x %like% "[A-Z][0-9]{2}[A-Z]{2}[0-9]{2}"]) + x.bak <- x x <- unique(x[!is.na(x)]) failures <- character(0) @@ -64,7 +69,7 @@ as.atc <- function(x) { x.new[is.na(x.new) & x.bak == x[i]] <- found[1L] } - # try ATC in code form, even if it does not exist in the antibiotics data set YET + # try ATC in ATC code form, even if it does not exist in the antibiotics data set YET if (length(found) == 0 & x[i] %like% '[A-Z][0-9][0-9][A-Z][A-Z][0-9][0-9]') { warning("ATC code ", x[i], " is not yet in the `antibiotics` data set.") fail <- FALSE @@ -134,7 +139,6 @@ as.atc <- function(x) { call. = FALSE) } class(x.new) <- "atc" - attr(x.new, 'package') <- 'AMR' x.new } diff --git a/R/freq.R b/R/freq.R index 968135da..0d83d53d 100755 --- a/R/freq.R +++ b/R/freq.R @@ -23,10 +23,10 @@ #' @param ... up to nine different columns of \code{x} when \code{x} is a \code{data.frame} or \code{tibble}, to calculate frequencies from - see Examples #' @param sort.count sort on count, i.e. frequencies. This will be \code{TRUE} at default for everything except for factors. #' @param nmax number of row to print. The default, \code{15}, uses \code{\link{getOption}("max.print.freq")}. Use \code{nmax = 0}, \code{nmax = Inf}, \code{nmax = NULL} or \code{nmax = NA} to print all rows. -#' @param na.rm a logical value indicating whether \code{NA} values should be removed from the frequency table. The header_txt will always print the amount of \code{NA}s. +#' @param na.rm a logical value indicating whether \code{NA} values should be removed from the frequency table. The header will always print the amount of \code{NA}s. #' @param row.names a logical value indicating whether row indices should be printed as \code{1:nrow(x)} -#' @param markdown print table in markdown format (this forces \code{nmax = NA}) -#' @param digits how many significant digits are to be used for numeric values in the header_txt (not for the items themselves, that depends on \code{\link{getOption}("digits")}) +#' @param markdown a logical value indicating whether the frequency table should be printed in markdown format. This will print all rows and is default behaviour in non-interactive R sessions (like when knitting RMarkdown files). +#' @param digits how many significant digits are to be used for numeric values in the header (not for the items themselves, that depends on \code{\link{getOption}("digits")}) #' @param quote a logical value indicating whether or not strings should be printed with surrounding quotes #' @param header a logical value indicating whether an informative header should be printed #' @param sep a character string to separate the terms when selecting multiple columns @@ -34,7 +34,7 @@ #' @param n number of top \emph{n} items to return, use -n for the bottom \emph{n} items. It will include more than \code{n} rows if there are ties. #' @details Frequency tables (or frequency distributions) are summaries of the distribution of values in a sample. With the `freq` function, you can create univariate frequency tables. Multiple variables will be pasted into one variable, so it forces a univariate distribution. This package also has a vignette available to explain the use of this function further, run \code{browseVignettes("AMR")} to read it. #' -#' For numeric values of any class, these additional values will all be calculated with \code{na.rm = TRUE} and shown into the header_txt: +#' For numeric values of any class, these additional values will all be calculated with \code{na.rm = TRUE} and shown into the header: #' \itemize{ #' \item{Mean, using \code{\link[base]{mean}}} #' \item{Standard Deviation, using \code{\link[stats]{sd}}} @@ -46,7 +46,7 @@ #' \item{Outliers (total count and unique count), using \code{\link[grDevices]{boxplot.stats}}} #' } #' -#' For dates and times of any class, these additional values will be calculated with \code{na.rm = TRUE} and shown into the header_txt: +#' For dates and times of any class, these additional values will be calculated with \code{na.rm = TRUE} and shown into the header: #' \itemize{ #' \item{Oldest, using \code{\link{min}}} #' \item{Newest, using \code{\link{max}}, with difference between newest and oldest} @@ -140,21 +140,13 @@ #' # check differences between frequency tables #' diff(freq(septic_patients$trim), #' freq(septic_patients$trsu)) -#' -#' \dontrun{ -#' # send frequency table to clipboard (e.g. for pasting in Excel) -#' septic_patients %>% -#' freq(age) %>% -#' format() %>% # this will format the percentages -#' clipboard_export() -#' } frequency_tbl <- function(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE, - markdown = FALSE, + markdown = !interactive(), digits = 2, quote = FALSE, header = !markdown, @@ -201,17 +193,14 @@ frequency_tbl <- function(x, cols <- NULL } } else if (any(class(x) == 'table')) { - if (!"tidyr" %in% rownames(installed.packages())) { - stop('transformation from `table` to frequency table requires the tidyr package.', call. = FALSE) - } - x <- x %>% - as.data.frame(stringsAsFactors = FALSE) %>% - # paste first two columns - tidyr::unite(col = "Pasted", 1:2, sep = sep, remove = TRUE) - x <- rep(x %>% pull(Pasted), x %>% pull(Freq)) + x <- as.data.frame(x, stringsAsFactors = FALSE) + # now this DF contains 3 columns: the 2 vars and a Freq column + # paste the first 2 cols and repeat them Freq times: + x <- rep(x = do.call(paste, c(x[colnames(x)[1:2]], sep = sep)), + times = x$Freq) x.name <- "a `table` object" cols <- NULL - mult.columns <- 2 + #mult.columns <- 2 } else { x.name <- NULL cols <- NULL @@ -221,74 +210,8 @@ frequency_tbl <- function(x, if (ncol(x) == 1 & any(class(x) == 'data.frame')) { x <- x %>% pull(1) } else if (ncol(x) < 10) { - mult.columns <- ncol(x) - - colnames(x) <- LETTERS[1:ncol(x)] - if (ncol(x) == 2) { - x$total <- paste(x$A %>% as.character(), - x$B %>% as.character(), - sep = sep) - } else if (ncol(x) == 3) { - x$total <- paste(x$A %>% as.character(), - x$B %>% as.character(), - x$C %>% as.character(), - sep = sep) - } else if (ncol(x) == 4) { - x$total <- paste(x$A %>% as.character(), - x$B %>% as.character(), - x$C %>% as.character(), - x$D %>% as.character(), - sep = sep) - } else if (ncol(x) == 5) { - x$total <- paste(x$A %>% as.character(), - x$B %>% as.character(), - x$C %>% as.character(), - x$D %>% as.character(), - x$E %>% as.character(), - sep = sep) - } else if (ncol(x) == 6) { - x$total <- paste(x$A %>% as.character(), - x$B %>% as.character(), - x$C %>% as.character(), - x$D %>% as.character(), - x$E %>% as.character(), - x$F %>% as.character(), - sep = sep) - } else if (ncol(x) == 7) { - x$total <- paste(x$A %>% as.character(), - x$B %>% as.character(), - x$C %>% as.character(), - x$D %>% as.character(), - x$E %>% as.character(), - x$F %>% as.character(), - x$G %>% as.character(), - sep = sep) - } else if (ncol(x) == 8) { - x$total <- paste(x$A %>% as.character(), - x$B %>% as.character(), - x$C %>% as.character(), - x$D %>% as.character(), - x$E %>% as.character(), - x$F %>% as.character(), - x$G %>% as.character(), - x$H %>% as.character(), - sep = sep) - } else if (ncol(x) == 9) { - x$total <- paste(x$A %>% as.character(), - x$B %>% as.character(), - x$C %>% as.character(), - x$D %>% as.character(), - x$E %>% as.character(), - x$F %>% as.character(), - x$G %>% as.character(), - x$H %>% as.character(), - x$I %>% as.character(), - sep = sep) - } - - x <- x$total - + x <- do.call(paste, c(x[colnames(x)], sep = sep)) } else { stop('A maximum of 9 columns can be analysed at the same time.', call. = FALSE) } @@ -585,7 +508,7 @@ diff.frequency_tbl <- function(x, y, ...) { #' @exportMethod print.frequency_tbl #' @importFrom knitr kable #' @importFrom dplyr n_distinct -#' @importFrom crayon bold +#' @importFrom crayon bold silver #' @export print.frequency_tbl <- function(x, nmax = getOption("max.print.freq", default = 15), ...) { @@ -629,6 +552,9 @@ print.frequency_tbl <- function(x, nmax = getOption("max.print.freq", default = if (!is.null(opt$header_txt)) { cat(opt$header_txt) } + } else if (opt$tbl_format == "markdown") { + # do print title as caption in markdown + cat("\n", title, sep = "") } if (NROW(x) == 0) { @@ -671,6 +597,9 @@ print.frequency_tbl <- function(x, nmax = getOption("max.print.freq", default = ' (', (x.unprinted / (x.unprinted + x.printed)) %>% percent(force_zero = TRUE), ') ]\n', sep = '') + if (opt$tbl_format == "pandoc") { + footer <- silver(footer) # only silver in regular printing + } } else { footer <- NULL } diff --git a/R/ggplot_rsi.R b/R/ggplot_rsi.R index 4a047793..38bd527b 100644 --- a/R/ggplot_rsi.R +++ b/R/ggplot_rsi.R @@ -23,6 +23,7 @@ #' @param position position adjustment of bars, either \code{"fill"} (default when \code{fun} is \code{\link{count_df}}), \code{"stack"} (default when \code{fun} is \code{\link{portion_df}}) or \code{"dodge"} #' @param x variable to show on x axis, either \code{"Antibiotic"} (default) or \code{"Interpretation"} or a grouping variable #' @param fill variable to categorise using the plots legend, either \code{"Antibiotic"} (default) or \code{"Interpretation"} or a grouping variable +#' @param breaks numeric vector of positions #' @param facet variable to split plots by, either \code{"Interpretation"} (default) or \code{"Antibiotic"} or a grouping variable #' @param translate_ab a column name of the \code{\link{antibiotics}} data set to translate the antibiotic abbreviations into, using \code{\link{abname}}. Default behaviour is to translate to official names according to the WHO. Use \code{translate_ab = FALSE} to disable translation. #' @param fun function to transform \code{data}, either \code{\link{count_df}} (default) or \code{\link{portion_df}} @@ -136,6 +137,7 @@ ggplot_rsi <- function(data, fill = "Interpretation", # params = list(), facet = NULL, + breaks = seq(0, 1, 0.1), translate_ab = "official", fun = count_df, nrow = NULL, @@ -189,7 +191,7 @@ ggplot_rsi <- function(data, if (fun_name == "portion_df" | (fun_name == "count_df" & position == "fill")) { # portions, so use y scale with percentage - p <- p + scale_y_percent() + p <- p + scale_y_percent(breaks = breaks) } if (fun_name == "count_df" & datalabels == TRUE) { @@ -281,9 +283,9 @@ facet_rsi <- function(facet = c("Interpretation", "Antibiotic"), nrow = NULL) { #' @rdname ggplot_rsi #' @export -scale_y_percent <- function() { - ggplot2::scale_y_continuous(breaks = seq(0, 1, 0.1), - labels = percent(seq(0, 1, 0.1))) +scale_y_percent <- function(breaks = seq(0, 1, 0.1)) { + ggplot2::scale_y_continuous(breaks = breaks, + labels = percent(breaks)) } #' @rdname ggplot_rsi diff --git a/README.md b/README.md index c81b3a47..12010865 100755 --- a/README.md +++ b/README.md @@ -3,15 +3,17 @@ This R package was created for academic research by PhD students of the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl) and the Medical Microbiology & Infection Prevention (MMBI) department of the [University Medical Center Groningen (UMCG)](https://www.umcg.nl). -:arrow_forward: Get it with `install.packages("AMR")` or see below for other possibilities. Read all changes and new functions in **[NEWS.md](https://github.com/msberends/AMR/blob/master/NEWS.md)**. +:arrow_forward: Get it with `install.packages("AMR")` or see below for other possibilities. + +:arrow_forward: Read the [changelog here](https://github.com/msberends/AMR/blob/master/NEWS.md). ## Authors - Matthijs S. Berends1,2,a, - Christian F. Luz1,a, +Matthijs S. Berends 1,2,a, +Christian F. Luz 1,a, Erwin E.A. Hassing2, - Corinna Glasner1,b, - Alex W. Friedrich1,b, - Bhanu Sinha1,b +Corinna Glasner 1,b, +Alex W. Friedrich 1,b, +Bhanu Sinha 1,b 1 Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - [rug.nl](http://www.rug.nl) [umcg.nl](http://www.umcg.nl)
2 Certe Medical Diagnostics & Advice, Groningen, the Netherlands - [certe.nl](http://www.certe.nl)
diff --git a/man/as.atc.Rd b/man/as.atc.Rd index 445be02f..68159d82 100644 --- a/man/as.atc.Rd +++ b/man/as.atc.Rd @@ -33,6 +33,7 @@ In the ATC classification system, the active substances are classified in a hier as.atc("J01FA01") as.atc("Erythromycin") as.atc("eryt") +as.atc(" eryt 123") as.atc("ERYT") as.atc("ERY") as.atc("Erythrocin") # Trade name diff --git a/man/freq.Rd b/man/freq.Rd index f69f2575..1dbec7be 100755 --- a/man/freq.Rd +++ b/man/freq.Rd @@ -9,12 +9,12 @@ \usage{ frequency_tbl(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE, - markdown = FALSE, digits = 2, quote = FALSE, header = !markdown, - sep = " ") + markdown = !interactive(), digits = 2, quote = FALSE, + header = !markdown, sep = " ") freq(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"), - na.rm = TRUE, row.names = TRUE, markdown = FALSE, digits = 2, - quote = FALSE, header = !markdown, sep = " ") + na.rm = TRUE, row.names = TRUE, markdown = !interactive(), + digits = 2, quote = FALSE, header = !markdown, sep = " ") top_freq(f, n) @@ -30,13 +30,13 @@ top_freq(f, n) \item{nmax}{number of row to print. The default, \code{15}, uses \code{\link{getOption}("max.print.freq")}. Use \code{nmax = 0}, \code{nmax = Inf}, \code{nmax = NULL} or \code{nmax = NA} to print all rows.} -\item{na.rm}{a logical value indicating whether \code{NA} values should be removed from the frequency table. The header_txt will always print the amount of \code{NA}s.} +\item{na.rm}{a logical value indicating whether \code{NA} values should be removed from the frequency table. The header will always print the amount of \code{NA}s.} \item{row.names}{a logical value indicating whether row indices should be printed as \code{1:nrow(x)}} -\item{markdown}{print table in markdown format (this forces \code{nmax = NA})} +\item{markdown}{a logical value indicating whether the frequency table should be printed in markdown format. This will print all rows and is default behaviour in non-interactive R sessions (like when knitting RMarkdown files).} -\item{digits}{how many significant digits are to be used for numeric values in the header_txt (not for the items themselves, that depends on \code{\link{getOption}("digits")})} +\item{digits}{how many significant digits are to be used for numeric values in the header (not for the items themselves, that depends on \code{\link{getOption}("digits")})} \item{quote}{a logical value indicating whether or not strings should be printed with surrounding quotes} @@ -57,7 +57,7 @@ Create a frequency table of a vector with items or a data frame. Supports quasiq \details{ Frequency tables (or frequency distributions) are summaries of the distribution of values in a sample. With the `freq` function, you can create univariate frequency tables. Multiple variables will be pasted into one variable, so it forces a univariate distribution. This package also has a vignette available to explain the use of this function further, run \code{browseVignettes("AMR")} to read it. -For numeric values of any class, these additional values will all be calculated with \code{na.rm = TRUE} and shown into the header_txt: +For numeric values of any class, these additional values will all be calculated with \code{na.rm = TRUE} and shown into the header: \itemize{ \item{Mean, using \code{\link[base]{mean}}} \item{Standard Deviation, using \code{\link[stats]{sd}}} @@ -69,7 +69,7 @@ For numeric values of any class, these additional values will all be calculated \item{Outliers (total count and unique count), using \code{\link[grDevices]{boxplot.stats}}} } -For dates and times of any class, these additional values will be calculated with \code{na.rm = TRUE} and shown into the header_txt: +For dates and times of any class, these additional values will be calculated with \code{na.rm = TRUE} and shown into the header: \itemize{ \item{Oldest, using \code{\link{min}}} \item{Newest, using \code{\link{max}}, with difference between newest and oldest} @@ -153,14 +153,6 @@ table(septic_patients$gender, # check differences between frequency tables diff(freq(septic_patients$trim), freq(septic_patients$trsu)) - -\dontrun{ -# send frequency table to clipboard (e.g. for pasting in Excel) -septic_patients \%>\% - freq(age) \%>\% - format() \%>\% # this will format the percentages - clipboard_export() -} } \keyword{freq} \keyword{frequency} diff --git a/man/ggplot_rsi.Rd b/man/ggplot_rsi.Rd index 9dc03650..36fc6f25 100644 --- a/man/ggplot_rsi.Rd +++ b/man/ggplot_rsi.Rd @@ -11,9 +11,10 @@ \title{AMR bar plots with \code{ggplot}} \usage{ ggplot_rsi(data, position = NULL, x = "Antibiotic", - fill = "Interpretation", facet = NULL, translate_ab = "official", - fun = count_df, nrow = NULL, datalabels = TRUE, - datalabels.size = 3, datalabels.colour = "grey15", ...) + fill = "Interpretation", facet = NULL, breaks = seq(0, 1, 0.1), + translate_ab = "official", fun = count_df, nrow = NULL, + datalabels = TRUE, datalabels.size = 3, + datalabels.colour = "grey15", ...) geom_rsi(position = NULL, x = c("Antibiotic", "Interpretation"), fill = "Interpretation", translate_ab = "official", fun = count_df, @@ -21,7 +22,7 @@ geom_rsi(position = NULL, x = c("Antibiotic", "Interpretation"), facet_rsi(facet = c("Interpretation", "Antibiotic"), nrow = NULL) -scale_y_percent() +scale_y_percent(breaks = seq(0, 1, 0.1)) scale_rsi_colours() @@ -41,6 +42,8 @@ labels_rsi_count(position = NULL, x = "Antibiotic", \item{facet}{variable to split plots by, either \code{"Interpretation"} (default) or \code{"Antibiotic"} or a grouping variable} +\item{breaks}{numeric vector of positions} + \item{translate_ab}{a column name of the \code{\link{antibiotics}} data set to translate the antibiotic abbreviations into, using \code{\link{abname}}. Default behaviour is to translate to official names according to the WHO. Use \code{translate_ab = FALSE} to disable translation.} \item{fun}{function to transform \code{data}, either \code{\link{count_df}} (default) or \code{\link{portion_df}}} diff --git a/tests/testthat/test-abname.R b/tests/testthat/test-abname.R index 9a1f963b..547ce4c9 100644 --- a/tests/testthat/test-abname.R +++ b/tests/testthat/test-abname.R @@ -13,7 +13,10 @@ test_that("abname works", { expect_error(abname("AMOX", to = c(1:3))) expect_error(abname("AMOX", to = "test")) - expect_warning(abname("TEST + expect_warning(abname("NOTEXISTING ")) expect_warning(abname("AMOX or GENT")) + + # this one is being found with as.atc internally + expect_equal(abname("flu_clox123"), "Flucloxacillin") })