2018-12-16 22:45:12 +01:00
|
|
|
# ==================================================================== #
|
|
|
|
# TITLE #
|
|
|
|
# Antimicrobial Resistance (AMR) Analysis #
|
|
|
|
# #
|
2019-01-02 23:24:07 +01:00
|
|
|
# SOURCE #
|
2020-07-08 14:48:06 +02:00
|
|
|
# https://github.com/msberends/AMR #
|
2018-12-16 22:45:12 +01:00
|
|
|
# #
|
|
|
|
# LICENCE #
|
2020-01-05 17:22:09 +01:00
|
|
|
# (c) 2018-2020 Berends MS, Luz CF et al. #
|
2018-12-16 22:45:12 +01:00
|
|
|
# #
|
2019-01-02 23:24:07 +01:00
|
|
|
# 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. #
|
|
|
|
# #
|
2020-01-05 17:22:09 +01:00
|
|
|
# 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. #
|
2020-07-08 14:48:06 +02:00
|
|
|
# Visit our website for more info: https://msberends.github.io/AMR. #
|
2018-12-16 22:45:12 +01:00
|
|
|
# ==================================================================== #
|
|
|
|
|
2018-08-25 22:01:14 +02:00
|
|
|
context("rsi.R")
|
|
|
|
|
|
|
|
test_that("rsi works", {
|
2019-10-15 14:35:23 +02:00
|
|
|
|
|
|
|
skip_on_cran()
|
|
|
|
|
2018-08-25 22:01:14 +02:00
|
|
|
expect_true(as.rsi("S") < as.rsi("I"))
|
|
|
|
expect_true(as.rsi("I") < as.rsi("R"))
|
|
|
|
expect_true(is.rsi(as.rsi("S")))
|
|
|
|
|
|
|
|
# print plots, should not raise errors
|
|
|
|
barplot(as.rsi(c("S", "I", "R")))
|
|
|
|
plot(as.rsi(c("S", "I", "R")))
|
|
|
|
print(as.rsi(c("S", "I", "R")))
|
2020-02-21 13:13:34 +01:00
|
|
|
|
|
|
|
expect_equal(as.character(as.rsi(c(1:3))), c("S", "I", "R"))
|
2018-08-25 22:01:14 +02:00
|
|
|
|
|
|
|
expect_equal(suppressWarnings(as.logical(as.rsi("INVALID VALUE"))), NA)
|
2020-07-22 12:29:51 +02:00
|
|
|
|
|
|
|
expect_equal(summary(as.rsi(c("S", "R"))),
|
|
|
|
structure(c("Class" = "rsi",
|
|
|
|
"%R" = "50% (n=1)",
|
|
|
|
"%SI" = "50% (n=1)",
|
|
|
|
"- %S" = "50% (n=1)",
|
|
|
|
"- %I" = "0% (n=0)"), class = c("summaryDefault", "table")))
|
|
|
|
|
2019-08-27 16:45:42 +02:00
|
|
|
expect_identical(as.logical(lapply(example_isolates, is.rsi.eligible)),
|
|
|
|
rep(FALSE, length(example_isolates)))
|
2020-07-22 12:29:51 +02:00
|
|
|
|
2018-11-02 14:55:29 +01:00
|
|
|
library(dplyr)
|
|
|
|
# 40 rsi columns
|
2019-08-27 16:45:42 +02:00
|
|
|
expect_equal(example_isolates %>%
|
2019-05-10 16:44:59 +02:00
|
|
|
mutate_at(vars(PEN:RIF), as.character) %>%
|
2018-11-02 15:04:48 +01:00
|
|
|
lapply(is.rsi.eligible) %>%
|
|
|
|
as.logical() %>%
|
|
|
|
sum(),
|
|
|
|
40)
|
2020-02-21 13:13:34 +01:00
|
|
|
|
2020-02-21 16:05:19 +01:00
|
|
|
expect_output(print(tibble(ab = as.rsi("S"))))
|
2020-02-21 13:13:34 +01:00
|
|
|
|
|
|
|
expect_error(as.rsi.mic(as.mic(16)))
|
|
|
|
expect_error(as.rsi.disk(as.disk(16)))
|
|
|
|
|
|
|
|
expect_error(get_guideline("this one does not exist"))
|
2018-11-02 14:55:29 +01:00
|
|
|
|
2018-08-25 22:01:14 +02:00
|
|
|
})
|
2019-05-13 10:10:16 +02:00
|
|
|
|
2020-02-21 13:13:34 +01:00
|
|
|
|
2019-05-13 10:10:16 +02:00
|
|
|
test_that("mic2rsi works", {
|
2019-10-15 14:35:23 +02:00
|
|
|
|
|
|
|
skip_on_cran()
|
|
|
|
|
2019-05-13 10:10:16 +02:00
|
|
|
expect_equal(as.character(
|
|
|
|
as.rsi(x = as.mic(0.125),
|
2019-09-18 15:46:09 +02:00
|
|
|
mo = "B_STRPT_PNMN",
|
2019-05-13 10:10:16 +02:00
|
|
|
ab = "AMX",
|
|
|
|
guideline = "EUCAST")),
|
|
|
|
"S")
|
|
|
|
expect_equal(as.character(
|
|
|
|
as.rsi(x = as.mic(4),
|
2019-09-18 15:46:09 +02:00
|
|
|
mo = "B_STRPT_PNMN",
|
2019-05-13 10:10:16 +02:00
|
|
|
ab = "AMX",
|
|
|
|
guideline = "EUCAST")),
|
|
|
|
"R")
|
|
|
|
|
2019-08-27 16:45:42 +02:00
|
|
|
expect_true(example_isolates %>%
|
2019-05-13 10:10:16 +02:00
|
|
|
mutate(amox_mic = as.mic(2)) %>%
|
|
|
|
select(mo, amox_mic) %>%
|
|
|
|
as.rsi() %>%
|
|
|
|
pull(amox_mic) %>%
|
|
|
|
is.rsi())
|
2020-02-20 13:19:23 +01:00
|
|
|
|
|
|
|
expect_warning(data.frame(mo = "E. coli",
|
|
|
|
NIT = c("<= 2", 32)) %>%
|
|
|
|
as.rsi())
|
|
|
|
expect_message(data.frame(mo = "E. coli",
|
|
|
|
NIT = c("<= 2", 32),
|
|
|
|
uti = TRUE) %>%
|
|
|
|
as.rsi())
|
|
|
|
expect_message(
|
|
|
|
data.frame(mo = "E. coli",
|
|
|
|
NIT = c("<= 2", 32),
|
|
|
|
specimen = c("urine", "blood")) %>%
|
|
|
|
as.rsi())
|
2019-05-13 10:10:16 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
test_that("disk2rsi works", {
|
2019-10-15 14:35:23 +02:00
|
|
|
|
|
|
|
skip_on_cran()
|
|
|
|
|
2019-05-13 10:10:16 +02:00
|
|
|
expect_equal(as.character(
|
|
|
|
as.rsi(x = as.disk(22),
|
2019-09-18 15:46:09 +02:00
|
|
|
mo = "B_STRPT_PNMN",
|
2019-05-13 10:10:16 +02:00
|
|
|
ab = "ERY",
|
|
|
|
guideline = "CLSI")),
|
|
|
|
"S")
|
|
|
|
expect_equal(as.character(
|
|
|
|
as.rsi(x = as.disk(18),
|
2019-09-18 15:46:09 +02:00
|
|
|
mo = "B_STRPT_PNMN",
|
2019-05-13 10:10:16 +02:00
|
|
|
ab = "ERY",
|
|
|
|
guideline = "CLSI")),
|
|
|
|
"I")
|
|
|
|
expect_equal(as.character(
|
|
|
|
as.rsi(x = as.disk(10),
|
2019-09-18 15:46:09 +02:00
|
|
|
mo = "B_STRPT_PNMN",
|
2019-05-13 10:10:16 +02:00
|
|
|
ab = "ERY",
|
|
|
|
guideline = "CLSI")),
|
|
|
|
"R")
|
|
|
|
|
2019-08-27 16:45:42 +02:00
|
|
|
expect_true(example_isolates %>%
|
2019-05-13 10:10:16 +02:00
|
|
|
mutate(amox_disk = as.disk(15)) %>%
|
|
|
|
select(mo, amox_disk) %>%
|
|
|
|
as.rsi(guideline = "CLSI") %>%
|
|
|
|
pull(amox_disk) %>%
|
|
|
|
is.rsi())
|
|
|
|
})
|