2018-12-16 22:45:12 +01:00
|
|
|
# ==================================================================== #
|
|
|
|
# TITLE #
|
|
|
|
# Antimicrobial Resistance (AMR) Analysis #
|
|
|
|
# #
|
|
|
|
# AUTHORS #
|
|
|
|
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
|
|
|
# #
|
|
|
|
# LICENCE #
|
|
|
|
# This package is free software; you can redistribute it and/or modify #
|
|
|
|
# it under the terms of the GNU General Public License version 2.0, #
|
|
|
|
# as published by the Free Software Foundation. #
|
|
|
|
# #
|
|
|
|
# This R package is distributed in the hope that it will be useful, #
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
|
|
# GNU General Public License version 2.0 for more details. #
|
|
|
|
# ==================================================================== #
|
|
|
|
|
2018-08-23 00:40:36 +02:00
|
|
|
context("count.R")
|
|
|
|
|
|
|
|
test_that("counts work", {
|
|
|
|
# amox resistance in `septic_patients`
|
2018-10-17 17:32:34 +02:00
|
|
|
expect_equal(count_R(septic_patients$amox), 683)
|
2018-08-23 00:40:36 +02:00
|
|
|
expect_equal(count_I(septic_patients$amox), 3)
|
2018-10-17 17:32:34 +02:00
|
|
|
expect_equal(count_S(septic_patients$amox), 486)
|
2018-08-23 00:40:36 +02:00
|
|
|
expect_equal(count_R(septic_patients$amox) + count_I(septic_patients$amox),
|
|
|
|
count_IR(septic_patients$amox))
|
|
|
|
expect_equal(count_S(septic_patients$amox) + count_I(septic_patients$amox),
|
|
|
|
count_SI(septic_patients$amox))
|
|
|
|
|
2018-10-12 16:35:18 +02:00
|
|
|
library(dplyr)
|
2018-10-17 17:32:34 +02:00
|
|
|
expect_equal(septic_patients %>% count_S(amcl), 1291)
|
|
|
|
expect_equal(septic_patients %>% count_S(amcl, gent), 1609)
|
|
|
|
expect_equal(septic_patients %>% count_all(amcl, gent), 1747)
|
2018-10-12 16:35:18 +02:00
|
|
|
expect_identical(septic_patients %>% count_all(amcl, gent),
|
|
|
|
septic_patients %>% count_S(amcl, gent) +
|
|
|
|
septic_patients %>% count_IR(amcl, gent))
|
2018-08-23 00:40:36 +02:00
|
|
|
|
|
|
|
# count of cases
|
|
|
|
expect_equal(septic_patients %>%
|
|
|
|
group_by(hospital_id) %>%
|
|
|
|
summarise(cipro = count_S(cipr),
|
|
|
|
genta = count_S(gent),
|
|
|
|
combination = count_S(cipr, gent)) %>%
|
|
|
|
pull(combination),
|
2018-09-24 23:33:29 +02:00
|
|
|
c(192, 446, 184, 474))
|
2018-08-23 00:40:36 +02:00
|
|
|
|
2018-10-16 09:59:31 +02:00
|
|
|
# count_df
|
|
|
|
expect_equal(
|
|
|
|
septic_patients %>% select(amox) %>% count_df() %>% pull(Value),
|
|
|
|
c(septic_patients$amox %>% count_S(),
|
|
|
|
septic_patients$amox %>% count_I(),
|
|
|
|
septic_patients$amox %>% count_R())
|
|
|
|
)
|
|
|
|
expect_equal(
|
|
|
|
septic_patients %>% select(amox) %>% count_df(combine_IR = TRUE) %>% pull(Value),
|
|
|
|
c(septic_patients$amox %>% count_S(),
|
|
|
|
septic_patients$amox %>% count_IR())
|
|
|
|
)
|
2018-08-23 01:01:50 +02:00
|
|
|
|
2018-08-23 00:40:36 +02:00
|
|
|
# warning for speed loss
|
|
|
|
expect_warning(count_R(as.character(septic_patients$amcl)))
|
|
|
|
expect_warning(count_I(as.character(septic_patients$amcl)))
|
|
|
|
expect_warning(count_S(as.character(septic_patients$amcl,
|
|
|
|
septic_patients$gent)))
|
|
|
|
expect_warning(count_S(septic_patients$amcl,
|
|
|
|
as.character(septic_patients$gent)))
|
|
|
|
|
|
|
|
# check for errors
|
|
|
|
expect_error(count_IR("test", minimum = "test"))
|
|
|
|
expect_error(count_IR("test", as_percent = "test"))
|
|
|
|
expect_error(count_I("test", minimum = "test"))
|
|
|
|
expect_error(count_I("test", as_percent = "test"))
|
|
|
|
expect_error(count_S("test", minimum = "test"))
|
|
|
|
expect_error(count_S("test", as_percent = "test"))
|
|
|
|
|
2018-09-16 22:11:17 +02:00
|
|
|
expect_error(count_df(c("A", "B", "C")))
|
2018-09-17 21:51:21 +02:00
|
|
|
expect_error(count_df(septic_patients[,"date"]))
|
2018-09-16 22:11:17 +02:00
|
|
|
|
2018-08-23 00:40:36 +02:00
|
|
|
})
|