diff --git a/DESCRIPTION b/DESCRIPTION index 139b89e64..69f382ee8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 2.1.1.9128 +Version: 2.1.1.9129 Date: 2025-01-27 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) @@ -46,6 +46,7 @@ Suggests: rmarkdown, rvest, skimr, + testthat, tibble, tidymodels, tidyselect, diff --git a/NEWS.md b/NEWS.md index a9c4aa550..3e1cee524 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.1.1.9128 +# AMR 2.1.1.9129 *(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://msberends.github.io/AMR/#latest-development-version).)* diff --git a/PythonPackage/AMR/AMR.egg-info/PKG-INFO b/PythonPackage/AMR/AMR.egg-info/PKG-INFO index b80d3fc6e..30b6ef0b2 100644 --- a/PythonPackage/AMR/AMR.egg-info/PKG-INFO +++ b/PythonPackage/AMR/AMR.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.2 Name: AMR -Version: 2.1.1.9128 +Version: 2.1.1.9129 Summary: A Python wrapper for the AMR R package Home-page: https://github.com/msberends/AMR Author: Matthijs Berends diff --git a/PythonPackage/AMR/AMR/datasets.py b/PythonPackage/AMR/AMR/datasets.py index efc5d87d8..28774b333 100644 --- a/PythonPackage/AMR/AMR/datasets.py +++ b/PythonPackage/AMR/AMR/datasets.py @@ -1,7 +1,3 @@ -BLUE = '\033[94m' -GREEN = '\033[32m' -RESET = '\033[0m' - import os import sys from rpy2 import robjects @@ -17,18 +13,22 @@ venv_path = sys.prefix r_lib_path = os.path.join(venv_path, "R_libs") # Ensure the R library path exists os.makedirs(r_lib_path, exist_ok=True) -# Set the R library path in .libPaths -base = importr('base') -# Turn off warnings -base.options(warn = -1) -base._libPaths(r_lib_path) +# Import base and utils +base = importr('base') +utils = importr('utils') + +# Override R library paths globally for the session +robjects.r(f'.Library <- "{r_lib_path}"') # Replace default library +robjects.r(f'.Library.site <- "{r_lib_path}"') # Replace site-specific library +base._libPaths(r_lib_path) # Override .libPaths() as well + +# Get the effective library path r_amr_lib_path = base._libPaths()[0] # Check if the AMR package is installed in R -if not isinstalled('AMR', lib_loc = r_amr_lib_path): - utils = importr('utils') - print(f"{BLUE}AMR:{RESET} Installing AMR package to {BLUE}{r_amr_lib_path}/{RESET}...", flush=True) +if not isinstalled('AMR', lib_loc=r_amr_lib_path): + print(f"AMR: Installing latest AMR R package to {r_amr_lib_path}...", flush=True) utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True) # Python package version of AMR @@ -43,16 +43,12 @@ r_amr_version = robjects.r(f'as.character(packageVersion("AMR", lib.loc = "{r_li # Compare R and Python package versions if r_amr_version != python_amr_version: try: - print(f"{BLUE}AMR:{RESET} Updating AMR package in {BLUE}{r_amr_lib_path}/{RESET}...", flush=True) - utils = importr('utils') + print(f"AMR: Updating AMR package in {r_amr_lib_path}...", flush=True) utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True) except Exception as e: - print(f"{BLUE}AMR:{RESET} Could not update: {e}{RESET}", flush=True) + print(f"AMR: Could not update: {e}", flush=True) -# Restore warnings to default -base.options(warn = 0) - -print(f"{BLUE}AMR:{RESET} Setting up R environment and AMR datasets...", flush=True) +print(f"AMR: Setting up R environment and AMR datasets...", flush=True) # Activate the automatic conversion between R and pandas DataFrames pandas2ri.activate() @@ -77,4 +73,4 @@ microorganisms = pandas2ri.rpy2py(robjects.r('AMR::microorganisms[, !sapply(AMR: antibiotics = pandas2ri.rpy2py(robjects.r('AMR::antibiotics[, !sapply(AMR::antibiotics, is.list)]')) clinical_breakpoints = pandas2ri.rpy2py(robjects.r('AMR::clinical_breakpoints[, !sapply(AMR::clinical_breakpoints, is.list)]')) -print(f"{BLUE}AMR:{RESET} {GREEN}Done.{RESET}", flush=True) +print(f"AMR: Done.", flush=True) diff --git a/PythonPackage/AMR/dist/AMR-2.1.1.9128-py3-none-any.whl b/PythonPackage/AMR/dist/AMR-2.1.1.9128-py3-none-any.whl deleted file mode 100644 index 2a5f62f2f..000000000 Binary files a/PythonPackage/AMR/dist/AMR-2.1.1.9128-py3-none-any.whl and /dev/null differ diff --git a/PythonPackage/AMR/dist/AMR-2.1.1.9129-py3-none-any.whl b/PythonPackage/AMR/dist/AMR-2.1.1.9129-py3-none-any.whl new file mode 100644 index 000000000..de4518af6 Binary files /dev/null and b/PythonPackage/AMR/dist/AMR-2.1.1.9129-py3-none-any.whl differ diff --git a/PythonPackage/AMR/dist/amr-2.1.1.9128.tar.gz b/PythonPackage/AMR/dist/amr-2.1.1.9128.tar.gz deleted file mode 100644 index fe3bebc94..000000000 Binary files a/PythonPackage/AMR/dist/amr-2.1.1.9128.tar.gz and /dev/null differ diff --git a/PythonPackage/AMR/dist/amr-2.1.1.9129.tar.gz b/PythonPackage/AMR/dist/amr-2.1.1.9129.tar.gz new file mode 100644 index 000000000..58447fa5d Binary files /dev/null and b/PythonPackage/AMR/dist/amr-2.1.1.9129.tar.gz differ diff --git a/PythonPackage/AMR/setup.py b/PythonPackage/AMR/setup.py index b48a98844..51c775221 100644 --- a/PythonPackage/AMR/setup.py +++ b/PythonPackage/AMR/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='AMR', - version='2.1.1.9128', + version='2.1.1.9129', packages=find_packages(), install_requires=[ 'rpy2', diff --git a/R/aa_globals.R b/R/aa_globals.R index 16e6a3837..8e245be4e 100755 --- a/R/aa_globals.R +++ b/R/aa_globals.R @@ -165,6 +165,7 @@ globalVariables(c( "lang", "language", "lookup", + "lower", "method", "mic ", "mic", @@ -198,6 +199,7 @@ globalVariables(c( "total", "txt", "type", + "upper", "uti_index", "value", "varname", diff --git a/R/antibiogram.R b/R/antibiogram.R index 503273433..a57592524 100755 --- a/R/antibiogram.R +++ b/R/antibiogram.R @@ -60,7 +60,7 @@ #' #' For estimating antimicrobial coverage, especially when creating a WISCA, the outcome might become more reliable by only including the top *n* species encountered in the data. You can filter on this top *n* using [top_n_microorganisms()]. For example, use `top_n_microorganisms(your_data, n = 10)` as a pre-processing step to only include the top 10 species in the data. #' -#' The numeric values of an antibiogram are stored in a long format as the [attribute] `long_numeric`. You can retrieve them using `attributes(x)$long_numeric`, where `x` is the outcome of [antibiogram()] or [wisca()]. This is ideal for e.g. advanced plotting. +#' The numeric values of an antibiogram are stored in a long format as the [attribute][attributes()] `long_numeric`. You can retrieve them using `attributes(x)$long_numeric`, where `x` is the outcome of [antibiogram()] or [wisca()]. This is ideal for e.g. advanced plotting. #' #' ### Formatting Type #' diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R index dd4ee82c7..2d8b0c6fd 100755 --- a/R/bug_drug_combinations.R +++ b/R/bug_drug_combinations.R @@ -36,6 +36,7 @@ #' @param remove_intrinsic_resistant [logical] to indicate that rows and columns with 100% resistance for all tested antimicrobials must be removed from the table #' @param FUN the function to call on the `mo` column to transform the microorganism codes - the default is [mo_shortname()] #' @param translate_ab a [character] of length 1 containing column names of the [antibiotics] data set +#' @param include_n_rows a [logical] to indicate if the total number of rows must be included in the output #' @param ... arguments passed on to `FUN` #' @inheritParams sir_df #' @inheritParams base::formatC @@ -182,8 +183,8 @@ bug_drug_combinations <- function(x, out <- out[, colnames(out)[colnames(out) != "total_rows"], drop = FALSE] } - out <- out %pm>% pm_arrange(mo, ab) out <- as_original_data_class(out, class(x.bak)) # will remove tibble groups + out <- out %pm>% pm_arrange(mo, ab) rownames(out) <- NULL structure(out, class = c("bug_drug_combinations", if(data_has_groups) "grouped" else NULL, class(out))) } diff --git a/R/ggplot_pca.R b/R/ggplot_pca.R index 4d879bff4..72e86aa03 100755 --- a/R/ggplot_pca.R +++ b/R/ggplot_pca.R @@ -261,7 +261,7 @@ ggplot_pca <- function(x, type = "open" ), colour = arrows_colour, - size = arrows_size, + linewidth = arrows_size, alpha = arrows_alpha ) if (arrows_textangled == TRUE) { diff --git a/R/top_n_microorganisms.R b/R/top_n_microorganisms.R index 5c4193cca..8d6ae4ee9 100755 --- a/R/top_n_microorganisms.R +++ b/R/top_n_microorganisms.R @@ -36,7 +36,7 @@ #' @param n_for_each an optional integer specifying the maximum number of rows to retain for each value of the selected property. If `NULL`, all rows within the top *n* groups will be included. #' @param col_mo A character string indicating the column in `x` that contains microorganism names or codes. Defaults to the first column of class [`mo`]. Values will be coerced using [as.mo()]. #' @param ... Additional arguments passed on to [mo_property()] when `property` is not `NULL`. -#' @details This function is useful for preprocessing data before creating [antibiograms][antibiograms()] or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species. +#' @details This function is useful for preprocessing data before creating [antibiograms][antibiogram()] or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species. #' @export #' @seealso [mo_property()], [as.mo()], [antibiogram()] #' @examples diff --git a/data-raw/_generate_python_wrapper.sh b/data-raw/_generate_python_wrapper.sh index b9b629f8d..e5f7519e1 100644 --- a/data-raw/_generate_python_wrapper.sh +++ b/data-raw/_generate_python_wrapper.sh @@ -42,10 +42,6 @@ description_file="../DESCRIPTION" # Write header to the datasets Python file, including the convert_to_python function cat < "$datasets_file" -BLUE = '\033[94m' -GREEN = '\033[32m' -RESET = '\033[0m' - import os import sys from rpy2 import robjects @@ -61,18 +57,22 @@ venv_path = sys.prefix r_lib_path = os.path.join(venv_path, "R_libs") # Ensure the R library path exists os.makedirs(r_lib_path, exist_ok=True) -# Set the R library path in .libPaths -base = importr('base') -# Turn off warnings -base.options(warn = -1) -base._libPaths(r_lib_path) +# Import base and utils +base = importr('base') +utils = importr('utils') + +# Override R library paths globally for the session +robjects.r(f'.Library <- "{r_lib_path}"') # Replace default library +robjects.r(f'.Library.site <- "{r_lib_path}"') # Replace site-specific library +base._libPaths(r_lib_path) # Override .libPaths() as well + +# Get the effective library path r_amr_lib_path = base._libPaths()[0] # Check if the AMR package is installed in R -if not isinstalled('AMR', lib_loc = r_amr_lib_path): - utils = importr('utils') - print(f"{BLUE}AMR:{RESET} Installing AMR package to {BLUE}{r_amr_lib_path}/{RESET}...", flush=True) +if not isinstalled('AMR', lib_loc=r_amr_lib_path): + print(f"AMR: Installing latest AMR R package to {r_amr_lib_path}...", flush=True) utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True) # Python package version of AMR @@ -87,16 +87,12 @@ r_amr_version = robjects.r(f'as.character(packageVersion("AMR", lib.loc = "{r_li # Compare R and Python package versions if r_amr_version != python_amr_version: try: - print(f"{BLUE}AMR:{RESET} Updating AMR package in {BLUE}{r_amr_lib_path}/{RESET}...", flush=True) - utils = importr('utils') + print(f"AMR: Updating AMR package in {r_amr_lib_path}...", flush=True) utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True) except Exception as e: - print(f"{BLUE}AMR:{RESET} Could not update: {e}{RESET}", flush=True) + print(f"AMR: Could not update: {e}", flush=True) -# Restore warnings to default -base.options(warn = 0) - -print(f"{BLUE}AMR:{RESET} Setting up R environment and AMR datasets...", flush=True) +print(f"AMR: Setting up R environment and AMR datasets...", flush=True) # Activate the automatic conversion between R and pandas DataFrames pandas2ri.activate() @@ -121,7 +117,7 @@ microorganisms = pandas2ri.rpy2py(robjects.r('AMR::microorganisms[, !sapply(AMR: antibiotics = pandas2ri.rpy2py(robjects.r('AMR::antibiotics[, !sapply(AMR::antibiotics, is.list)]')) clinical_breakpoints = pandas2ri.rpy2py(robjects.r('AMR::clinical_breakpoints[, !sapply(AMR::clinical_breakpoints, is.list)]')) -print(f"{BLUE}AMR:{RESET} {GREEN}Done.{RESET}", flush=True) +print(f"AMR: Done.", flush=True) EOL echo "from .datasets import example_isolates" >> $init_file diff --git a/data-raw/gpt_training_text_v2.1.1.9128.txt b/data-raw/gpt_training_text_v2.1.1.9129.txt similarity index 99% rename from data-raw/gpt_training_text_v2.1.1.9128.txt rename to data-raw/gpt_training_text_v2.1.1.9129.txt index ad94c68c8..f7252d947 100644 --- a/data-raw/gpt_training_text_v2.1.1.9128.txt +++ b/data-raw/gpt_training_text_v2.1.1.9129.txt @@ -1,5 +1,5 @@ This files contains all context you must know about the AMR package for R. -First and foremost, you are trained on version 2.1.1.9128. Remember this whenever someone asks which AMR package version you’re at. +First and foremost, you are trained on version 2.1.1.9129. Remember this whenever someone asks which AMR package version you’re at. -------------------------------- THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'NAMESPACE': @@ -1705,7 +1705,7 @@ This function returns a table with values between 0 and 100 for \emph{susceptibi For estimating antimicrobial coverage, especially when creating a WISCA, the outcome might become more reliable by only including the top \emph{n} species encountered in the data. You can filter on this top \emph{n} using \code{\link[=top_n_microorganisms]{top_n_microorganisms()}}. For example, use \code{top_n_microorganisms(your_data, n = 10)} as a pre-processing step to only include the top 10 species in the data. -The numeric values of an antibiogram are stored in a long format as the \link{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting. +The numeric values of an antibiogram are stored in a long format as the \link[=attributes]{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting. \subsection{Formatting Type}{ The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} is the susceptibility percentage (for WISCA: \code{4-6} indicates the confidence level), \code{15} the numerator, and \code{300} the denominator: @@ -3900,6 +3900,8 @@ bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname, \item{FUN}{the function to call on the \code{mo} column to transform the microorganism codes - the default is \code{\link[=mo_shortname]{mo_shortname()}}} +\item{include_n_rows}{a \link{logical} to indicate if the total number of rows must be included in the output} + \item{...}{arguments passed on to \code{FUN}} \item{translate_ab}{a \link{character} of length 1 containing column names of the \link{antibiotics} data set} @@ -8027,7 +8029,7 @@ top_n_microorganisms(x, n, property = "fullname", n_for_each = NULL, This function filters a data set to include only the top \emph{n} microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera. } \details{ -This function is useful for preprocessing data before creating \link[=antibiograms]{antibiograms} or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species. +This function is useful for preprocessing data before creating \link[=antibiogram]{antibiograms} or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species. } \examples{ # filter to the top 3 species: diff --git a/data-raw/reproduction_of_microorganisms.R b/data-raw/reproduction_of_microorganisms.R index 843bcf668..842bbcd77 100644 --- a/data-raw/reproduction_of_microorganisms.R +++ b/data-raw/reproduction_of_microorganisms.R @@ -2210,6 +2210,6 @@ devtools::load_all(".") # run the unit tests Sys.setenv(NOT_CRAN = "true") -testthat::test_file("inst/tinytest/test-data.R") -testthat::test_file("inst/tinytest/test-mo.R") -testthat::test_file("inst/tinytest/test-mo_property.R") +testthat::test_file("inst/tests/testthat/test-data.R") +testthat::test_file("inst/tests/testthat/test-mo.R") +testthat::test_file("inst/tests/testthat/test-mo_property.R") diff --git a/inst/tinytest/test-_deprecated.R b/inst/tests/test-_deprecated.R similarity index 100% rename from inst/tinytest/test-_deprecated.R rename to inst/tests/test-_deprecated.R diff --git a/inst/tinytest/test-_misc.R b/inst/tests/test-_misc.R similarity index 87% rename from inst/tinytest/test-_misc.R rename to inst/tests/test-_misc.R index 582a09c5e..05f26b83a 100755 --- a/inst/tinytest/test-_misc.R +++ b/inst/tests/test-_misc.R @@ -27,6 +27,15 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # +tryCatch(!is.function(expect_stout), error = function(e) TRUE) { + expect_stout <<- testthat::expect_output +} +tryCatch(!is.function(expect_inherits), error = function(e) TRUE) { + expect_inherits <<- function(x, y, ...) testthat::expect(inherits(x, y), + failure_message = paste0("Expected class ", paste(y, collapse = "/"), + ", got class ", paste(class(x), collapse = "/"))) +} + expect_equal(AMR:::percentage(0.25), "25%") expect_equal(AMR:::percentage(0.5), "50%") expect_equal(AMR:::percentage(0.500, digits = 1), "50.0%") diff --git a/inst/tinytest/test-ab.R b/inst/tests/test-ab.R similarity index 100% rename from inst/tinytest/test-ab.R rename to inst/tests/test-ab.R diff --git a/inst/tinytest/test-ab_from_text.R b/inst/tests/test-ab_from_text.R similarity index 100% rename from inst/tinytest/test-ab_from_text.R rename to inst/tests/test-ab_from_text.R diff --git a/inst/tinytest/test-ab_property.R b/inst/tests/test-ab_property.R similarity index 100% rename from inst/tinytest/test-ab_property.R rename to inst/tests/test-ab_property.R diff --git a/inst/tinytest/test-ab_selectors.R b/inst/tests/test-ab_selectors.R similarity index 100% rename from inst/tinytest/test-ab_selectors.R rename to inst/tests/test-ab_selectors.R diff --git a/inst/tinytest/test-age.R b/inst/tests/test-age.R similarity index 100% rename from inst/tinytest/test-age.R rename to inst/tests/test-age.R diff --git a/inst/tinytest/test-antibiogram.R b/inst/tests/test-antibiogram.R similarity index 100% rename from inst/tinytest/test-antibiogram.R rename to inst/tests/test-antibiogram.R diff --git a/inst/tinytest/test-atc_online.R b/inst/tests/test-atc_online.R similarity index 100% rename from inst/tinytest/test-atc_online.R rename to inst/tests/test-atc_online.R diff --git a/inst/tinytest/test-av.R b/inst/tests/test-av.R similarity index 100% rename from inst/tinytest/test-av.R rename to inst/tests/test-av.R diff --git a/inst/tinytest/test-av_from_text.R b/inst/tests/test-av_from_text.R similarity index 100% rename from inst/tinytest/test-av_from_text.R rename to inst/tests/test-av_from_text.R diff --git a/inst/tinytest/test-av_property.R b/inst/tests/test-av_property.R similarity index 100% rename from inst/tinytest/test-av_property.R rename to inst/tests/test-av_property.R diff --git a/inst/tinytest/test-availability.R b/inst/tests/test-availability.R similarity index 100% rename from inst/tinytest/test-availability.R rename to inst/tests/test-availability.R diff --git a/inst/tinytest/test-bug_drug_combinations.R b/inst/tests/test-bug_drug_combinations.R similarity index 100% rename from inst/tinytest/test-bug_drug_combinations.R rename to inst/tests/test-bug_drug_combinations.R diff --git a/inst/tinytest/test-count.R b/inst/tests/test-count.R similarity index 100% rename from inst/tinytest/test-count.R rename to inst/tests/test-count.R diff --git a/inst/tinytest/test-custom_antimicrobials.R b/inst/tests/test-custom_antimicrobials.R similarity index 100% rename from inst/tinytest/test-custom_antimicrobials.R rename to inst/tests/test-custom_antimicrobials.R diff --git a/inst/tinytest/test-custom_microorganisms.R b/inst/tests/test-custom_microorganisms.R similarity index 99% rename from inst/tinytest/test-custom_microorganisms.R rename to inst/tests/test-custom_microorganisms.R index 5d106ab6e..acfe7fa7a 100644 --- a/inst/tinytest/test-custom_microorganisms.R +++ b/inst/tests/test-custom_microorganisms.R @@ -37,7 +37,7 @@ suppressMessages( species = "asburiae/cloacae") ) ) - + expect_identical(as.character(as.mo("ENT_ASB_CLO")), "ENT_ASB_CLO") expect_identical(mo_name("ENT_ASB_CLO"), "Enterobacter asburiae/cloacae") expect_identical(mo_gramstain("ENT_ASB_CLO", language = NULL), "Gram-negative") diff --git a/inst/tinytest/test-data.R b/inst/tests/test-data.R similarity index 100% rename from inst/tinytest/test-data.R rename to inst/tests/test-data.R diff --git a/inst/tinytest/test-disk.R b/inst/tests/test-disk.R similarity index 100% rename from inst/tinytest/test-disk.R rename to inst/tests/test-disk.R diff --git a/inst/tinytest/test-eucast_rules.R b/inst/tests/test-eucast_rules.R similarity index 100% rename from inst/tinytest/test-eucast_rules.R rename to inst/tests/test-eucast_rules.R diff --git a/inst/tinytest/test-first_isolate.R b/inst/tests/test-first_isolate.R similarity index 100% rename from inst/tinytest/test-first_isolate.R rename to inst/tests/test-first_isolate.R diff --git a/inst/tinytest/test-g.test.R b/inst/tests/test-g.test.R similarity index 100% rename from inst/tinytest/test-g.test.R rename to inst/tests/test-g.test.R diff --git a/inst/tinytest/test-get_episode.R b/inst/tests/test-get_episode.R similarity index 100% rename from inst/tinytest/test-get_episode.R rename to inst/tests/test-get_episode.R diff --git a/inst/tinytest/test-ggplot_sir.R b/inst/tests/test-ggplot_sir.R similarity index 92% rename from inst/tinytest/test-ggplot_sir.R rename to inst/tests/test-ggplot_sir.R index 29ec76249..afbe4ac94 100644 --- a/inst/tinytest/test-ggplot_sir.R +++ b/inst/tests/test-ggplot_sir.R @@ -43,13 +43,15 @@ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE) && summarise_all(resistance) %>% as.double() ) - - expect_stdout(print(example_isolates %>% - select(AMC, CIP) %>% - ggplot_sir(x = "interpretation", facet = "antibiotic"))) - expect_stdout(print(example_isolates %>% - select(AMC, CIP) %>% - ggplot_sir(x = "antibiotic", facet = "interpretation"))) + + expect_inherits(example_isolates %>% + select(AMC, CIP) %>% + ggplot_sir(x = "interpretation", facet = "antibiotic"), + "gg") + expect_inherits(example_isolates %>% + select(AMC, CIP) %>% + ggplot_sir(x = "antibiotic", facet = "interpretation"), + "gg") expect_equal( (example_isolates %>% diff --git a/inst/tinytest/test-guess_ab_col.R b/inst/tests/test-guess_ab_col.R similarity index 100% rename from inst/tinytest/test-guess_ab_col.R rename to inst/tests/test-guess_ab_col.R diff --git a/inst/tinytest/test-italicise_taxonomy.R b/inst/tests/test-italicise_taxonomy.R similarity index 100% rename from inst/tinytest/test-italicise_taxonomy.R rename to inst/tests/test-italicise_taxonomy.R diff --git a/inst/tinytest/test-join_microorganisms.R b/inst/tests/test-join_microorganisms.R similarity index 100% rename from inst/tinytest/test-join_microorganisms.R rename to inst/tests/test-join_microorganisms.R diff --git a/inst/tinytest/test-key_antimicrobials.R b/inst/tests/test-key_antimicrobials.R similarity index 100% rename from inst/tinytest/test-key_antimicrobials.R rename to inst/tests/test-key_antimicrobials.R diff --git a/inst/tinytest/test-kurtosis.R b/inst/tests/test-kurtosis.R similarity index 100% rename from inst/tinytest/test-kurtosis.R rename to inst/tests/test-kurtosis.R diff --git a/inst/tinytest/test-like.R b/inst/tests/test-like.R similarity index 100% rename from inst/tinytest/test-like.R rename to inst/tests/test-like.R diff --git a/inst/tinytest/test-mdro.R b/inst/tests/test-mdro.R similarity index 100% rename from inst/tinytest/test-mdro.R rename to inst/tests/test-mdro.R diff --git a/inst/tinytest/test-mean_amr_distance.R b/inst/tests/test-mean_amr_distance.R similarity index 100% rename from inst/tinytest/test-mean_amr_distance.R rename to inst/tests/test-mean_amr_distance.R diff --git a/inst/tinytest/test-mic.R b/inst/tests/test-mic.R similarity index 100% rename from inst/tinytest/test-mic.R rename to inst/tests/test-mic.R diff --git a/inst/tinytest/test-mo.R b/inst/tests/test-mo.R similarity index 100% rename from inst/tinytest/test-mo.R rename to inst/tests/test-mo.R diff --git a/inst/tinytest/test-mo_property.R b/inst/tests/test-mo_property.R similarity index 100% rename from inst/tinytest/test-mo_property.R rename to inst/tests/test-mo_property.R diff --git a/inst/tinytest/test-pca.R b/inst/tests/test-pca.R similarity index 100% rename from inst/tinytest/test-pca.R rename to inst/tests/test-pca.R diff --git a/inst/tinytest/test-proportion.R b/inst/tests/test-proportion.R similarity index 100% rename from inst/tinytest/test-proportion.R rename to inst/tests/test-proportion.R diff --git a/inst/tinytest/test-random.R b/inst/tests/test-random.R similarity index 100% rename from inst/tinytest/test-random.R rename to inst/tests/test-random.R diff --git a/inst/tinytest/test-resistance_predict.R b/inst/tests/test-resistance_predict.R similarity index 100% rename from inst/tinytest/test-resistance_predict.R rename to inst/tests/test-resistance_predict.R diff --git a/inst/tinytest/test-sir.R b/inst/tests/test-sir.R similarity index 100% rename from inst/tinytest/test-sir.R rename to inst/tests/test-sir.R diff --git a/inst/tinytest/test-skewness.R b/inst/tests/test-skewness.R similarity index 100% rename from inst/tinytest/test-skewness.R rename to inst/tests/test-skewness.R diff --git a/inst/tinytest/test-top_n_microorganisms.R b/inst/tests/test-top_n_microorganisms.R similarity index 100% rename from inst/tinytest/test-top_n_microorganisms.R rename to inst/tests/test-top_n_microorganisms.R diff --git a/inst/tinytest/test-translate.R b/inst/tests/test-translate.R similarity index 100% rename from inst/tinytest/test-translate.R rename to inst/tests/test-translate.R diff --git a/inst/tinytest/test-vctrs.R b/inst/tests/test-vctrs.R similarity index 100% rename from inst/tinytest/test-vctrs.R rename to inst/tests/test-vctrs.R diff --git a/inst/tinytest/test-zzz.R b/inst/tests/test-zzz.R similarity index 100% rename from inst/tinytest/test-zzz.R rename to inst/tests/test-zzz.R diff --git a/man/antibiogram.Rd b/man/antibiogram.Rd index c3023111a..8f2506c33 100644 --- a/man/antibiogram.Rd +++ b/man/antibiogram.Rd @@ -100,7 +100,7 @@ This function returns a table with values between 0 and 100 for \emph{susceptibi For estimating antimicrobial coverage, especially when creating a WISCA, the outcome might become more reliable by only including the top \emph{n} species encountered in the data. You can filter on this top \emph{n} using \code{\link[=top_n_microorganisms]{top_n_microorganisms()}}. For example, use \code{top_n_microorganisms(your_data, n = 10)} as a pre-processing step to only include the top 10 species in the data. -The numeric values of an antibiogram are stored in a long format as the \link{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting. +The numeric values of an antibiogram are stored in a long format as the \link[=attributes]{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting. \subsection{Formatting Type}{ The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} is the susceptibility percentage (for WISCA: \code{4-6} indicates the confidence level), \code{15} the numerator, and \code{300} the denominator: diff --git a/man/bug_drug_combinations.Rd b/man/bug_drug_combinations.Rd index 3544563ed..8a2206b83 100644 --- a/man/bug_drug_combinations.Rd +++ b/man/bug_drug_combinations.Rd @@ -21,6 +21,8 @@ bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname, \item{FUN}{the function to call on the \code{mo} column to transform the microorganism codes - the default is \code{\link[=mo_shortname]{mo_shortname()}}} +\item{include_n_rows}{a \link{logical} to indicate if the total number of rows must be included in the output} + \item{...}{arguments passed on to \code{FUN}} \item{translate_ab}{a \link{character} of length 1 containing column names of the \link{antibiotics} data set} diff --git a/man/top_n_microorganisms.Rd b/man/top_n_microorganisms.Rd index 876ea2bff..2c2e87b60 100644 --- a/man/top_n_microorganisms.Rd +++ b/man/top_n_microorganisms.Rd @@ -24,7 +24,7 @@ top_n_microorganisms(x, n, property = "fullname", n_for_each = NULL, This function filters a data set to include only the top \emph{n} microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera. } \details{ -This function is useful for preprocessing data before creating \link[=antibiograms]{antibiograms} or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species. +This function is useful for preprocessing data before creating \link[=antibiogram]{antibiograms} or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species. } \examples{ # filter to the top 3 species: diff --git a/tests/tinytest.R b/tests/tinytest.R index cede282c9..48ca4a9dc 100644 --- a/tests/tinytest.R +++ b/tests/tinytest.R @@ -27,21 +27,25 @@ # how to conduct AMR data analysis: https://msberends.github.io/AMR/ # # ==================================================================== # -# we use {tinytest} instead of {testthat} because it does not rely on recent R versions - we want to test on R >= 3.0. +# we use {tinytest} for older R versions to allow unit testing in R >= 3.0.0. -# Run them in RStudio using: -# rstudioapi::jobRunScript("tests/tinytest.R", name = "AMR Unit Tests", workingDir = getwd(), exportEnv = "tinytest_results") +# use this to quickly use testtthat for more informative errors: +# testthat::test_dir("inst/tests") -# test only on GitHub Actions and at using RStudio jobs - not on CRAN as tests are lengthy -if (tryCatch(isTRUE(AMR:::import_fn("isJob", "rstudioapi")()), error = function(e) FALSE) || - identical(Sys.getenv("R_RUN_TINYTEST"), "true")) { - # env var 'R_LIBS_USER' got overwritten during 'R CMD check' in GitHub Actions, so: +# test only on GitHub Actions - not on CRAN as tests are lengthy +if (identical(Sys.getenv("R_RUN_TINYTEST"), "true")) { + # env var 'R_LIBS_USER' gets overwritten during 'R CMD check' in GitHub Actions, so: .libPaths(c(Sys.getenv("R_LIBS_USER_GH_ACTIONS"), .libPaths())) + if (AMR:::pkg_is_available("tinytest", also_load = TRUE)) { + + # load the package library(AMR) + # set language set_AMR_locale("English") - # set some functions if on old R + + # set some functions for older R versions if (getRversion() < "3.2.0") { anyNA <- AMR:::anyNA dir.exists <- AMR:::dir.exists @@ -64,16 +68,15 @@ if (tryCatch(isTRUE(AMR:::import_fn("isJob", "rstudioapi")()), error = function( if (getRversion() < "4.0.0") { deparse1 <- AMR:::deparse1 } - - # start the unit tests + suppressMessages( out <- test_package("AMR", - testdir = ifelse(dir.exists("inst/tinytest"), - "inst/tinytest", - "tinytest" - ), - verbose = FALSE, - color = FALSE + testdir = ifelse(dir.exists("inst/tests"), + "inst/tests", + "tests" + ), + verbose = FALSE, + color = FALSE ) ) cat("\n\nSUMMARY:\n")