mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 16:02:02 +02:00
(v1.6.0.9048) ab selectors overhaul
This commit is contained in:
@ -37,3 +37,20 @@ expect_identical(suppressWarnings(key_antibiotics_equal("S", "S")),
|
||||
expect_warning(filter_first_weighted_isolate(example_isolates))
|
||||
expect_identical(suppressWarnings(filter_first_weighted_isolate(example_isolates)),
|
||||
filter_first_isolate(example_isolates))
|
||||
|
||||
expect_warning(filter_ab_class(example_isolates, "mycobact"))
|
||||
expect_warning(filter_aminoglycosides(example_isolates))
|
||||
expect_warning(filter_betalactams(example_isolates))
|
||||
expect_warning(filter_carbapenems(example_isolates))
|
||||
expect_warning(filter_cephalosporins(example_isolates))
|
||||
expect_warning(filter_1st_cephalosporins(example_isolates))
|
||||
expect_warning(filter_2nd_cephalosporins(example_isolates))
|
||||
expect_warning(filter_3rd_cephalosporins(example_isolates))
|
||||
expect_warning(filter_4th_cephalosporins(example_isolates))
|
||||
expect_warning(filter_5th_cephalosporins(example_isolates))
|
||||
expect_warning(filter_fluoroquinolones(example_isolates))
|
||||
expect_warning(filter_glycopeptides(example_isolates))
|
||||
expect_warning(filter_macrolides(example_isolates))
|
||||
expect_warning(filter_oxazolidinones(example_isolates))
|
||||
expect_warning(filter_penicillins(example_isolates))
|
||||
expect_warning(filter_tetracyclines(example_isolates))
|
||||
|
@ -23,7 +23,7 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
if (current_R_older_than(3.2)) {
|
||||
if (!AMR:::current_R_older_than(3.2)) {
|
||||
# antibiotic class selectors require at least R-3.2
|
||||
expect_true(ncol(example_isolates[, aminoglycosides(), drop = FALSE]) < ncol(example_isolates))
|
||||
expect_true(ncol(example_isolates[, betalactams(), drop = FALSE]) < ncol(example_isolates))
|
||||
@ -40,4 +40,24 @@ if (current_R_older_than(3.2)) {
|
||||
expect_true(ncol(example_isolates[, oxazolidinones(), drop = FALSE]) < ncol(example_isolates))
|
||||
expect_true(ncol(example_isolates[, penicillins(), drop = FALSE]) < ncol(example_isolates))
|
||||
expect_true(ncol(example_isolates[, tetracyclines(), drop = FALSE]) < ncol(example_isolates))
|
||||
|
||||
# Examples:
|
||||
|
||||
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
|
||||
expect_equal(ncol(example_isolates[, c("mo", aminoglycosides())]), 5)
|
||||
|
||||
# filter using any() or all()
|
||||
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), ]), 55)
|
||||
expect_equal(nrow(subset(example_isolates, any(carbapenems() == "R"))), 55)
|
||||
|
||||
# filter on any or all results in the carbapenem columns (i.e., IPM, MEM):
|
||||
expect_equal(nrow(example_isolates[any(carbapenems()), ]), 962)
|
||||
expect_equal(nrow(example_isolates[all(carbapenems()), ]), 756)
|
||||
|
||||
# filter with multiple antibiotic selectors using c()
|
||||
expect_equal(nrow(example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]), 26)
|
||||
|
||||
# filter + select in one go: get penicillins in carbapenems-resistant strains
|
||||
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), penicillins()]), 55)
|
||||
expect_equal(ncol(example_isolates[any(carbapenems() == "R"), penicillins()]), 7)
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Data Analysis for R #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://github.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2018-2021 Berends MS, Luz CF et al. #
|
||||
# Developed at the University of Groningen, the Netherlands, in #
|
||||
# collaboration with non-profit organisations Certe Medical #
|
||||
# Diagnostics & Advice, and University Medical Center Groningen. #
|
||||
# #
|
||||
# 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 the full manual and a complete tutorial about #
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
if (pkg_is_available("dplyr")) {
|
||||
expect_true(example_isolates %>% filter_ab_class("carbapenem") %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_aminoglycosides() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_betalactams() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_carbapenems() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_1st_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_2nd_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_3rd_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_4th_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% mutate(ceftaroline = CTX) %>% filter_5th_cephalosporins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_fluoroquinolones() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_glycopeptides() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_macrolides() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_oxazolidinones() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_penicillins() %>% nrow() < nrow(example_isolates))
|
||||
expect_true(example_isolates %>% filter_tetracyclines() %>% nrow() < nrow(example_isolates))
|
||||
|
||||
expect_true(example_isolates %>% filter_carbapenems("R", "all") %>% nrow() > 0)
|
||||
|
||||
expect_error(example_isolates %>% filter_carbapenems(result = "test"))
|
||||
expect_error(example_isolates %>% filter_carbapenems(scope = "test"))
|
||||
expect_message(example_isolates %>% select(1:3) %>% filter_carbapenems())
|
||||
}
|
Reference in New Issue
Block a user