mirror of
https://github.com/msberends/AMR.git
synced 2025-07-10 01:02:47 +02:00
ggplot_rsi example update, more unit tests
This commit is contained in:
@ -33,10 +33,13 @@ test_that("guess_atc works", {
|
||||
rep("J01FA01", 8))
|
||||
|
||||
expect_identical(class(as.atc("amox")), "atc")
|
||||
|
||||
expect_identical(class(pull(antibiotics, atc)), "atc")
|
||||
expect_identical(ab_trivial_nl("Cefmenoxim"), "Cefmenoxim")
|
||||
|
||||
expect_warning(as.atc("Z00ZZ00")) # not yet available in data set
|
||||
expect_warning(as.atc("UNKNOWN"))
|
||||
|
||||
expect_output(print(as.atc("amox")))
|
||||
|
||||
# first 5 chars of official name
|
||||
expect_equal(as.character(as.atc(c("nitro", "cipro"))),
|
||||
|
@ -10,10 +10,13 @@ test_that("as.bactid works", {
|
||||
expect_equal(as.character(as.bactid("Escherichia species")), "ESC")
|
||||
expect_equal(as.character(as.bactid(" ESCCOL ")), "ESCCOL")
|
||||
expect_equal(as.character(as.bactid("klpn")), "KLEPNE")
|
||||
expect_equal(as.character(as.bactid("Klebsiella")), "KLE")
|
||||
expect_equal(as.character(as.bactid("coagulase negative")), "STACNS")
|
||||
|
||||
expect_equal(as.character(as.bactid("P. aer")), "PSEAER") # not Pasteurella aerogenes
|
||||
|
||||
expect_equal(as.character(as.bactid("Negative rods")), "GNR")
|
||||
expect_equal(as.character(as.bactid("Gram negative rods")), "GNR")
|
||||
|
||||
# GLIMS
|
||||
expect_equal(as.character(as.bactid("shiboy")), "SHIBOY")
|
||||
@ -65,6 +68,8 @@ test_that("as.bactid works", {
|
||||
expect_identical(as.character(guess_bactid("S. salivarius", Lancefield = FALSE)), "STCSAL")
|
||||
expect_identical(as.character(guess_bactid("S. salivarius", Lancefield = TRUE)), "STCGRK") # group K
|
||||
|
||||
library(dplyr)
|
||||
|
||||
# select with one column
|
||||
expect_identical(
|
||||
septic_patients[1:10,] %>%
|
||||
@ -88,6 +93,9 @@ test_that("as.bactid works", {
|
||||
# unknown results
|
||||
expect_warning(as.bactid(c("INVALID", "Yeah, unknown")))
|
||||
|
||||
# too many columns
|
||||
expect_error(septic_patients %>% select(1:3) %>% as.bactid())
|
||||
|
||||
# print
|
||||
expect_output(print(as.bactid(c("ESCCOL", NA))))
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
context("eucast.R")
|
||||
|
||||
test_that("EUCAST rules work", {
|
||||
|
||||
expect_error(EUCAST_rules(septic_patients, col_bactid = "Non-existing"))
|
||||
|
||||
|
||||
expect_identical(colnames(septic_patients),
|
||||
colnames(suppressWarnings(EUCAST_rules(septic_patients))))
|
||||
|
||||
@ -31,4 +35,31 @@ test_that("EUCAST rules work", {
|
||||
coli = "R", # Colistin
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(suppressWarnings(EUCAST_rules(a, info = FALSE)), b)
|
||||
|
||||
# pita must be R in Enterobacteriaceae when tica is R
|
||||
library(dplyr)
|
||||
expect_equal(suppressWarnings(
|
||||
septic_patients %>%
|
||||
mutate(tica = as.rsi("R"),
|
||||
pita = as.rsi("S")) %>%
|
||||
EUCAST_rules(col_bactid = "bactid") %>%
|
||||
left_join_microorganisms() %>%
|
||||
filter(family == "Enterobacteriaceae") %>%
|
||||
pull(pita) %>%
|
||||
unique() %>%
|
||||
as.character()),
|
||||
"R")
|
||||
# azit and clar must be equal to eryt
|
||||
expect_equal(suppressWarnings(
|
||||
septic_patients %>%
|
||||
mutate(azit = as.rsi("R"),
|
||||
clar = as.rsi("R")) %>%
|
||||
EUCAST_rules(col_bactid = "bactid") %>%
|
||||
pull(clar)),
|
||||
suppressWarnings(
|
||||
septic_patients %>%
|
||||
EUCAST_rules(col_bactid = "bactid") %>%
|
||||
left_join_microorganisms() %>%
|
||||
pull(eryt)))
|
||||
|
||||
})
|
||||
|
@ -25,6 +25,20 @@ test_that("first isolates work", {
|
||||
info = TRUE),
|
||||
na.rm = TRUE)),
|
||||
1426)
|
||||
# and 1449 when not ignoring I
|
||||
expect_equal(
|
||||
suppressWarnings(
|
||||
sum(
|
||||
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
|
||||
col_date = "date",
|
||||
col_patient_id = "patient_id",
|
||||
col_bactid = "bactid",
|
||||
col_keyantibiotics = "keyab",
|
||||
ignore_I = FALSE,
|
||||
type = "keyantibiotics",
|
||||
info = TRUE),
|
||||
na.rm = TRUE)),
|
||||
1449)
|
||||
# and 1430 when using points
|
||||
expect_equal(
|
||||
suppressWarnings(
|
||||
@ -86,10 +100,34 @@ test_that("first isolates work", {
|
||||
na.rm = TRUE),
|
||||
1501)
|
||||
|
||||
# "No isolates found"
|
||||
expect_message(septic_patients %>%
|
||||
mutate(specimen = "test") %>%
|
||||
mutate(first = first_isolate(., "date", "patient_id",
|
||||
col_bactid = "bactid", col_specimen = "specimen",
|
||||
filter_specimen = "something_unexisting")))
|
||||
col_bactid = "bactid",
|
||||
col_specimen = "specimen",
|
||||
filter_specimen = "something_unexisting",
|
||||
output_logical = FALSE)))
|
||||
|
||||
# printing of exclusion message
|
||||
expect_output(septic_patients %>%
|
||||
first_isolate(col_date = "date",
|
||||
col_bactid = "bactid",
|
||||
col_patient_id = "patient_id",
|
||||
col_testcode = "sex",
|
||||
testcodes_exclude = "M"))
|
||||
|
||||
# errors
|
||||
expect_error(first_isolate("date", "patient_id", col_bactid = "bactid"))
|
||||
expect_error(first_isolate(septic_patients))
|
||||
expect_error(first_isolate(septic_patients,
|
||||
col_date = "non-existing col",
|
||||
col_bactid = "bactid"))
|
||||
|
||||
expect_warning(septic_patients %>%
|
||||
mutate(bactid = as.character(bactid)) %>%
|
||||
first_isolate(col_date = "date",
|
||||
col_bactid = "bactid",
|
||||
col_patient_id = "patient_id"))
|
||||
|
||||
})
|
||||
|
Reference in New Issue
Block a user