diff --git a/DESCRIPTION b/DESCRIPTION index 4cad1a8a..51d8fb43 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.1.0.9011 -Date: 2020-05-18 +Version: 1.1.0.9012 +Date: 2020-05-19 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), @@ -35,12 +35,9 @@ Description: Functions to simplify the analysis and prediction of Antimicrobial and the Clinical and Laboratory Standards Institute (2014) . Depends: - R (>= 3.1.0) -Imports: - cleaner, - pillar, - vctrs + R (>= 3.0.0) Suggests: + cleaner, covr, dplyr, ggplot2, diff --git a/NAMESPACE b/NAMESPACE index d8c8a54d..1ab06665 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,7 +19,6 @@ S3method("[[<-",mic) S3method("[[<-",mo) S3method("[[<-",rsi) S3method(as.data.frame,ab) -S3method(as.data.frame,disk) S3method(as.data.frame,mo) S3method(as.double,mic) S3method(as.integer,mic) @@ -43,11 +42,6 @@ S3method(freq,rsi) S3method(kurtosis,data.frame) S3method(kurtosis,default) S3method(kurtosis,matrix) -S3method(pillar_shaft,ab) -S3method(pillar_shaft,disk) -S3method(pillar_shaft,mic) -S3method(pillar_shaft,mo) -S3method(pillar_shaft,rsi) S3method(plot,mic) S3method(plot,resistance_predict) S3method(plot,rsi) @@ -66,30 +60,6 @@ S3method(skewness,matrix) S3method(summary,mic) S3method(summary,mo) S3method(summary,rsi) -S3method(vec_cast.ab,ab) -S3method(vec_cast.ab,character) -S3method(vec_cast.ab,default) -S3method(vec_cast.character,ab) -S3method(vec_cast.character,mo) -S3method(vec_cast.mo,character) -S3method(vec_cast.mo,default) -S3method(vec_cast.mo,mo) -S3method(vec_ptype2.ab,character) -S3method(vec_ptype2.ab,default) -S3method(vec_ptype2.character,ab) -S3method(vec_ptype2.character,mo) -S3method(vec_ptype2.mo,character) -S3method(vec_ptype2.mo,default) -S3method(vec_ptype_abbr,ab) -S3method(vec_ptype_abbr,disk) -S3method(vec_ptype_abbr,mic) -S3method(vec_ptype_abbr,mo) -S3method(vec_ptype_abbr,rsi) -S3method(vec_ptype_full,ab) -S3method(vec_ptype_full,disk) -S3method(vec_ptype_full,mic) -S3method(vec_ptype_full,mo) -S3method(vec_ptype_full,rsi) export("%like%") export("%like_case%") export(ab_atc) @@ -147,7 +117,6 @@ export(filter_glycopeptides) export(filter_macrolides) export(filter_tetracyclines) export(first_isolate) -export(freq) export(full_join_microorganisms) export(g.test) export(geom_rsi) @@ -221,18 +190,12 @@ export(right_join_microorganisms) export(rsi_df) export(rsi_predict) export(scale_rsi_colours) -export(scale_type.ab) -export(scale_type.mo) export(scale_y_percent) export(semi_join_microorganisms) export(set_mo_source) export(skewness) export(susceptibility) export(theme_rsi) -export(vec_cast.ab) -export(vec_cast.mo) -export(vec_ptype2.ab) -export(vec_ptype2.mo) exportMethods("[.ab") exportMethods("[.disk") exportMethods("[.mic") @@ -252,7 +215,6 @@ exportMethods("[[<-.mic") exportMethods("[[<-.mo") exportMethods("[[<-.rsi") exportMethods(as.data.frame.ab) -exportMethods(as.data.frame.disk) exportMethods(as.data.frame.mo) exportMethods(as.double.mic) exportMethods(as.integer.mic) @@ -267,8 +229,6 @@ exportMethods(c.rsi) exportMethods(droplevels.mic) exportMethods(droplevels.rsi) exportMethods(format.bug_drug_combinations) -exportMethods(freq.mo) -exportMethods(freq.rsi) exportMethods(kurtosis) exportMethods(kurtosis.data.frame) exportMethods(kurtosis.default) @@ -284,8 +244,6 @@ exportMethods(print.mo) exportMethods(print.mo_renamed) exportMethods(print.mo_uncertainties) exportMethods(print.rsi) -exportMethods(scale_type.ab) -exportMethods(scale_type.mo) exportMethods(skewness) exportMethods(skewness.data.frame) exportMethods(skewness.default) @@ -293,22 +251,6 @@ exportMethods(skewness.matrix) exportMethods(summary.mic) exportMethods(summary.mo) exportMethods(summary.rsi) -exportMethods(vec_cast.character.ab) -exportMethods(vec_cast.character.mo) -exportMethods(vec_ptype2.character.ab) -exportMethods(vec_ptype2.character.mo) -exportMethods(vec_ptype_abbr.ab) -exportMethods(vec_ptype_abbr.disk) -exportMethods(vec_ptype_abbr.mic) -exportMethods(vec_ptype_abbr.mo) -exportMethods(vec_ptype_abbr.rsi) -exportMethods(vec_ptype_full.ab) -exportMethods(vec_ptype_full.disk) -exportMethods(vec_ptype_full.mic) -exportMethods(vec_ptype_full.mo) -exportMethods(vec_ptype_full.rsi) -importFrom(cleaner,freq) -importFrom(cleaner,freq.default) importFrom(graphics,arrows) importFrom(graphics,axis) importFrom(graphics,barplot) @@ -316,7 +258,6 @@ importFrom(graphics,par) importFrom(graphics,plot) importFrom(graphics,points) importFrom(graphics,text) -importFrom(pillar,pillar_shaft) importFrom(stats,complete.cases) importFrom(stats,glm) importFrom(stats,lm) @@ -325,9 +266,3 @@ importFrom(stats,prcomp) importFrom(stats,predict) importFrom(stats,qchisq) importFrom(stats,var) -importFrom(vctrs,vec_cast) -importFrom(vctrs,vec_cast.character) -importFrom(vctrs,vec_default_cast) -importFrom(vctrs,vec_ptype2.character) -importFrom(vctrs,vec_ptype_abbr) -importFrom(vctrs,vec_ptype_full) diff --git a/NEWS.md b/NEWS.md index 8e74f381..5fc07d9a 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,17 @@ -# AMR 1.1.0.9011 -## Last updated: 18-May-2020 +# AMR 1.1.0.9012 +## Last updated: 19-May-2020 ### Breaking -* Removed previously deprecated function `p.symbol()` - it was replaced with `p_symbol()` + +* Removed code dependency on **all** R packages that this `AMR` package relied upon: `cleaner`, `crayon`, `data.table`, `dplyr`, `ggplot2`, `knitr`, `microbenchmark`, `pillar`, `R6`, `rlang`, `tidyr` and `vctrs`. This is a major code change, but will probably not be noticeable by most users. + + Making this package independent on especially the tidyverse tremendously increases sustainability on the long term, since tidyverse functions change quite often. Most of our functions are replaced with versions that only rely on base R, which keeps this package fully functional for many years to come, without requiring a lot of maintenance to keep up with other packages anymore. Another upside it that this package can now be used with all versions of R since R-3.0.0 (April 2013). Our package is being used in settings where the resources are very limited. Fewer dependencies on newer software is helpful for such settings. + + Negative effects of this change are: + * Function `freq()` that was borrowed from the `cleaner` package was removed. Use `cleaner::freq()`, or run `library("cleaner")` before you use `freq()`. + * Printing values of class `mo` or `ab` in a tibble will no longer be in colour. + * All functions from the `mo_*` family (like `mo_name()` and `mo_gramstain()`) are noticeably slower when running on tens of thousands of rows. + * For developers: classes `mo` and `ab` now both also inherit class `character`, to support any data transformation. This change invalidates code that checks for class length == 1. ### Changed * Small fix for some text input that could not be coerced as valid MIC values @@ -11,7 +20,7 @@ * Added official drug names to verbose output of `eucast_rules()` ### Other -* Removed dependency on **all** packages that were needed for the `AMR` package to work properly: `backports`, `crayon`, `data.table`, `dplyr`, `ggplot2`, `R6`, `rlang` and `tidyr`. This is a major code change, but will probably not be noticeable by users. Making this package independent on especially the tidyverse (packages `dplyr`, `ggplot2` and `tidyr`) tremendously increases sustainability on the long term, since tidyverse functions change quite often. Most of our functions are replaced with versions that only rely on base R, which keeps this package fully functional for many years to come, without requiring a lot of maintenance to keep up with other packages anymore. The only dependencies that remained are for extending methods of other packages, like `pillar` and `vctrs` for printing and working with tibbles using our classes `mo` and `ab`. +* Removed previously deprecated function `p.symbol()` - it was replaced with `p_symbol()` * Removed function `read.4d()`, that was only useful for reading from an old test database. # AMR 1.1.0 diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 56a24bac..defc8943 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -427,6 +427,8 @@ percentage <- function(x, digits = NULL, ...) { } # prevent dependency on package 'backports' +# these functions were not available in previous versions of R (last checked: R 4.0.0) +# see here for the full list: https://github.com/r-lib/backports strrep = function(x, times) { x = as.character(x) if (length(x) == 0L) @@ -451,3 +453,6 @@ trimws <- function (x, which = c("both", "left", "right")) { isFALSE <- function (x) { is.logical(x) && length(x) == 1L && !is.na(x) && !x } +deparse1 = function (expr, collapse = " ", width.cutoff = 500L, ...) { + paste(deparse(expr, width.cutoff, ...), collapse = collapse) +} diff --git a/R/ab.R b/R/ab.R index 55262b3c..6bd39dff 100755 --- a/R/ab.R +++ b/R/ab.R @@ -75,7 +75,7 @@ as.ab <- function(x, ...) { if (all(toupper(x) %in% antibiotics$ab)) { # valid AB code, but not yet right class return(structure(.Data = toupper(x), - class = "ab")) + class = c("ab", "character"))) } x_bak <- x @@ -332,7 +332,7 @@ as.ab <- function(x, ...) { } structure(.Data = x_result, - class = "ab") + class = c("ab", "character")) } #' @rdname as.ab @@ -352,17 +352,14 @@ print.ab <- function(x, ...) { #' @exportMethod as.data.frame.ab #' @export #' @noRd -as.data.frame.ab <- function(x, ...) { - # same as as.data.frame.character but with removed stringsAsFactors - nm <- paste(deparse(substitute(x), width.cutoff = 500L), - collapse = " ") +as.data.frame.ab <- function (x, ...) { + nm <- deparse1(substitute(x)) if (!"nm" %in% names(list(...))) { - as.data.frame.vector(x, ..., nm = nm) + as.data.frame.vector(as.ab(x), ..., nm = nm) } else { - as.data.frame.vector(x, ...) + as.data.frame.vector(as.ab(x), ...) } } - #' @exportMethod [.ab #' @export #' @noRd @@ -403,11 +400,3 @@ c.ab <- function(x, ...) { attributes(y) <- attributes(x) class_integrity_check(y, "antimicrobial code", antibiotics$ab) } - -#' @importFrom pillar pillar_shaft -#' @export -pillar_shaft.ab <- function(x, ...) { - out <- format(x) - out[is.na(x)] <- font_red("NA") - pillar::new_pillar_shaft_simple(out, align = "left", min_width = 4) -} diff --git a/R/disk.R b/R/disk.R index 9b7229cf..dbb9576f 100644 --- a/R/disk.R +++ b/R/disk.R @@ -53,9 +53,7 @@ #' as.rsi(df) #' } as.disk <- function(x, na.rm = FALSE) { - if (is.disk(x)) { - x - } else { + if (!is.disk(x)) { x <- x %>% unlist() if (na.rm == TRUE) { x <- x[!is.na(x)] @@ -81,10 +79,9 @@ as.disk <- function(x, na.rm = FALSE) { "%) that were invalid disk zones: ", list_missing, call. = FALSE) } - - class(x) <- "disk" - x } + structure(as.integer(x), + class = c("disk", "integer")) } all_valid_disks <- function(x) { @@ -98,20 +95,6 @@ is.disk <- function(x) { inherits(x, "disk") } -#' @exportMethod as.data.frame.disk -#' @export -#' @noRd -as.data.frame.disk <- function(x, ...) { - # same as as.data.frame.integer but with removed stringsAsFactors, since it will be class "disk" - nm <- paste(deparse(substitute(x), width.cutoff = 500L), - collapse = " ") - if (!"nm" %in% names(list(...))) { - as.data.frame.vector(x, ..., nm = nm) - } else { - as.data.frame.vector(x, ...) - } -} - #' @exportMethod print.disk #' @export #' @noRd @@ -120,14 +103,6 @@ print.disk <- function(x, ...) { print(as.integer(x), quote = FALSE) } -#' @importFrom pillar pillar_shaft -#' @export -pillar_shaft.disk <- function(x, ...) { - out <- trimws(format(x)) - out[is.na(x)] <- font_red(NA) - pillar::new_pillar_shaft_simple(out, align = "right", min_width = 3) -} - #' @exportMethod [.disk #' @export #' @noRd diff --git a/R/freq.R b/R/freq.R index c990da0b..13e9216c 100755 --- a/R/freq.R +++ b/R/freq.R @@ -19,12 +19,15 @@ # Visit our website for more info: https://msberends.gitlab.io/AMR. # # ==================================================================== # -#' @importFrom cleaner freq -#' @export -cleaner::freq +if ("cleaner" %in% rownames(utils::installed.packages())) { + freq <- get("freq", envir = asNamespace("cleaner")) + freq.default <- get("freq.default", envir = asNamespace("cleaner")) +} else { + freq <- "" + freq.default <- "" +} -#' @exportMethod freq.mo -#' @importFrom cleaner freq.default +#' @method freq mo #' @export #' @noRd freq.mo <- function(x, ...) { @@ -47,11 +50,10 @@ freq.mo <- function(x, ...) { ")"), `No of genera` = n_distinct(mo_genus(x_noNA, language = NULL)), `No of species` = n_distinct(paste(mo_genus(x_noNA, language = NULL), - mo_species(x_noNA, language = NULL))))) + mo_species(x_noNA, language = NULL))))) } -#' @exportMethod freq.rsi -#' @importFrom cleaner freq.default +#' @method freq rsi #' @export #' @noRd freq.rsi <- function(x, ...) { diff --git a/R/mic.R b/R/mic.R index 79aace17..37a3f958 100755 --- a/R/mic.R +++ b/R/mic.R @@ -232,14 +232,6 @@ barplot.mic <- function(height, axis(2, seq(0, max(table(droplevels.factor(height))))) } -#' @importFrom pillar pillar_shaft -#' @export -pillar_shaft.mic <- function(x, ...) { - out <- trimws(format(x)) - out[is.na(x)] <- font_red(NA) - pillar::new_pillar_shaft_simple(out, align = "right", min_width = 4) -} - #' @exportMethod [.mic #' @export #' @noRd diff --git a/R/mo.R b/R/mo.R index e1dcb583..f51b0885 100755 --- a/R/mo.R +++ b/R/mo.R @@ -230,7 +230,8 @@ as.mo <- function(x, } to_class_mo <- function(x) { - structure(.Data = x, class = "mo") + structure(.Data = x, + class = c("mo", "character")) } #' @rdname as.mo @@ -1558,27 +1559,6 @@ print.mo <- function(x, ...) { print.default(x, quote = FALSE) } -#' @importFrom pillar pillar_shaft -#' @export -pillar_shaft.mo <- function(x, ...) { - out <- format(x) - # grey out the kingdom (part until first "_") - out[!is.na(x)] <- gsub("^([A-Z]+_)(.*)", paste0(font_subtle("\\1"), "\\2"), out[!is.na(x)]) - # and grey out every _ - out[!is.na(x)] <- gsub("_", font_subtle("_"), out[!is.na(x)]) - - # markup NA and UNKNOWN - out[is.na(x)] <- font_red(" NA") - out[x == "UNKNOWN"] <- font_red(" UNKNOWN") - - # make it always fit exactly - pillar::new_pillar_shaft_simple(out, - align = "left", - width = max(nchar(x)) + ifelse(length(x[x %in% c(NA, "UNKNOWN")]) > 0, - 2, - 0)) -} - #' @exportMethod summary.mo #' @export #' @noRd @@ -1598,14 +1578,12 @@ summary.mo <- function(object, ...) { #' @exportMethod as.data.frame.mo #' @export #' @noRd -as.data.frame.mo <- function(x, ...) { - # same as as.data.frame.character but with removed stringsAsFactors, since it will be class "mo" - nm <- paste(deparse(substitute(x), width.cutoff = 500L), - collapse = " ") +as.data.frame.mo <- function (x, ...) { + nm <- deparse1(substitute(x)) if (!"nm" %in% names(list(...))) { - as.data.frame.vector(x, ..., nm = nm) + as.data.frame.vector(as.mo(x), ..., nm = nm) } else { - as.data.frame.vector(x, ...) + as.data.frame.vector(as.mo(x), ...) } } diff --git a/R/rsi.R b/R/rsi.R index ac4a18b2..44b69cfe 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -650,17 +650,6 @@ barplot.rsi <- function(height, } } -#' @importFrom pillar pillar_shaft -#' @export -pillar_shaft.rsi <- function(x, ...) { - out <- trimws(format(x)) - out[is.na(x)] <- font_subtle(" NA") - out[x == "S"] <- font_green_bg(font_white(" S ")) - out[x == "I"] <- font_yellow_bg(font_black(" I ")) - out[x == "R"] <- font_red_bg(font_white(" R ")) - pillar::new_pillar_shaft_simple(out, align = "left", width = 3) -} - #' @exportMethod [<-.rsi #' @export #' @noRd diff --git a/R/rsi_calc.R b/R/rsi_calc.R index 1c527d6c..23ba562b 100755 --- a/R/rsi_calc.R +++ b/R/rsi_calc.R @@ -45,7 +45,7 @@ rsi_calc <- function(..., stop("`only_all_tested` must be logical", call. = FALSE) } - dots_df <- switch(1, ...) # it needs this evaluation + dots_df <- switch(1, ...) dots <- base::eval(base::substitute(base::alist(...))) if ("also_single_tested" %in% names(dots)) { stop("`also_single_tested` was replaced by `only_all_tested`. Please read Details in the help page (`?proportion`) as this may have a considerable impact on your analysis.", call. = FALSE) @@ -53,21 +53,21 @@ rsi_calc <- function(..., ndots <- length(dots) if ("data.frame" %in% class(dots_df)) { - # data.frame passed with other columns, like: example_isolates %>% proportion_S(amcl, gent) + # data.frame passed with other columns, like: example_isolates %>% proportion_S(AMC, GEN) dots <- as.character(dots) dots <- dots[dots != "."] if (length(dots) == 0 | all(dots == "df")) { - # for complete data.frames, like example_isolates %>% select(amcl, gent) %>% proportion_S() + # for complete data.frames, like example_isolates %>% select(AMC, GEN) %>% proportion_S() # and the old rsi function, which has "df" as name of the first parameter x <- dots_df } else { x <- dots_df[, dots[dots %in% colnames(dots_df)]] } } else if (ndots == 1) { - # only 1 variable passed (can also be data.frame), like: proportion_S(example_isolates$amcl) and example_isolates$amcl %>% proportion_S() + # only 1 variable passed (can also be data.frame), like: proportion_S(example_isolates$AMC) and example_isolates$AMC %>% proportion_S() x <- dots_df } else { - # multiple variables passed without pipe, like: proportion_S(example_isolates$amcl, example_isolates$gent) + # multiple variables passed without pipe, like: proportion_S(example_isolates$AMC, example_isolates$GEN) x <- NULL try(x <- as.data.frame(dots), silent = TRUE) if (is.null(x)) { diff --git a/R/sysdata.rda b/R/sysdata.rda index 644ed268..be08c5f4 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/R/tidyverse.R b/R/tidyverse.R deleted file mode 100644 index ba6e65eb..00000000 --- a/R/tidyverse.R +++ /dev/null @@ -1,257 +0,0 @@ -# ==================================================================== # -# TITLE # -# Antimicrobial Resistance (AMR) Analysis # -# # -# SOURCE # -# https://gitlab.com/msberends/AMR # -# # -# LICENCE # -# (c) 2018-2020 Berends MS, Luz CF et al. # -# # -# This R package is free software; you can freely use and distribute # -# it for both personal and commercial purposes under the terms of the # -# GNU General Public License version 2.0 (GNU GPL-2), as published by # -# the Free Software Foundation. # -# # -# We created this package for both routine data analysis and academic # -# research and it was publicly released in the hope that it will be # -# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. # -# Visit our website for more info: https://msberends.gitlab.io/AMR. # -# ==================================================================== # - -#' Methods for tidyverse -#' -#' These methods are needed to support methods used by the tidyverse, like joining and transforming data, with new classes that come with this package. -#' @inheritSection lifecycle Stable lifecycle -#' @inheritSection AMR Read more on our website! -#' @keywords internal -#' @name AMR-tidyverse -NULL - -#' @rdname AMR-tidyverse -#' @exportMethod scale_type.mo -#' @export -scale_type.mo <- function(x) { - # fix for: - # "Don't know how to automatically pick scale for object of type mo. Defaulting to continuous." - # "Error: Discrete value supplied to continuous scale" - "discrete" -} - -#' @rdname AMR-tidyverse -#' @exportMethod scale_type.ab -#' @export -scale_type.ab <- function(x) { - # fix for: - # "Don't know how to automatically pick scale for object of type mo. Defaulting to continuous." - # "Error: Discrete value supplied to continuous scale" - "discrete" -} - - -# Class mo ---------------------------------------------------------------- - - -#' @exportMethod vec_ptype_abbr.mo -#' @importFrom vctrs vec_ptype_abbr -#' @export -vec_ptype_abbr.mo <- function(x, ...) { - "mo" -} - -#' @exportMethod vec_ptype_full.mo -#' @importFrom vctrs vec_ptype_full -#' @export -vec_ptype_full.mo <- function(x, ...) { - "mo" -} - -#' @rdname AMR-tidyverse -#' @export -vec_ptype2.mo <- function(x, y, ...) { - UseMethod("vec_ptype2.mo", y) -} - -#' @method vec_ptype2.mo default -#' @export -vec_ptype2.mo.default <- function(x, y, ..., x_arg = "x", y_arg = "y") { - vctrs::vec_default_ptype2(x, y, x_arg = x_arg, y_arg = y_arg) -} - -#' @method vec_ptype2.mo character -#' @export -vec_ptype2.mo.character <- function(x, y, ...) { - x -} - -#' @method vec_ptype2.character mo -#' @exportMethod vec_ptype2.character.mo -#' @importFrom vctrs vec_ptype2.character -#' @export -vec_ptype2.character.mo <- function(x, y, ...) { - y -} - -#' @rdname AMR-tidyverse -#' @export -vec_cast.mo <- function(x, to, ...) { - UseMethod("vec_cast.mo") -} - -#' @method vec_cast.mo mo -#' @export -vec_cast.mo.mo <- function(x, to, ...) { - as.mo(x) -} - -#' @method vec_cast.mo character -#' @export -vec_cast.mo.character <- function(x, to, ...) { - as.mo(x) -} - -#' @method vec_cast.mo default -#' @importFrom vctrs vec_default_cast -#' @export -vec_cast.mo.default <- function(x, to, ...) { - vec_default_cast(x, to) -} - -#' @method vec_cast.character mo -#' @exportMethod vec_cast.character.mo -#' @importFrom vctrs vec_cast vec_cast.character -#' @export -vec_cast.character.mo <- function(x, to, ...) { - unclass(x) -} - - -# Class ab ---------------------------------------------------------------- - - -#' @exportMethod vec_ptype_abbr.ab -#' @importFrom vctrs vec_ptype_abbr -#' @export -vec_ptype_abbr.ab <- function(x, ...) { - "ab" -} - -#' @exportMethod vec_ptype_full.ab -#' @importFrom vctrs vec_ptype_full -#' @export -vec_ptype_full.ab <- function(x, ...) { - "ab" -} - -#' @rdname AMR-tidyverse -#' @export -vec_ptype2.ab <- function(x, y, ...) { - UseMethod("vec_ptype2.ab", y) -} - -#' @method vec_ptype2.ab default -#' @export -vec_ptype2.ab.default <- function(x, y, ..., x_arg = "x", y_arg = "y") { - vctrs::vec_default_ptype2(x, y, x_arg = x_arg, y_arg = y_arg) -} - -#' @method vec_ptype2.ab character -#' @export -vec_ptype2.ab.character <- function(x, y, ...) { - x -} - -#' @method vec_ptype2.character ab -#' @exportMethod vec_ptype2.character.ab -#' @importFrom vctrs vec_ptype2.character -#' @export -vec_ptype2.character.ab <- function(x, y, ...) { - y -} - -#' @rdname AMR-tidyverse -#' @export -vec_cast.ab <- function(x, to, ...) { - UseMethod("vec_cast.ab") -} - -#' @method vec_cast.ab ab -#' @export -vec_cast.ab.ab <- function(x, to, ...) { - as.ab(x) -} - -#' @method vec_cast.ab character -#' @export -vec_cast.ab.character <- function(x, to, ...) { - as.ab(x) -} - -#' @method vec_cast.ab default -#' @importFrom vctrs vec_default_cast -#' @export -vec_cast.ab.default <- function(x, to, ...) { - vec_default_cast(x, to) -} - -#' @method vec_cast.character ab -#' @exportMethod vec_cast.character.ab -#' @importFrom vctrs vec_cast vec_cast.character -#' @export -vec_cast.character.ab <- function(x, to, ...) { - unclass(x) -} - - -# Class disk -------------------------------------------------------------- - - -#' @exportMethod vec_ptype_abbr.disk -#' @importFrom vctrs vec_ptype_abbr -#' @export -vec_ptype_abbr.disk <- function(x, ...) { - "disk" -} - -#' @exportMethod vec_ptype_full.disk -#' @importFrom vctrs vec_ptype_full -#' @export -vec_ptype_full.disk <- function(x, ...) { - "disk" -} - - -# Class rsi -------------------------------------------------------------- - - -#' @exportMethod vec_ptype_abbr.rsi -#' @importFrom vctrs vec_ptype_abbr -#' @export -vec_ptype_abbr.rsi <- function(x, ...) { - "rsi" -} - -#' @exportMethod vec_ptype_full.rsi -#' @importFrom vctrs vec_ptype_full -#' @export -vec_ptype_full.rsi <- function(x, ...) { - "rsi" -} - - -# Class mic -------------------------------------------------------------- - - -#' @exportMethod vec_ptype_abbr.mic -#' @importFrom vctrs vec_ptype_abbr -#' @export -vec_ptype_abbr.mic <- function(x, ...) { - "mic" -} - -#' @exportMethod vec_ptype_full.mic -#' @importFrom vctrs vec_ptype_full -#' @export -vec_ptype_full.mic <- function(x, ...) { - "mic" -} diff --git a/_pkgdown.yml b/_pkgdown.yml index 7ae14e2d..614f9ab0 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -162,8 +162,6 @@ reference: contents: - "`get_locale`" - "`like`" - - "`reexports`" - - "`AMR-tidyverse`" - title: Deprecated functions desc: > These functions are deprecated, meaning that they will still diff --git a/data-raw/country_analysis.R b/data-raw/country_analysis.R index 4d37c19e..34cff779 100644 --- a/data-raw/country_analysis.R +++ b/data-raw/country_analysis.R @@ -56,6 +56,7 @@ for (i in 2:length(unique_ip)) { ip_tbl <- ip_tbl %>% bind_rows(GET_df(unique_ip[i])) } +close(p) ip_tbl.bak <- ip_tbl diff --git a/data-raw/microorganisms.translation.rds b/data-raw/microorganisms.translation.rds index c4509704..dcbf445b 100644 Binary files a/data-raw/microorganisms.translation.rds and b/data-raw/microorganisms.translation.rds differ diff --git a/data/antibiotics.rda b/data/antibiotics.rda index 428f40be..38dc5432 100755 Binary files a/data/antibiotics.rda and b/data/antibiotics.rda differ diff --git a/data/example_isolates.rda b/data/example_isolates.rda index 04b026c0..6840f09f 100644 Binary files a/data/example_isolates.rda and b/data/example_isolates.rda differ diff --git a/data/microorganisms.codes.rda b/data/microorganisms.codes.rda index 200d1d5a..fa2d48cf 100644 Binary files a/data/microorganisms.codes.rda and b/data/microorganisms.codes.rda differ diff --git a/data/microorganisms.rda b/data/microorganisms.rda index f1cd35a4..1d8b4f48 100644 Binary files a/data/microorganisms.rda and b/data/microorganisms.rda differ diff --git a/data/rsi_translation.rda b/data/rsi_translation.rda index e4a87194..2bd3fe0c 100644 Binary files a/data/rsi_translation.rda and b/data/rsi_translation.rda differ diff --git a/docs/404.html b/docs/404.html index ceb363be..190e92ae 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9011 + 1.1.0.9012 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index e3f2fee6..16712307 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9011 + 1.1.0.9012 diff --git a/docs/articles/index.html b/docs/articles/index.html index 31cbb7a4..4f845205 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9011 + 1.1.0.9012 diff --git a/docs/authors.html b/docs/authors.html index 5655c677..ec94f7a4 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9011 + 1.1.0.9012 diff --git a/docs/countries.png b/docs/countries.png index e3ac90a6..3429e4ca 100644 Binary files a/docs/countries.png and b/docs/countries.png differ diff --git a/docs/countries_large.png b/docs/countries_large.png index 80ea0809..db9aff9e 100644 Binary files a/docs/countries_large.png and b/docs/countries_large.png differ diff --git a/docs/index.html b/docs/index.html index 34fcaa92..27330846 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.1.0.9011 + 1.1.0.9012 @@ -200,7 +200,7 @@ A methods paper about this package has been preprinted at bioRxiv (DOI: 10.1101/

(TLDR - to find out how to conduct AMR analysis, please continue reading here to get started.

AMR is a free, open-source and independent R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. Our aim is to provide a standard for clean and reproducible antimicrobial resistance data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting.

After installing this package, R knows ~70,000 distinct microbial species and all ~550 antibiotic, antimycotic and antiviral drugs by name and code (including ATC, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. It supports any data format, including WHONET/EARS-Net data.

-

We created this package for both routine data analysis and academic research (as part of our PhD theses) at the Faculty of Medical Sciences of the University of Groningen, the Netherlands, and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and is free software (see Copyright).

+

We created this package for both routine data analysis and academic research (as part of our PhD theses) at the Faculty of Medical Sciences of the University of Groningen, the Netherlands, and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and is free software (see Copyright). It is fully independent on any other R package and only requires R version 3.0.0 (April 2013) or higher to run.

Used in more than 100 countries
Since its first public release in early 2018, this package has been downloaded from more than 100 countries (source: CRAN logs). Click the map to enlarge, to see the names of the countries. diff --git a/docs/news/index.html b/docs/news/index.html index f17b6465..295f3ce7 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9011 + 1.1.0.9012

@@ -229,19 +229,28 @@ Source: NEWS.md -
-

-AMR 1.1.0.9011 Unreleased +
+

+AMR 1.1.0.9012 Unreleased

-
+

-Last updated: 18-May-2020 +Last updated: 19-May-2020

Breaking

    -
  • Removed previously deprecated function p.symbol() - it was replaced with p_symbol() +
  • +

    Removed code dependency on all R packages that this AMR package relied upon: cleaner, crayon, data.table, dplyr, ggplot2, knitr, microbenchmark, pillar, R6, rlang, tidyr and vctrs. This is a major code change, but will probably not be noticeable by most users.

    +

    Making this package independent on especially the tidyverse tremendously increases sustainability on the long term, since tidyverse functions change quite often. Most of our functions are replaced with versions that only rely on base R, which keeps this package fully functional for many years to come, without requiring a lot of maintenance to keep up with other packages anymore. Another upside it that this package can now be used with all versions of R since R-3.0.0 (April 2013). Our package is being used in settings where the resources are very limited. Fewer dependencies on newer software is helpful for such settings.

    +Negative effects of this change are: +
      +
    • Function freq() that was borrowed from the cleaner package was removed. Use cleaner::freq(), or run library("cleaner") before you use freq().
    • +
    • Printing values of class mo or ab in a tibble will no longer be in colour.
    • +
    • All functions from the mo_* family (like mo_name() and mo_gramstain()) are noticeably slower when running on tens of thousands of rows.
    • +
    • For developers: classes mo and ab now both also inherit class character, to support any data transformation. This change invalidates code that checks for class length == 1.
    • +
@@ -260,7 +269,8 @@

Other

    -
  • Removed dependency on all packages that were needed for the AMR package to work properly: backports, crayon, data.table, dplyr, ggplot2, R6, rlang and tidyr. This is a major code change, but will probably not be noticeable by users. Making this package independent on especially the tidyverse (packages dplyr, ggplot2 and tidyr) tremendously increases sustainability on the long term, since tidyverse functions change quite often. Most of our functions are replaced with versions that only rely on base R, which keeps this package fully functional for many years to come, without requiring a lot of maintenance to keep up with other packages anymore. The only dependencies that remained are for extending methods of other packages, like pillar and vctrs for printing and working with tibbles using our classes mo and ab.
  • +
  • Removed previously deprecated function p.symbol() - it was replaced with p_symbol() +
  • Removed function read.4d(), that was only useful for reading from an old test database.
@@ -531,7 +541,7 @@ For WHONET users, this means that all records/isolates with organism code #> Warning message: #> invalid microorganism 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 (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).
  • +
  • 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).
  • Renamed data set septic_patients to example_isolates

  • @@ -788,7 +798,7 @@ Please age() function gained a new parameter exact to determine ages with decimals
  • Removed deprecated functions guess_mo(), guess_atc(), EUCAST_rules(), interpretive_reading(), rsi()
  • -
  • Frequency tables (freq()): +
  • Frequency tables (freq()):
    • speed improvement for microbial IDs
    • fixed factor level names for R Markdown
    • @@ -796,12 +806,12 @@ Please
      septic_patients %>%
      -  freq(age) %>%
      +  freq(age) %>%
         boxplot()
       # grouped boxplots:
       septic_patients %>%
         group_by(hospital_id) %>%
      -  freq(age) %>%
      +  freq(age) %>%
         boxplot()
  • @@ -812,7 +822,7 @@ Please age_groups(), to let groups of fives and tens end with 100+ instead of 120+ -
  • Fix for freq() for when all values are NA +
  • Fix for freq() for when all values are NA
  • Fix for first_isolate() for when dates are missing
  • Improved speed of guess_ab_col() @@ -1034,7 +1044,7 @@ Using as.mo(..., allow_uncertain = 3)
  • -
  • Frequency tables (freq() function): +
  • Frequency tables (freq() function):
    • Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:

      @@ -1042,15 +1052,15 @@ Using as.mo(..., allow_uncertain = 3)# OLD WAY septic_patients %>% mutate(genus = mo_genus(mo)) %>% - freq(genus) + freq(genus) # NEW WAY septic_patients %>% - freq(mo_genus(mo)) + freq(mo_genus(mo)) # Even supports grouping variables: septic_patients %>% group_by(gender) %>% - freq(mo_genus(mo)) + freq(mo_genus(mo))
    • 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
    • @@ -1137,18 +1147,18 @@ Using as.mo(..., allow_uncertain = 3)Using portion_* functions now throws a warning when total available isolate is below parameter minimum
    • Functions as.mo, as.rsi, as.mic, as.atc and freq will not set package name as attribute anymore
    • -
    • Frequency tables - freq(): +
    • Frequency tables - freq():
      • Support for grouping variables, test with:

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

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

        Support for types (classes) list and matrix for freq

        my_matrix = with(septic_patients, matrix(c(age, gender), ncol = 2))
        -freq(my_matrix)
        +freq(my_matrix)

        For lists, subsetting is possible:

        my_list = list(age = septic_patients$age, gender = septic_patients$gender)
        -my_list %>% freq(age)
        -my_list %>% freq(gender)
        +my_list %>% freq(age) +my_list %>% freq(gender)
      @@ -1405,13 +1415,13 @@ Using as.mo(..., allow_uncertain = 3)
    • A vignette to explain its usage
    • Support for rsi (antimicrobial resistance) to use as input
    • -
    • Support for table to use as input: freq(table(x, y)) +
    • Support for table to use as input: freq(table(x, y))
    • Support for existing functions hist and plot to use a frequency table as input: hist(freq(df$age))
    • Support for as.vector, as.data.frame, as_tibble and format
    • -
    • Support for quasiquotation: freq(mydata, mycolumn) is the same as mydata %>% freq(mycolumn) +
    • Support for quasiquotation: freq(mydata, mycolumn) is the same as mydata %>% freq(mycolumn)
    • Function top_freq function to return the top/below n items as vector
    • Header of frequency tables now also show Mean Absolute Deviaton (MAD) and Interquartile Range (IQR)
    • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 56724c48..b6bbe22b 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -10,7 +10,7 @@ articles: WHONET: WHONET.html benchmarks: benchmarks.html resistance_predict: resistance_predict.html -last_built: 2020-05-18T11:59Z +last_built: 2020-05-19T10:08Z urls: reference: https://msberends.gitlab.io/AMR/reference article: https://msberends.gitlab.io/AMR/articles diff --git a/docs/reference/index.html b/docs/reference/index.html index 8ad965d1..f15ed052 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9011 + 1.1.0.9012 @@ -583,18 +583,6 @@

      like() `%like%` `%like_case%`

      Pattern Matching

      - - - -

      reexports

      - -

      Objects exported from other packages

      - - - -

      scale_type.mo() scale_type.ab() vec_ptype2.mo() vec_cast.mo() vec_ptype2.ab() vec_cast.ab()

      - -

      Methods for tidyverse

      diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 44113abb..38a73684 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -6,9 +6,6 @@ https://msberends.gitlab.io/AMR/reference/AMR-deprecated.html - - https://msberends.gitlab.io/AMR/reference/AMR-tidyverse.html - https://msberends.gitlab.io/AMR/reference/AMR.html @@ -132,9 +129,6 @@ https://msberends.gitlab.io/AMR/reference/proportion.html - - https://msberends.gitlab.io/AMR/reference/reexports.html - https://msberends.gitlab.io/AMR/reference/resistance_predict.html diff --git a/index.md b/index.md index b55c3c84..7f4ecf8e 100644 --- a/index.md +++ b/index.md @@ -12,7 +12,7 @@ After installing this package, R knows [**~70,000 distinct microbial species**](./reference/microorganisms.html) and all [**~550 antibiotic, antimycotic and antiviral drugs**](./reference/antibiotics.html) by name and code (including ATC, LOINC and SNOMED CT), and knows all about valid R/SI and MIC values. It supports any data format, including WHONET/EARS-Net data. -We created this package for both routine data analysis and academic research (as part of our PhD theses) at the Faculty of Medical Sciences of the University of Groningen, the Netherlands, and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is [actively maintained](./news) and is free software (see [Copyright](#copyright)). +We created this package for both routine data analysis and academic research (as part of our PhD theses) at the Faculty of Medical Sciences of the University of Groningen, the Netherlands, and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is [actively maintained](./news) and is free software (see [Copyright](#copyright)). It is fully independent on any other R package and only requires R version 3.0.0 (April 2013) or higher to run.

      diff --git a/man/AMR-tidyverse.Rd b/man/AMR-tidyverse.Rd deleted file mode 100644 index 4ec9886b..00000000 --- a/man/AMR-tidyverse.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/tidyverse.R -\name{AMR-tidyverse} -\alias{AMR-tidyverse} -\alias{scale_type.mo} -\alias{scale_type.ab} -\alias{vec_ptype2.mo} -\alias{vec_cast.mo} -\alias{vec_ptype2.ab} -\alias{vec_cast.ab} -\title{Methods for tidyverse} -\usage{ -scale_type.mo(x) - -scale_type.ab(x) - -vec_ptype2.mo(x, y, ...) - -vec_cast.mo(x, to, ...) - -vec_ptype2.ab(x, y, ...) - -vec_cast.ab(x, to, ...) -} -\description{ -These methods are needed to support methods used by the tidyverse, like joining and transforming data, with new classes that come with this package. -} -\section{Stable lifecycle}{ - -\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} -The \link[AMR:lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, we are largely happy with the unlying code, and major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; we will avoid removing arguments or changing the meaning of existing arguments. - -If the unlying code needs breaking changes, they will occur gradually. To begin with, the function or argument will be deprecated; it will continue to work but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. -} - -\section{Read more on our website!}{ - -On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. -} - -\keyword{internal} diff --git a/man/reexports.Rd b/man/reexports.Rd deleted file mode 100644 index 4f14eecb..00000000 --- a/man/reexports.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/freq.R -\docType{import} -\name{reexports} -\alias{reexports} -\alias{freq} -\title{Objects exported from other packages} -\keyword{internal} -\description{ -These objects are imported from other packages. Follow the links -below to see their documentation. - -\describe{ - \item{cleaner}{\code{\link[cleaner]{freq}}} -}} - diff --git a/pkgdown/logos/countries.png b/pkgdown/logos/countries.png index e3ac90a6..3429e4ca 100644 Binary files a/pkgdown/logos/countries.png and b/pkgdown/logos/countries.png differ diff --git a/pkgdown/logos/countries_large.png b/pkgdown/logos/countries_large.png index 80ea0809..db9aff9e 100644 Binary files a/pkgdown/logos/countries_large.png and b/pkgdown/logos/countries_large.png differ diff --git a/tests/testthat/test-ab.R b/tests/testthat/test-ab.R index 2f22d1ae..14b9bb09 100755 --- a/tests/testthat/test-ab.R +++ b/tests/testthat/test-ab.R @@ -34,8 +34,8 @@ test_that("as.ab works", { "Romycin"))), rep("ERY", 10)) - expect_identical(class(as.ab("amox")), "ab") - expect_identical(class(pull(antibiotics, ab)), "ab") + expect_identical(class(as.ab("amox")), c("ab", "character")) + expect_identical(class(pull(antibiotics, ab)), c("ab", "character")) expect_true(is.ab(as.ab("amox"))) expect_output(print(as.ab("amox"))) expect_output(print(data.frame(a = as.ab("amox")))) @@ -46,8 +46,6 @@ test_that("as.ab works", { expect_output(print(as.ab("amox"))) - expect_identical(class(pull(antibiotics, ab)), "ab") - expect_equal(as.character(as.ab("Phloxapen")), "FLC") diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index b2b79772..3f85f7c1 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -27,9 +27,9 @@ test_that("data sets are valid", { # IDs should always be unique expect_identical(nrow(microorganisms), length(unique(microorganisms$mo))) - expect_identical(class(microorganisms$mo), "mo") + expect_identical(class(microorganisms$mo), c("mo", "character")) expect_identical(nrow(antibiotics), length(unique(antibiotics$ab))) - expect_identical(class(antibiotics$ab), "ab") + expect_identical(class(antibiotics$ab), c("ab", "character")) # check cross table reference expect_true(all(microorganisms.codes$mo %in% microorganisms$mo)) diff --git a/tests/testthat/test-extended.R b/tests/testthat/test-extended.R deleted file mode 100644 index 9405d573..00000000 --- a/tests/testthat/test-extended.R +++ /dev/null @@ -1,29 +0,0 @@ -# ==================================================================== # -# TITLE # -# Antimicrobial Resistance (AMR) Analysis # -# # -# SOURCE # -# https://gitlab.com/msberends/AMR # -# # -# LICENCE # -# (c) 2018-2020 Berends MS, Luz CF et al. # -# # -# This R package is free software; you can freely use and distribute # -# it for both personal and commercial purposes under the terms of the # -# GNU General Public License version 2.0 (GNU GPL-2), as published by # -# the Free Software Foundation. # -# # -# We created this package for both routine data analysis and academic # -# research and it was publicly released in the hope that it will be # -# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. # -# Visit our website for more info: https://msberends.gitlab.io/AMR. # -# ==================================================================== # - -context("extended.R") - -test_that("extensions work", { - - expect_identical(scale_type.mo(), "discrete") - expect_identical(scale_type.ab(), "discrete") - -})