From cb1814f5ff97f4b43fdd706d7ba6467f3a0122e7 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Tue, 19 May 2020 13:18:01 +0200 Subject: [PATCH] (v1.1.0.9013) lose dependencies --- DESCRIPTION | 2 +- NAMESPACE | 2 -- NEWS.md | 5 ++- R/aa_helper_functions.R | 14 ++++---- R/ab.R | 2 +- R/freq.R | 72 -------------------------------------- R/mo.R | 2 +- docs/404.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 10 +++--- docs/pkgdown.yml | 2 +- docs/reference/index.html | 2 +- tests/testthat/test-freq.R | 36 ------------------- 16 files changed, 24 insertions(+), 135 deletions(-) delete mode 100755 R/freq.R delete mode 100755 tests/testthat/test-freq.R diff --git a/DESCRIPTION b/DESCRIPTION index 51d8fb43c..84422237c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.1.0.9012 +Version: 1.1.0.9013 Date: 2020-05-19 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NAMESPACE b/NAMESPACE index 1ab06665e..0279915ef 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -37,8 +37,6 @@ S3method(c,rsi) S3method(droplevels,mic) S3method(droplevels,rsi) S3method(format,bug_drug_combinations) -S3method(freq,mo) -S3method(freq,rsi) S3method(kurtosis,data.frame) S3method(kurtosis,default) S3method(kurtosis,matrix) diff --git a/NEWS.md b/NEWS.md index 5fc07d9a7..bf92cc655 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,8 @@ -# AMR 1.1.0.9012 +# AMR 1.1.0.9013 ## Last updated: 19-May-2020 ### Breaking - -* 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. +* Removed code dependency on **all** R packages that this `AMR` package required: `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. diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index defc89432..70837e7f8 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -429,8 +429,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) +strrep <- function(x, times) { + x <- as.character(x) if (length(x) == 0L) return(x) unlist(.mapply(function(x, times) { @@ -441,18 +441,18 @@ strrep = function(x, times) { paste0(replicate(times, x), collapse = "") }, list(x = x, times = times), MoreArgs = list()), use.names = FALSE) } -trimws <- function (x, which = c("both", "left", "right")) { - which = match.arg(which) - mysub = function(re, x) sub(re, "", x, perl = TRUE) +trimws <- function(x, which = c("both", "left", "right")) { + which <- match.arg(which) + mysub <- function(re, x) sub(re, "", x, perl = TRUE) if (which == "left") return(mysub("^[ \t\r\n]+", x)) if (which == "right") return(mysub("[ \t\r\n]+$", x)) mysub("[ \t\r\n]+$", mysub("^[ \t\r\n]+", x)) } -isFALSE <- function (x) { +isFALSE <- function(x) { is.logical(x) && length(x) == 1L && !is.na(x) && !x } -deparse1 = function (expr, collapse = " ", width.cutoff = 500L, ...) { +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 6bd39dff6..adf56f698 100755 --- a/R/ab.R +++ b/R/ab.R @@ -352,7 +352,7 @@ print.ab <- function(x, ...) { #' @exportMethod as.data.frame.ab #' @export #' @noRd -as.data.frame.ab <- function (x, ...) { +as.data.frame.ab <- function(x, ...) { nm <- deparse1(substitute(x)) if (!"nm" %in% names(list(...))) { as.data.frame.vector(as.ab(x), ..., nm = nm) diff --git a/R/freq.R b/R/freq.R deleted file mode 100755 index 13e9216cd..000000000 --- a/R/freq.R +++ /dev/null @@ -1,72 +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. # -# ==================================================================== # - -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 <- "" -} - -#' @method freq mo -#' @export -#' @noRd -freq.mo <- function(x, ...) { - x_noNA <- as.mo(x[!is.na(x)]) # as.mo() to get the newest mo codes - grams <- mo_gramstain(x_noNA, language = NULL) - digits <- list(...)$digits - if (is.null(digits)) { - digits <- 2 - } - freq.default(x = x, ..., - .add_header = list(`Gram-negative` = paste0(format(sum(grams == "Gram-negative", na.rm = TRUE), - big.mark = ",", - decimal.mark = "."), - " (", percentage(sum(grams == "Gram-negative", na.rm = TRUE) / length(grams), digits = digits), - ")"), - `Gram-positive` = paste0(format(sum(grams == "Gram-positive", na.rm = TRUE), - big.mark = ",", - decimal.mark = "."), - " (", percentage(sum(grams == "Gram-positive", na.rm = TRUE) / length(grams), digits = digits), - ")"), - `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))))) -} - -#' @method freq rsi -#' @export -#' @noRd -freq.rsi <- function(x, ...) { - x_name <- deparse(substitute(x)) - x_name <- gsub(".*[$]", "", x_name) - ab <- suppressMessages(suppressWarnings(as.ab(x_name))) - if (!is.na(ab)) { - freq.default(x = x, ..., - .add_header = list(Drug = paste0(ab_name(ab), " (", ab, ", ", ab_atc(ab), ")"), - group = ab_group(ab), - `%SI` = susceptibility(x, minimum = 0, as_percent = TRUE))) - } else { - freq.default(x = x, ..., - .add_header = list(`%SI` = susceptibility(x, minimum = 0, as_percent = TRUE))) - } -} diff --git a/R/mo.R b/R/mo.R index f51b0885e..fa0e8c5f8 100755 --- a/R/mo.R +++ b/R/mo.R @@ -1578,7 +1578,7 @@ summary.mo <- function(object, ...) { #' @exportMethod as.data.frame.mo #' @export #' @noRd -as.data.frame.mo <- function (x, ...) { +as.data.frame.mo <- function(x, ...) { nm <- deparse1(substitute(x)) if (!"nm" %in% names(list(...))) { as.data.frame.vector(as.mo(x), ..., nm = nm) diff --git a/docs/404.html b/docs/404.html index 190e92ae6..0e7c7e3f2 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9012 + 1.1.0.9013 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 167123075..6b52a3971 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9012 + 1.1.0.9013 diff --git a/docs/articles/index.html b/docs/articles/index.html index 4f8452055..4c792747d 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9012 + 1.1.0.9013 diff --git a/docs/authors.html b/docs/authors.html index ec94f7a49..be9616028 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9012 + 1.1.0.9013 diff --git a/docs/index.html b/docs/index.html index 273308462..f30276f0a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.1.0.9012 + 1.1.0.9013 diff --git a/docs/news/index.html b/docs/news/index.html index 295f3ce72..47f07f99f 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9012 + 1.1.0.9013 @@ -229,9 +229,9 @@ Source: NEWS.md -
-

-AMR 1.1.0.9012 Unreleased +
+

+AMR 1.1.0.9013 Unreleased

@@ -242,7 +242,7 @@ Breaking

  • -

    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.

    +

    Removed code dependency on all R packages that this AMR package required: 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:
      diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index b6bbe22b7..6e635efa3 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-19T10:08Z +last_built: 2020-05-19T11:17Z 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 f15ed0529..f8aa1505e 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.1.0.9012 + 1.1.0.9013
diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R deleted file mode 100755 index c5329cc8d..000000000 --- a/tests/testthat/test-freq.R +++ /dev/null @@ -1,36 +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("freq.R") - -test_that("frequency table works", { - library(cleaner) - # mo - expect_true(is.freq(freq(example_isolates$mo))) - # for this to work, the output of mo_gramstain() is to be expected as follows: - expect_equal(mo_gramstain("B_ESCHR_COLI", language = NULL), "Gram-negative") - expect_equal(mo_gramstain("B_STPHY_AURS", language = NULL), "Gram-positive") - - # rsi - expect_true(is.freq(freq(example_isolates$AMX))) - library(dplyr) - expect_true(is.freq(example_isolates %>% freq(AMX))) -})