1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 22:41:52 +02:00

(v1.1.0.9004) lose dependencies

This commit is contained in:
2020-05-16 13:05:47 +02:00
parent 9fce546901
commit 7f3da74b17
111 changed files with 3211 additions and 2345 deletions

View File

@ -37,34 +37,23 @@ test_that("first isolates work", {
1317)
# first weighted isolates
ex_iso_with_keyab <- example_isolates
ex_iso_with_keyab$keyab <- key_antibiotics(example_isolates, warnings = FALSE)
expect_equal(
suppressWarnings(
sum(
first_isolate(x = example_isolates %>% mutate(keyab = key_antibiotics(.)),
first_isolate(x = ex_iso_with_keyab,
# let syntax determine arguments automatically
type = "keyantibiotics",
info = TRUE),
na.rm = TRUE)),
1413)
# should be same for tibbles
expect_equal(
suppressWarnings(
sum(
first_isolate(x = example_isolates %>% dplyr::as_tibble() %>% mutate(keyab = key_antibiotics(.)),
# let syntax determine these automatically:
# col_date = "date",
# col_patient_id = "patient_id",
# col_mo = "mo",
# col_keyantibiotics = "keyab",
type = "keyantibiotics",
info = TRUE),
na.rm = TRUE)),
1413)
# when not ignoring I
expect_equal(
suppressWarnings(
sum(
first_isolate(x = example_isolates %>% mutate(keyab = key_antibiotics(.)),
first_isolate(x = ex_iso_with_keyab,
col_date = "date",
col_patient_id = "patient_id",
col_mo = "mo",
@ -78,7 +67,7 @@ test_that("first isolates work", {
expect_equal(
suppressWarnings(
sum(
first_isolate(x = example_isolates %>% mutate(keyab = key_antibiotics(.)),
first_isolate(x = ex_iso_with_keyab,
col_date = "date",
col_patient_id = "patient_id",
col_mo = "mo",
@ -99,16 +88,16 @@ test_that("first isolates work", {
info = TRUE,
icu_exclude = TRUE),
na.rm = TRUE),
906)
891)
# set 1500 random observations to be of specimen type 'Urine'
random_rows <- sample(x = 1:2000, size = 1500, replace = FALSE)
x <- example_isolates
x$specimen <- "Other"
x[random_rows, "specimen"] <- "Urine"
expect_lt(
sum(
first_isolate(x = mutate(example_isolates,
specimen = if_else(row_number() %in% random_rows,
"Urine",
"Other")),
first_isolate(x = x,
col_date = "date",
col_patient_id = "patient_id",
col_mo = "mo",
@ -120,10 +109,7 @@ test_that("first isolates work", {
# same, but now exclude ICU
expect_lt(
sum(
first_isolate(x = mutate(example_isolates,
specimen = if_else(row_number() %in% random_rows,
"Urine",
"Other")),
first_isolate(x = x,
col_date = "date",
col_patient_id = "patient_id",
col_mo = "mo",
@ -136,17 +122,19 @@ test_that("first isolates work", {
1501)
# "No isolates found"
expect_message(example_isolates %>%
mutate(specimen = "test") %>%
mutate(first = first_isolate(., "date", "patient_id",
col_mo = "mo",
col_specimen = "specimen",
filter_specimen = "something_unexisting",
info = TRUE)))
test_iso <- example_isolates
test_iso$specimen <- "test"
expect_message(first_isolate(test_iso,
"date",
"patient_id",
col_mo = "mo",
col_specimen = "specimen",
filter_specimen = "something_unexisting",
info = TRUE))
# printing of exclusion message
expect_message(example_isolates %>%
first_isolate(col_date = "date",
expect_message(first_isolate(example_isolates,
col_date = "date",
col_mo = "mo",
col_patient_id = "patient_id",
col_testcode = "gender",
@ -190,23 +178,15 @@ test_that("first isolates work", {
1322)
# unknown MOs
expect_equal(example_isolates %>%
mutate(mo = ifelse(mo == "B_ESCHR_COLI", "UNKNOWN", mo)) %>%
mutate(first = first_isolate(., include_unknown = FALSE)) %>%
.$first %>%
sum(),
test_unknown <- example_isolates
test_unknown$mo <- ifelse(test_unknown$mo == "B_ESCHR_COLI", "UNKNOWN", test_unknown$mo)
expect_equal(sum(first_isolate(test_unknown, include_unknown = FALSE)),
1062)
expect_equal(example_isolates %>%
mutate(mo = ifelse(mo == "B_ESCHR_COLI", "UNKNOWN", mo)) %>%
mutate(first = first_isolate(., include_unknown = TRUE)) %>%
.$first %>%
sum(),
expect_equal(sum(first_isolate(test_unknown, include_unknown = TRUE)),
1529)
expect_equal(example_isolates %>%
mutate(mo = ifelse(mo == "B_ESCHR_COLI", NA, mo)) %>%
mutate(first = first_isolate(.)) %>%
.$first %>%
sum(),
test_unknown$mo <- ifelse(test_unknown$mo == "UNKNOWN", NA, test_unknown$mo)
expect_equal(sum(first_isolate(test_unknown)),
1062)
})