mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 14:01:55 +02:00
replaced bactid by mo
This commit is contained in:
@ -1,118 +0,0 @@
|
||||
context("bactid.R")
|
||||
|
||||
test_that("as.bactid works", {
|
||||
expect_identical(
|
||||
as.character(as.bactid(c("E. coli", "H. influenzae"))),
|
||||
c("ESCCOL", "HAEINF"))
|
||||
|
||||
expect_equal(as.character(as.bactid("Escherichia coli")), "ESCCOL")
|
||||
expect_equal(as.character(as.bactid("Escherichia coli")), "ESCCOL")
|
||||
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")
|
||||
|
||||
expect_equal(as.character(as.bactid("MRSE")), "STAEPI")
|
||||
expect_equal(as.character(as.bactid("VRE")), "ENC")
|
||||
expect_equal(as.character(as.bactid("MRPA")), "PSEAER")
|
||||
expect_equal(as.character(as.bactid("PISP")), "STCPNE")
|
||||
expect_equal(as.character(as.bactid("PRSP")), "STCPNE")
|
||||
expect_equal(as.character(as.bactid("VISP")), "STCPNE")
|
||||
expect_equal(as.character(as.bactid("VRSP")), "STCPNE")
|
||||
|
||||
expect_identical(
|
||||
as.character(
|
||||
as.bactid(c("stau",
|
||||
"STAU",
|
||||
"staaur",
|
||||
"S. aureus",
|
||||
"S aureus",
|
||||
"Staphylococcus aureus",
|
||||
"MRSA",
|
||||
"VISA"))),
|
||||
rep("STAAUR", 8))
|
||||
|
||||
# check for Becker classification
|
||||
expect_identical(as.character(guess_bactid("S. epidermidis", Becker = FALSE)), "STAEPI")
|
||||
expect_identical(as.character(guess_bactid("S. epidermidis", Becker = TRUE)), "STACNS")
|
||||
expect_identical(as.character(guess_bactid("STAEPI", Becker = TRUE)), "STACNS")
|
||||
expect_identical(as.character(guess_bactid("S. intermedius", Becker = FALSE)), "STAINT")
|
||||
expect_identical(as.character(guess_bactid("S. intermedius", Becker = TRUE)), "STACPS")
|
||||
expect_identical(as.character(guess_bactid("STAINT", Becker = TRUE)), "STACPS")
|
||||
# aureus must only be influenced if Becker = "all"
|
||||
expect_identical(as.character(guess_bactid("STAAUR", Becker = FALSE)), "STAAUR")
|
||||
expect_identical(as.character(guess_bactid("STAAUR", Becker = TRUE)), "STAAUR")
|
||||
expect_identical(as.character(guess_bactid("STAAUR", Becker = "all")), "STACPS")
|
||||
|
||||
# check for Lancefield classification
|
||||
expect_identical(as.character(guess_bactid("S. pyogenes", Lancefield = FALSE)), "STCPYO")
|
||||
expect_identical(as.character(guess_bactid("S. pyogenes", Lancefield = TRUE)), "STCGRA")
|
||||
expect_identical(as.character(guess_bactid("STCPYO", Lancefield = TRUE)), "STCGRA")
|
||||
expect_identical(as.character(guess_bactid("S. agalactiae", Lancefield = FALSE)), "STCAGA")
|
||||
expect_identical(as.character(guess_bactid("S. agalactiae", Lancefield = TRUE)), "STCGRB") # group B
|
||||
expect_identical(as.character(guess_bactid("S. equisimilis", Lancefield = FALSE)), "STCEQS")
|
||||
expect_identical(as.character(guess_bactid("S. equisimilis", Lancefield = TRUE)), "STCGRC") # group C
|
||||
expect_identical(as.character(guess_bactid("S. anginosus", Lancefield = FALSE)), "STCANG")
|
||||
expect_identical(as.character(guess_bactid("S. anginosus", Lancefield = TRUE)), "STCGRF") # group F
|
||||
expect_identical(as.character(guess_bactid("S. sanguis", Lancefield = FALSE)), "STCSAN")
|
||||
expect_identical(as.character(guess_bactid("S. sanguis", Lancefield = TRUE)), "STCGRH") # group H
|
||||
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,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus) %>%
|
||||
as.bactid() %>%
|
||||
as.character(),
|
||||
c("ESC", "ESC", "STA", "STA", "STA",
|
||||
"STA", "STA", "STA", "STA", "STA"))
|
||||
|
||||
# select with two columns
|
||||
expect_identical(
|
||||
septic_patients[1:10,] %>%
|
||||
pull(bactid),
|
||||
septic_patients[1:10,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus, species) %>%
|
||||
as.bactid() %>%
|
||||
as.character())
|
||||
|
||||
# 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))))
|
||||
|
||||
# helper function
|
||||
expect_identical(as.bactid("ESCCOL"),
|
||||
guess_bactid("ESCCOL"))
|
||||
|
||||
# test pull
|
||||
expect_equal(nrow(septic_patients %>% mutate(bactid = as.bactid(bactid))),
|
||||
2000)
|
||||
|
||||
# test data.frame
|
||||
expect_equal(nrow(data.frame(test = as.bactid("ESCCOL"))),
|
||||
1)
|
||||
|
||||
# check empty values
|
||||
expect_equal(as.character(suppressWarnings(as.bactid(""))),
|
||||
NA_character_)
|
||||
|
||||
})
|
24
tests/testthat/test-deprecated.R
Normal file
24
tests/testthat/test-deprecated.R
Normal file
@ -0,0 +1,24 @@
|
||||
context("deprecated.R")
|
||||
|
||||
test_that("deprecated functions work", {
|
||||
|
||||
expect_identical(is.mo(as.mo("esco")), suppressWarnings(is.bactid(as.bactid("esco"))))
|
||||
expect_warning(identical(is.mo(as.mo("esco")), is.bactid(as.bactid("esco"))))
|
||||
|
||||
expect_identical(as.mo("esco"), suppressWarnings(guess_bactid("esco")))
|
||||
|
||||
expect_error(suppressWarnings(ratio("A")))
|
||||
expect_error(suppressWarnings(ratio(1, ratio = "abc")))
|
||||
expect_error(suppressWarnings(ratio(c(1, 2), ratio = c(1, 2, 3))))
|
||||
expect_warning(ratio(c(772, 1611, 737), ratio = "1:2:1"))
|
||||
expect_identical(suppressWarnings(ratio(c(772, 1611, 737), ratio = "1:2:1")), c(780, 1560, 780))
|
||||
expect_identical(suppressWarnings(ratio(c(1752, 1895), ratio = c(1, 1))), c(1823.5, 1823.5))
|
||||
|
||||
old_mo <- "ESCCOL"
|
||||
class(old_mo) <- "bactid"
|
||||
# print
|
||||
expect_output(print(old_mo))
|
||||
# test data.frame and pull
|
||||
expect_equal(as.character(dplyr::pull(data.frame(test = old_mo), test)), "ESCCOL")
|
||||
|
||||
})
|
@ -2,19 +2,19 @@ context("eucast.R")
|
||||
|
||||
test_that("EUCAST rules work", {
|
||||
|
||||
expect_error(EUCAST_rules(septic_patients, col_bactid = "Non-existing"))
|
||||
expect_error(EUCAST_rules(septic_patients, col_mo = "Non-existing"))
|
||||
|
||||
|
||||
expect_identical(colnames(septic_patients),
|
||||
colnames(suppressWarnings(EUCAST_rules(septic_patients))))
|
||||
|
||||
a <- data.frame(bactid =
|
||||
a <- data.frame(mo =
|
||||
c("KLEPNE", # Klebsiella pneumoniae
|
||||
"PSEAER", # Pseudomonas aeruginosa
|
||||
"ENTAER"), # Enterobacter aerogenes
|
||||
amox = "-", # Amoxicillin
|
||||
stringsAsFactors = FALSE)
|
||||
b <- data.frame(bactid =
|
||||
b <- data.frame(mo =
|
||||
c("KLEPNE", # Klebsiella pneumoniae
|
||||
"PSEAER", # Pseudomonas aeruginosa
|
||||
"ENTAER"), # Enterobacter aerogenes
|
||||
@ -24,12 +24,12 @@ test_that("EUCAST rules work", {
|
||||
expect_identical(suppressWarnings(EUCAST_rules(a, info = FALSE)), b)
|
||||
expect_identical(suppressWarnings(interpretive_reading(a, info = TRUE)), b)
|
||||
|
||||
a <- data.frame(bactid =
|
||||
a <- data.frame(mo =
|
||||
c("STAAUR", # Staphylococcus aureus
|
||||
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
|
||||
coli = "-", # Colistin
|
||||
stringsAsFactors = FALSE)
|
||||
b <- data.frame(bactid =
|
||||
b <- data.frame(mo =
|
||||
c("STAAUR", # Staphylococcus aureus
|
||||
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
|
||||
coli = "R", # Colistin
|
||||
@ -42,7 +42,7 @@ test_that("EUCAST rules work", {
|
||||
septic_patients %>%
|
||||
mutate(tica = as.rsi("R"),
|
||||
pita = as.rsi("S")) %>%
|
||||
EUCAST_rules(col_bactid = "bactid") %>%
|
||||
EUCAST_rules(col_mo = "mo") %>%
|
||||
left_join_microorganisms() %>%
|
||||
filter(family == "Enterobacteriaceae") %>%
|
||||
pull(pita) %>%
|
||||
@ -54,11 +54,11 @@ test_that("EUCAST rules work", {
|
||||
septic_patients %>%
|
||||
mutate(azit = as.rsi("R"),
|
||||
clar = as.rsi("R")) %>%
|
||||
EUCAST_rules(col_bactid = "bactid") %>%
|
||||
EUCAST_rules(col_mo = "mo") %>%
|
||||
pull(clar)),
|
||||
suppressWarnings(
|
||||
septic_patients %>%
|
||||
EUCAST_rules(col_bactid = "bactid") %>%
|
||||
EUCAST_rules(col_mo = "mo") %>%
|
||||
left_join_microorganisms() %>%
|
||||
pull(eryt)))
|
||||
|
||||
|
@ -7,7 +7,7 @@ test_that("first isolates work", {
|
||||
first_isolate(tbl = septic_patients,
|
||||
col_date = "date",
|
||||
col_patient_id = "patient_id",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
info = TRUE),
|
||||
na.rm = TRUE),
|
||||
1331)
|
||||
@ -19,7 +19,7 @@ test_that("first isolates work", {
|
||||
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
|
||||
col_date = "date",
|
||||
col_patient_id = "patient_id",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
col_keyantibiotics = "keyab",
|
||||
type = "keyantibiotics",
|
||||
info = TRUE),
|
||||
@ -32,7 +32,7 @@ test_that("first isolates work", {
|
||||
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
|
||||
col_date = "date",
|
||||
col_patient_id = "patient_id",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
col_keyantibiotics = "keyab",
|
||||
ignore_I = FALSE,
|
||||
type = "keyantibiotics",
|
||||
@ -46,7 +46,7 @@ test_that("first isolates work", {
|
||||
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
|
||||
col_date = "date",
|
||||
col_patient_id = "patient_id",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
col_keyantibiotics = "keyab",
|
||||
type = "points",
|
||||
info = TRUE),
|
||||
@ -57,7 +57,7 @@ test_that("first isolates work", {
|
||||
expect_equal(
|
||||
sum(
|
||||
first_isolate(septic_patients,
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
col_date = "date",
|
||||
col_patient_id = "patient_id",
|
||||
col_icu = "ward_icu",
|
||||
@ -76,7 +76,7 @@ test_that("first isolates work", {
|
||||
"Other")),
|
||||
col_date = "date",
|
||||
col_patient_id = "patient_id",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
col_specimen = "specimen",
|
||||
filter_specimen = "Urine",
|
||||
info = TRUE),
|
||||
@ -91,7 +91,7 @@ test_that("first isolates work", {
|
||||
"Other")),
|
||||
col_date = "date",
|
||||
col_patient_id = "patient_id",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
col_specimen = "specimen",
|
||||
filter_specimen = "Urine",
|
||||
col_icu = "ward_icu",
|
||||
@ -104,7 +104,7 @@ test_that("first isolates work", {
|
||||
expect_message(septic_patients %>%
|
||||
mutate(specimen = "test") %>%
|
||||
mutate(first = first_isolate(., "date", "patient_id",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
col_specimen = "specimen",
|
||||
filter_specimen = "something_unexisting",
|
||||
output_logical = FALSE)))
|
||||
@ -112,22 +112,22 @@ test_that("first isolates work", {
|
||||
# printing of exclusion message
|
||||
expect_output(septic_patients %>%
|
||||
first_isolate(col_date = "date",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
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("date", "patient_id", col_mo = "mo"))
|
||||
expect_error(first_isolate(septic_patients))
|
||||
expect_error(first_isolate(septic_patients,
|
||||
col_date = "non-existing col",
|
||||
col_bactid = "bactid"))
|
||||
col_mo = "mo"))
|
||||
|
||||
expect_warning(septic_patients %>%
|
||||
mutate(bactid = as.character(bactid)) %>%
|
||||
mutate(mo = as.character(mo)) %>%
|
||||
first_isolate(col_date = "date",
|
||||
col_bactid = "bactid",
|
||||
col_mo = "mo",
|
||||
col_patient_id = "patient_id"))
|
||||
|
||||
})
|
||||
|
@ -22,7 +22,7 @@ test_that("frequency table works", {
|
||||
expect_output(print(freq(septic_patients$age[0])))
|
||||
|
||||
# character
|
||||
expect_output(print(freq(septic_patients$bactid)))
|
||||
expect_output(print(freq(septic_patients$mo)))
|
||||
# integer
|
||||
expect_output(print(freq(septic_patients$age)))
|
||||
# date
|
||||
@ -56,21 +56,21 @@ test_that("frequency table works", {
|
||||
# top 5
|
||||
expect_equal(
|
||||
septic_patients %>%
|
||||
freq(bactid) %>%
|
||||
freq(mo) %>%
|
||||
top_freq(5) %>%
|
||||
length(),
|
||||
5)
|
||||
# there're more than 5 lowest values
|
||||
expect_gt(
|
||||
septic_patients %>%
|
||||
freq(bactid) %>%
|
||||
freq(mo) %>%
|
||||
top_freq(-5) %>%
|
||||
length(),
|
||||
5)
|
||||
# n has length > 1
|
||||
expect_error(
|
||||
septic_patients %>%
|
||||
freq(bactid) %>%
|
||||
freq(mo) %>%
|
||||
top_freq(n = c(1, 2))
|
||||
)
|
||||
# input must be freq tbl
|
||||
|
@ -25,11 +25,11 @@ test_that("joins work", {
|
||||
|
||||
|
||||
expect_equal(nrow(inner_join_microorganisms("ESCCOL")), 1)
|
||||
expect_equal(nrow(inner_join_microorganisms("ESCCOL", by = c("bactid" = "bactid"))), 1)
|
||||
expect_warning(inner_join_microorganisms("Escherichia", by = c("bactid" = "genus")))
|
||||
expect_equal(nrow(inner_join_microorganisms("ESCCOL", by = c("mo" = "mo"))), 1)
|
||||
expect_warning(inner_join_microorganisms("Escherichia", by = c("mo" = "genus")))
|
||||
|
||||
expect_equal(nrow(left_join_microorganisms("ESCCOL")), 1)
|
||||
expect_warning(left_join_microorganisms("Escherichia", by = c("bactid" = "genus")))
|
||||
expect_warning(left_join_microorganisms("Escherichia", by = c("mo" = "genus")))
|
||||
|
||||
expect_equal(nrow(semi_join_microorganisms("ESCCOL")), 1)
|
||||
expect_equal(nrow(anti_join_microorganisms("ESCCOL")), 0)
|
||||
|
118
tests/testthat/test-mo.R
Normal file
118
tests/testthat/test-mo.R
Normal file
@ -0,0 +1,118 @@
|
||||
context("mo.R")
|
||||
|
||||
test_that("as.mo works", {
|
||||
expect_identical(
|
||||
as.character(as.mo(c("E. coli", "H. influenzae"))),
|
||||
c("ESCCOL", "HAEINF"))
|
||||
|
||||
expect_equal(as.character(as.mo("Escherichia coli")), "ESCCOL")
|
||||
expect_equal(as.character(as.mo("Escherichia coli")), "ESCCOL")
|
||||
expect_equal(as.character(as.mo("Escherichia species")), "ESC")
|
||||
expect_equal(as.character(as.mo(" ESCCOL ")), "ESCCOL")
|
||||
expect_equal(as.character(as.mo("klpn")), "KLEPNE")
|
||||
expect_equal(as.character(as.mo("Klebsiella")), "KLE")
|
||||
expect_equal(as.character(as.mo("coagulase negative")), "STACNS")
|
||||
|
||||
expect_equal(as.character(as.mo("P. aer")), "PSEAER") # not Pasteurella aerogenes
|
||||
|
||||
expect_equal(as.character(as.mo("Negative rods")), "GNR")
|
||||
expect_equal(as.character(as.mo("Gram negative rods")), "GNR")
|
||||
|
||||
# GLIMS
|
||||
expect_equal(as.character(as.mo("shiboy")), "SHIBOY")
|
||||
|
||||
expect_equal(as.character(as.mo("MRSE")), "STAEPI")
|
||||
expect_equal(as.character(as.mo("VRE")), "ENC")
|
||||
expect_equal(as.character(as.mo("MRPA")), "PSEAER")
|
||||
expect_equal(as.character(as.mo("PISP")), "STCPNE")
|
||||
expect_equal(as.character(as.mo("PRSP")), "STCPNE")
|
||||
expect_equal(as.character(as.mo("VISP")), "STCPNE")
|
||||
expect_equal(as.character(as.mo("VRSP")), "STCPNE")
|
||||
|
||||
expect_identical(
|
||||
as.character(
|
||||
as.mo(c("stau",
|
||||
"STAU",
|
||||
"staaur",
|
||||
"S. aureus",
|
||||
"S aureus",
|
||||
"Staphylococcus aureus",
|
||||
"MRSA",
|
||||
"VISA"))),
|
||||
rep("STAAUR", 8))
|
||||
|
||||
# check for Becker classification
|
||||
expect_identical(as.character(guess_mo("S. epidermidis", Becker = FALSE)), "STAEPI")
|
||||
expect_identical(as.character(guess_mo("S. epidermidis", Becker = TRUE)), "STACNS")
|
||||
expect_identical(as.character(guess_mo("STAEPI", Becker = TRUE)), "STACNS")
|
||||
expect_identical(as.character(guess_mo("S. intermedius", Becker = FALSE)), "STAINT")
|
||||
expect_identical(as.character(guess_mo("S. intermedius", Becker = TRUE)), "STACPS")
|
||||
expect_identical(as.character(guess_mo("STAINT", Becker = TRUE)), "STACPS")
|
||||
# aureus must only be influenced if Becker = "all"
|
||||
expect_identical(as.character(guess_mo("STAAUR", Becker = FALSE)), "STAAUR")
|
||||
expect_identical(as.character(guess_mo("STAAUR", Becker = TRUE)), "STAAUR")
|
||||
expect_identical(as.character(guess_mo("STAAUR", Becker = "all")), "STACPS")
|
||||
|
||||
# check for Lancefield classification
|
||||
expect_identical(as.character(guess_mo("S. pyogenes", Lancefield = FALSE)), "STCPYO")
|
||||
expect_identical(as.character(guess_mo("S. pyogenes", Lancefield = TRUE)), "STCGRA")
|
||||
expect_identical(as.character(guess_mo("STCPYO", Lancefield = TRUE)), "STCGRA")
|
||||
expect_identical(as.character(guess_mo("S. agalactiae", Lancefield = FALSE)), "STCAGA")
|
||||
expect_identical(as.character(guess_mo("S. agalactiae", Lancefield = TRUE)), "STCGRB") # group B
|
||||
expect_identical(as.character(guess_mo("S. equisimilis", Lancefield = FALSE)), "STCEQS")
|
||||
expect_identical(as.character(guess_mo("S. equisimilis", Lancefield = TRUE)), "STCGRC") # group C
|
||||
expect_identical(as.character(guess_mo("S. anginosus", Lancefield = FALSE)), "STCANG")
|
||||
expect_identical(as.character(guess_mo("S. anginosus", Lancefield = TRUE)), "STCGRF") # group F
|
||||
expect_identical(as.character(guess_mo("S. sanguis", Lancefield = FALSE)), "STCSAN")
|
||||
expect_identical(as.character(guess_mo("S. sanguis", Lancefield = TRUE)), "STCGRH") # group H
|
||||
expect_identical(as.character(guess_mo("S. salivarius", Lancefield = FALSE)), "STCSAL")
|
||||
expect_identical(as.character(guess_mo("S. salivarius", Lancefield = TRUE)), "STCGRK") # group K
|
||||
|
||||
library(dplyr)
|
||||
|
||||
# select with one column
|
||||
expect_identical(
|
||||
septic_patients[1:10,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus) %>%
|
||||
as.mo() %>%
|
||||
as.character(),
|
||||
c("ESC", "ESC", "STA", "STA", "STA",
|
||||
"STA", "STA", "STA", "STA", "STA"))
|
||||
|
||||
# select with two columns
|
||||
expect_identical(
|
||||
septic_patients[1:10,] %>%
|
||||
pull(mo),
|
||||
septic_patients[1:10,] %>%
|
||||
left_join_microorganisms() %>%
|
||||
select(genus, species) %>%
|
||||
as.mo() %>%
|
||||
as.character())
|
||||
|
||||
# unknown results
|
||||
expect_warning(as.mo(c("INVALID", "Yeah, unknown")))
|
||||
|
||||
# too many columns
|
||||
expect_error(septic_patients %>% select(1:3) %>% as.mo())
|
||||
|
||||
# print
|
||||
expect_output(print(as.mo(c("ESCCOL", NA))))
|
||||
|
||||
# helper function
|
||||
expect_identical(as.mo("ESCCOL"),
|
||||
guess_mo("ESCCOL"))
|
||||
|
||||
# test pull
|
||||
expect_equal(nrow(septic_patients %>% mutate(mo = as.mo(mo))),
|
||||
2000)
|
||||
|
||||
# test data.frame
|
||||
expect_equal(nrow(data.frame(test = as.mo("ESCCOL"))),
|
||||
1)
|
||||
|
||||
# check empty values
|
||||
expect_equal(as.character(suppressWarnings(as.mo(""))),
|
||||
NA_character_)
|
||||
|
||||
})
|
@ -122,7 +122,7 @@ test_that("old rsi works", {
|
||||
|
||||
test_that("prediction of rsi works", {
|
||||
amox_R <- septic_patients %>%
|
||||
filter(bactid == "ESCCOL") %>%
|
||||
filter(mo == "ESCCOL") %>%
|
||||
rsi_predict(col_ab = "amox",
|
||||
col_date = "date",
|
||||
minimum = 10,
|
||||
@ -131,37 +131,37 @@ test_that("prediction of rsi works", {
|
||||
# amox resistance will increase according to data set `septic_patients`
|
||||
expect_true(amox_R[3] < amox_R[20])
|
||||
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
|
||||
model = "binomial",
|
||||
col_ab = "amox",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
|
||||
model = "loglin",
|
||||
col_ab = "amox",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
|
||||
model = "lin",
|
||||
col_ab = "amox",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
|
||||
model = "INVALID MODEL",
|
||||
col_ab = "amox",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
|
||||
col_ab = "NOT EXISTING COLUMN",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
|
||||
col_ab = "amox",
|
||||
col_date = "NOT EXISTING COLUMN",
|
||||
info = TRUE))
|
||||
# almost all E. coli are mero S in the Netherlands :)
|
||||
expect_error(resistance_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
|
||||
expect_error(resistance_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
|
||||
col_ab = "mero",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
|
Reference in New Issue
Block a user