mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 14:01:55 +02:00
(v1.1.0.9004) lose dependencies
This commit is contained in:
@ -54,7 +54,7 @@ test_that("counts work", {
|
||||
combination = count_susceptible(CIP, GEN)) %>%
|
||||
pull(combination),
|
||||
c(253, 465, 192, 558))
|
||||
|
||||
|
||||
# count_df
|
||||
expect_equal(
|
||||
example_isolates %>% select(AMX) %>% count_df() %>% pull(value),
|
||||
|
@ -51,17 +51,17 @@ test_that("data sets are valid", {
|
||||
})
|
||||
|
||||
test_that("creation of data sets is valid", {
|
||||
DT <- make_DT()
|
||||
expect_lt(nrow(DT[prevalence == 1]), nrow(DT[prevalence == 2]))
|
||||
expect_lt(nrow(DT[prevalence == 2]), nrow(DT[prevalence == 3]))
|
||||
df <- create_MO_lookup()
|
||||
expect_lt(nrow(df[which(df$prevalence == 1), ]), nrow(df[which(df$prevalence == 2), ]))
|
||||
expect_lt(nrow(df[which(df$prevalence == 2), ]), nrow(df[which(df$prevalence == 3), ]))
|
||||
expect_true(all(c("mo", "fullname",
|
||||
"kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies",
|
||||
"rank", "col_id", "species_id", "source", "ref", "prevalence",
|
||||
"kingdom_index", "fullname_lower", "g_species") %in% colnames(DT)))
|
||||
"kingdom_index", "fullname_lower", "g_species") %in% colnames(df)))
|
||||
|
||||
oldDT <- make_oldDT()
|
||||
olddf <- create_MO.old_lookup()
|
||||
expect_true(all(c("col_id", "col_id_new", "fullname", "ref", "prevalence",
|
||||
"fullname_lower", "g_species") %in% colnames(oldDT)))
|
||||
"fullname_lower", "g_species") %in% colnames(olddf)))
|
||||
|
||||
old <- make_trans_tbl()
|
||||
expect_gt(length(old), 0)
|
||||
|
@ -22,9 +22,6 @@
|
||||
context("deprecated.R")
|
||||
|
||||
test_that("deprecated functions work", {
|
||||
expect_identical(suppressWarnings(p.symbol(seq(0, 1, 0.001))),
|
||||
p_symbol(seq(0, 1, 0.001)))
|
||||
|
||||
expect_equal(suppressWarnings(portion_S(example_isolates$AMX)), proportion_S(example_isolates$AMX))
|
||||
expect_equal(suppressWarnings(portion_SI(example_isolates$AMX)), proportion_SI(example_isolates$AMX))
|
||||
expect_equal(suppressWarnings(portion_I(example_isolates$AMX)), proportion_I(example_isolates$AMX))
|
||||
|
@ -24,24 +24,24 @@ context("eucast_rules.R")
|
||||
test_that("EUCAST rules work", {
|
||||
|
||||
skip_on_cran()
|
||||
|
||||
|
||||
# thoroughly check input table
|
||||
expect_equal(colnames(eucast_rules_file),
|
||||
c("if_mo_property", "like.is.one_of", "this_value",
|
||||
"and_these_antibiotics", "have_these_values",
|
||||
"then_change_these_antibiotics", "to_value",
|
||||
"reference.rule", "reference.rule_group"))
|
||||
|
||||
|
||||
expect_error(suppressWarnings(eucast_rules(example_isolates, col_mo = "Non-existing")))
|
||||
expect_error(eucast_rules(x = "text"))
|
||||
expect_error(eucast_rules(data.frame(a = "test")))
|
||||
expect_error(eucast_rules(data.frame(mo = "test"), rules = "invalid rules set"))
|
||||
|
||||
expect_warning(eucast_rules(data.frame(mo = "Escherichia coli", vancomycin = "S", stringsAsFactors = TRUE)))
|
||||
|
||||
|
||||
expect_identical(colnames(example_isolates),
|
||||
colnames(suppressWarnings(eucast_rules(example_isolates))))
|
||||
|
||||
|
||||
a <- data.frame(mo = c("Klebsiella pneumoniae",
|
||||
"Pseudomonas aeruginosa",
|
||||
"Enterobacter aerogenes"),
|
||||
@ -54,7 +54,7 @@ test_that("EUCAST rules work", {
|
||||
stringsAsFactors = FALSE)
|
||||
expect_identical(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
|
||||
expect_identical(suppressWarnings(eucast_rules(a, "mo", info = TRUE)), b)
|
||||
|
||||
|
||||
a <- data.frame(mo = c("Staphylococcus aureus",
|
||||
"Streptococcus group A"),
|
||||
COL = "-", # Colistin
|
||||
@ -64,7 +64,7 @@ test_that("EUCAST rules work", {
|
||||
COL = "R", # Colistin
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
|
||||
|
||||
|
||||
# piperacillin must be R in Enterobacteriaceae when tica is R
|
||||
library(dplyr)
|
||||
expect_equal(suppressWarnings(
|
||||
@ -78,25 +78,17 @@ test_that("EUCAST rules work", {
|
||||
unique() %>%
|
||||
as.character()),
|
||||
"R")
|
||||
|
||||
|
||||
# Azithromicin and Clarythromycin must be equal to Erythromycin
|
||||
a <- suppressWarnings(
|
||||
example_isolates %>%
|
||||
transmute(mo,
|
||||
ERY,
|
||||
AZM = as.rsi("R"),
|
||||
CLR = as.rsi("R")) %>%
|
||||
eucast_rules(col_mo = "mo") %>%
|
||||
pull(CLR))
|
||||
b <- suppressWarnings(
|
||||
example_isolates %>%
|
||||
select(mo, ERY) %>%
|
||||
eucast_rules(col_mo = "mo") %>%
|
||||
pull(ERY))
|
||||
|
||||
a <- eucast_rules(data.frame(mo = example_isolates$mo,
|
||||
ERY = example_isolates$ERY,
|
||||
AZM = as.rsi("R"),
|
||||
CLR = as.rsi("R"),
|
||||
stringsAsFactors = FALSE))$CLR
|
||||
b <- example_isolates$ERY
|
||||
expect_identical(a[!is.na(b)],
|
||||
b[!is.na(b)])
|
||||
|
||||
|
||||
# amox is inferred by benzylpenicillin in Kingella kingae
|
||||
expect_equal(
|
||||
suppressWarnings(
|
||||
@ -108,11 +100,11 @@ test_that("EUCAST rules work", {
|
||||
, info = FALSE))$AMX
|
||||
),
|
||||
"S")
|
||||
|
||||
|
||||
# also test norf
|
||||
expect_output(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE)))
|
||||
|
||||
|
||||
# check verbose output
|
||||
expect_output(suppressWarnings(eucast_rules(example_isolates, verbose = TRUE, info = TRUE)))
|
||||
|
||||
|
||||
})
|
||||
|
@ -22,7 +22,8 @@
|
||||
context("filter_ab_class.R")
|
||||
|
||||
test_that("ATC-group filtering works", {
|
||||
library(dplyr)
|
||||
skip_on_cran()
|
||||
|
||||
expect_gt(example_isolates %>% filter_ab_class("carbapenem") %>% nrow(), 0)
|
||||
expect_gt(example_isolates %>% filter_aminoglycosides() %>% nrow(), 0)
|
||||
expect_gt(example_isolates %>% filter_carbapenems() %>% nrow(), 0)
|
||||
@ -40,5 +41,5 @@ test_that("ATC-group filtering works", {
|
||||
|
||||
expect_error(example_isolates %>% filter_carbapenems(result = "test"))
|
||||
expect_error(example_isolates %>% filter_carbapenems(scope = "test"))
|
||||
expect_warning(example_isolates %>% select(1:3) %>% filter_carbapenems())
|
||||
expect_message(example_isolates %>% select(1:3) %>% filter_carbapenems())
|
||||
})
|
||||
|
@ -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)
|
||||
|
||||
})
|
||||
|
@ -25,8 +25,6 @@ test_that("mdro works", {
|
||||
|
||||
skip_on_cran()
|
||||
|
||||
library(dplyr)
|
||||
|
||||
expect_error(suppressWarnings(mdro(example_isolates, country = "invalid", col_mo = "mo", info = TRUE)))
|
||||
expect_error(suppressWarnings(mdro(example_isolates, country = "fr", info = TRUE)))
|
||||
expect_error(mdro(example_isolates, guideline = c("BRMO", "MRGN"), info = TRUE))
|
||||
@ -100,7 +98,7 @@ test_that("mdro works", {
|
||||
expect_equal(
|
||||
# select only rifampicine, mo will be determined automatically (as M. tuberculosis),
|
||||
# number of mono-resistant strains should be equal to number of rifampicine-resistant strains
|
||||
example_isolates %>% select(RIF) %>% mdr_tb() %>% freq() %>% pull(count) %>% .[2],
|
||||
freq(mdr_tb(example_isolates[, "RIF", drop = FALSE]))$count[2],
|
||||
count_R(example_isolates$RIF))
|
||||
|
||||
sample_rsi <- function() {
|
||||
@ -109,69 +107,113 @@ test_that("mdro works", {
|
||||
prob = c(0.5, 0.1, 0.4),
|
||||
replace = TRUE)
|
||||
}
|
||||
expect_gt(
|
||||
#suppressWarnings(
|
||||
data.frame(rifampicin = sample_rsi(),
|
||||
inh = sample_rsi(),
|
||||
gatifloxacin = sample_rsi(),
|
||||
eth = sample_rsi(),
|
||||
pza = sample_rsi(),
|
||||
MFX = sample_rsi(),
|
||||
KAN = sample_rsi()) %>%
|
||||
mdr_tb() %>%
|
||||
n_distinct()
|
||||
#)
|
||||
,
|
||||
2)
|
||||
x <- data.frame(rifampicin = sample_rsi(),
|
||||
inh = sample_rsi(),
|
||||
gatifloxacin = sample_rsi(),
|
||||
eth = sample_rsi(),
|
||||
pza = sample_rsi(),
|
||||
MFX = sample_rsi(),
|
||||
KAN = sample_rsi())
|
||||
expect_gt(n_distinct(mdr_tb(x)), 2)
|
||||
|
||||
# check the guideline by Magiorakos et al. (2012), the default guideline
|
||||
stau <- tribble(
|
||||
~mo, ~GEN, ~RIF, ~CPT, ~OXA, ~CIP, ~MFX, ~SXT, ~FUS, ~VAN, ~TEC, ~TLV, ~TGC, ~CLI, ~DAP, ~ERY, ~LNZ, ~CHL, ~FOS, ~QDA, ~TCY, ~DOX, ~MNO,
|
||||
"S. aureus", "R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"S. aureus", "R", "R", "R", "R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"S. aureus", "S", "S", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R",
|
||||
"S. aureus", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R"
|
||||
)
|
||||
stau <- data.frame(mo = c("S. aureus", "S. aureus", "S. aureus", "S. aureus"),
|
||||
GEN = c("R", "R", "S", "R"),
|
||||
RIF = c("S", "R", "S", "R"),
|
||||
CPT = c("S", "R", "R", "R"),
|
||||
OXA = c("S", "R", "R", "R"),
|
||||
CIP = c("S", "S", "R", "R"),
|
||||
MFX = c("S", "S", "R", "R"),
|
||||
SXT = c("S", "S", "R", "R"),
|
||||
FUS = c("S", "S", "R", "R"),
|
||||
VAN = c("S", "S", "R", "R"),
|
||||
TEC = c("S", "S", "R", "R"),
|
||||
TLV = c("S", "S", "R", "R"),
|
||||
TGC = c("S", "S", "R", "R"),
|
||||
CLI = c("S", "S", "R", "R"),
|
||||
DAP = c("S", "S", "R", "R"),
|
||||
ERY = c("S", "S", "R", "R"),
|
||||
LNZ = c("S", "S", "R", "R"),
|
||||
CHL = c("S", "S", "R", "R"),
|
||||
FOS = c("S", "S", "R", "R"),
|
||||
QDA = c("S", "S", "R", "R"),
|
||||
TCY = c("S", "S", "R", "R"),
|
||||
DOX = c("S", "S", "R", "R"),
|
||||
MNO = c("S", "S", "R", "R"),
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(as.integer(mdro(stau)), c(1:4))
|
||||
expect_s3_class(mdro(stau, verbose = TRUE), "data.frame")
|
||||
|
||||
ente <- tribble(
|
||||
~mo, ~GEH, ~STH, ~IPM, ~MEM, ~DOR, ~CIP, ~LVX, ~MFX, ~VAN, ~TEC, ~TGC, ~DAP, ~LNZ, ~AMP, ~QDA, ~DOX, ~MNO,
|
||||
"Enterococcus", "R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"Enterococcus", "R", "R", "R", "R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"Enterococcus", "S", "S", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R",
|
||||
"Enterococcus", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R"
|
||||
)
|
||||
ente <- data.frame(mo = c("Enterococcus", "Enterococcus", "Enterococcus", "Enterococcus"),
|
||||
GEH = c("R", "R", "S", "R"),
|
||||
STH = c("S", "R", "S", "R"),
|
||||
IPM = c("S", "R", "R", "R"),
|
||||
MEM = c("S", "R", "R", "R"),
|
||||
DOR = c("S", "S", "R", "R"),
|
||||
CIP = c("S", "S", "R", "R"),
|
||||
LVX = c("S", "S", "R", "R"),
|
||||
MFX = c("S", "S", "R", "R"),
|
||||
VAN = c("S", "S", "R", "R"),
|
||||
TEC = c("S", "S", "R", "R"),
|
||||
TGC = c("S", "S", "R", "R"),
|
||||
DAP = c("S", "S", "R", "R"),
|
||||
LNZ = c("S", "S", "R", "R"),
|
||||
AMP = c("S", "S", "R", "R"),
|
||||
QDA = c("S", "S", "R", "R"),
|
||||
DOX = c("S", "S", "R", "R"),
|
||||
MNO = c("S", "S", "R", "R"),
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(as.integer(mdro(ente)), c(1:4))
|
||||
expect_s3_class(mdro(ente, verbose = TRUE), "data.frame")
|
||||
|
||||
entero <- tribble(
|
||||
~mo, ~GEN, ~TOB, ~AMK, ~NET, ~CPT, ~TCC, ~TZP, ~ETP, ~IPM, ~MEM, ~DOR, ~CZO, ~CXM, ~CTX, ~CAZ, ~FEP, ~FOX, ~CTT, ~CIP, ~SXT, ~TGC, ~ATM, ~AMP, ~AMC, ~SAM, ~CHL, ~FOS, ~COL, ~TCY, ~DOX, ~MNO,
|
||||
"E. coli", "R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"E. coli", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"E. coli", "S", "S", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R",
|
||||
"E. coli", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R"
|
||||
)
|
||||
entero <- data.frame(mo = c("E. coli", "E. coli", "E. coli", "E. coli"),
|
||||
GEN = c("R", "R", "S", "R"), TOB = c("S", "R", "S", "R"),
|
||||
AMK = c("S", "R", "R", "R"), NET = c("S", "R", "R", "R"),
|
||||
CPT = c("S", "R", "R", "R"), TCC = c("S", "R", "R", "R"),
|
||||
TZP = c("S", "S", "R", "R"), ETP = c("S", "S", "R", "R"),
|
||||
IPM = c("S", "S", "R", "R"), MEM = c("S", "S", "R", "R"),
|
||||
DOR = c("S", "S", "R", "R"), CZO = c("S", "S", "R", "R"),
|
||||
CXM = c("S", "S", "R", "R"), CTX = c("S", "S", "R", "R"),
|
||||
CAZ = c("S", "S", "R", "R"), FEP = c("S", "S", "R", "R"),
|
||||
FOX = c("S", "S", "R", "R"), CTT = c("S", "S", "R", "R"),
|
||||
CIP = c("S", "S", "R", "R"), SXT = c("S", "S", "R", "R"),
|
||||
TGC = c("S", "S", "R", "R"), ATM = c("S", "S", "R", "R"),
|
||||
AMP = c("S", "S", "R", "R"), AMC = c("S", "S", "R", "R"),
|
||||
SAM = c("S", "S", "R", "R"), CHL = c("S", "S", "R", "R"),
|
||||
FOS = c("S", "S", "R", "R"), COL = c("S", "S", "R", "R"),
|
||||
TCY = c("S", "S", "R", "R"), DOX = c("S", "S", "R", "R"),
|
||||
MNO = c("S", "S", "R", "R"),
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(as.integer(mdro(entero)), c(1:4))
|
||||
expect_s3_class(mdro(entero, verbose = TRUE), "data.frame")
|
||||
|
||||
pseud <- tribble(
|
||||
~mo, ~GEN, ~TOB, ~AMK, ~NET, ~IPM, ~MEM, ~DOR, ~CAZ, ~FEP, ~CIP, ~LVX, ~TCC, ~TZP, ~ATM, ~FOS, ~COL, ~PLB,
|
||||
"P. aeruginosa", "R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"P. aeruginosa", "R", "S", "S", "S", "R", "S", "S", "S", "R", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"P. aeruginosa", "S", "S", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R",
|
||||
"P. aeruginosa", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R"
|
||||
)
|
||||
pseud <- data.frame(mo = c("P. aeruginosa", "P. aeruginosa", "P. aeruginosa", "P. aeruginosa"),
|
||||
GEN = c("R", "R", "S", "R"), TOB = c("S", "S", "S", "R"),
|
||||
AMK = c("S", "S", "R", "R"), NET = c("S", "S", "R", "R"),
|
||||
IPM = c("S", "R", "R", "R"), MEM = c("S", "S", "R", "R"),
|
||||
DOR = c("S", "S", "R", "R"), CAZ = c("S", "S", "R", "R"),
|
||||
FEP = c("S", "R", "R", "R"), CIP = c("S", "S", "R", "R"),
|
||||
LVX = c("S", "S", "R", "R"), TCC = c("S", "S", "R", "R"),
|
||||
TZP = c("S", "S", "R", "R"), ATM = c("S", "S", "R", "R"),
|
||||
FOS = c("S", "S", "R", "R"), COL = c("S", "S", "R", "R"),
|
||||
PLB = c("S", "S", "R", "R"),
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(as.integer(mdro(pseud)), c(1:4))
|
||||
expect_s3_class(mdro(pseud, verbose = TRUE), "data.frame")
|
||||
|
||||
acin <- tribble(
|
||||
~mo, ~GEN, ~TOB, ~AMK, ~NET, ~IPM, ~MEM, ~DOR, ~CIP, ~LVX, ~TZP, ~TCC, ~CTX, ~CRO, ~CAZ, ~FEP, ~SXT, ~SAM, ~COL, ~PLB, ~TCY, ~DOX, ~MNO,
|
||||
"A. baumannii", "R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
|
||||
"A. baumannii", "R", "R", "R", "R", "S", "R", "S", "S", "S", "S", "S", "S", "S", "S", "R", "S", "S", "S", "S", "S", "S", "S",
|
||||
"A. baumannii", "S", "S", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R",
|
||||
"A. baumannii", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R", "R"
|
||||
)
|
||||
acin <- data.frame(mo = c("A. baumannii", "A. baumannii", "A. baumannii", "A. baumannii"),
|
||||
GEN = c("R", "R", "S", "R"), TOB = c("S", "R", "S", "R"),
|
||||
AMK = c("S", "R", "R", "R"), NET = c("S", "R", "R", "R"),
|
||||
IPM = c("S", "S", "R", "R"), MEM = c("S", "R", "R", "R"),
|
||||
DOR = c("S", "S", "R", "R"), CIP = c("S", "S", "R", "R"),
|
||||
LVX = c("S", "S", "R", "R"), TZP = c("S", "S", "R", "R"),
|
||||
TCC = c("S", "S", "R", "R"), CTX = c("S", "S", "R", "R"),
|
||||
CRO = c("S", "S", "R", "R"), CAZ = c("S", "S", "R", "R"),
|
||||
FEP = c("S", "R", "R", "R"), SXT = c("S", "S", "R", "R"),
|
||||
SAM = c("S", "S", "R", "R"), COL = c("S", "S", "R", "R"),
|
||||
PLB = c("S", "S", "R", "R"), TCY = c("S", "S", "R", "R"),
|
||||
DOX = c("S", "S", "R", "R"), MNO = c("S", "S", "R", "R"),
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(as.integer(mdro(acin)), c(1:4))
|
||||
expect_s3_class(mdro(acin, verbose = TRUE), "data.frame")
|
||||
|
||||
|
@ -25,7 +25,6 @@ test_that("as.mo works", {
|
||||
|
||||
skip_on_cran()
|
||||
|
||||
library(dplyr)
|
||||
MOs <- microorganisms %>% filter(!is.na(mo), nchar(mo) > 3)
|
||||
expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo)))
|
||||
|
||||
@ -64,7 +63,7 @@ test_that("as.mo works", {
|
||||
|
||||
expect_equal(as.character(as.mo("MRSE")), "B_STPHY_EPDR")
|
||||
expect_equal(as.character(as.mo("VRE")), "B_ENTRC")
|
||||
expect_equal(as.character(as.mo("MRPA")), "B_PSDMN_ARGN")
|
||||
expect_equal(as.character(as.mo("MRPA")), "B_PSDMN_AERG")
|
||||
expect_equal(as.character(as.mo("PISP")), "B_STRPT_PNMN")
|
||||
expect_equal(as.character(as.mo("PRSP")), "B_STRPT_PNMN")
|
||||
expect_equal(as.character(as.mo("VISP")), "B_STRPT_PNMN")
|
||||
|
@ -100,14 +100,12 @@ test_that("mo_property works", {
|
||||
expect_warning(mo_name(c("B_ESCHR_COL", "B_STPHY_AUR")))
|
||||
|
||||
# outcome of mo_fullname must always return the fullname from the data set
|
||||
library(dplyr)
|
||||
x <- microorganisms %>%
|
||||
transmute(mo,
|
||||
# fullname from the original data:
|
||||
f1 = fullname,
|
||||
# newly created fullname based on MO code:
|
||||
f2 = mo_fullname(mo, language = "en")) %>%
|
||||
filter(f1 != f2)
|
||||
expect_equal(nrow(x), 0)
|
||||
|
||||
x <- data.frame(mo = microorganisms$mo,
|
||||
# fullname from the original data:
|
||||
f1 = microorganisms$fullname,
|
||||
# newly created fullname based on MO code:
|
||||
f2 = mo_fullname(microorganisms$mo, language = "en"),
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(nrow(subset(x, f1 != f2)), 0)
|
||||
|
||||
})
|
||||
|
@ -22,13 +22,20 @@
|
||||
context("pca.R")
|
||||
|
||||
test_that("PCA works", {
|
||||
library(dplyr)
|
||||
resistance_data <- example_isolates %>%
|
||||
filter(mo %in% as.mo(c("E. coli", "K. pneumoniae", "S. aureus"))) %>%
|
||||
select(mo, AMC, CXM, CTX, TOB, TMP) %>%
|
||||
group_by(order = mo_order(mo), # group on anything, like order
|
||||
genus = mo_genus(mo)) %>% # and genus as we do here
|
||||
summarise_if(is.rsi, resistance, minimum = 0)
|
||||
resistance_data <- structure(list(order = c("Bacillales", "Enterobacterales", "Enterobacterales"),
|
||||
genus = c("Staphylococcus", "Escherichia", "Klebsiella"),
|
||||
AMC = c(0.00425, 0.13062, 0.10344),
|
||||
CXM = c(0.00425, 0.05376, 0.10344),
|
||||
CTX = c(0.00000, 0.02396, 0.05172),
|
||||
TOB = c(0.02325, 0.02597, 0.10344),
|
||||
TMP = c(0.08387, 0.39141, 0.18367)),
|
||||
class = c("grouped_df", "tbl_df", "tbl", "data.frame"),
|
||||
row.names = c(NA, -3L),
|
||||
groups = structure(list(order = c("Bacillales", "Enterobacterales"),
|
||||
.rows = list(1L, 2:3)),
|
||||
row.names = c(NA, -2L),
|
||||
class = c("tbl_df", "tbl", "data.frame"),
|
||||
.drop = TRUE))
|
||||
|
||||
pca_model <- pca(resistance_data)
|
||||
|
||||
|
Reference in New Issue
Block a user