2018-07-23 14:14:03 +02:00
|
|
|
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("P. aer")), "PSEAER") # not Pasteurella aerogenes
|
|
|
|
|
|
|
|
expect_equal(as.character(as.bactid("Negative rods")), "GNR")
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
# select with one column
|
|
|
|
expect_identical(
|
|
|
|
septic_patients[1:10,] %>%
|
|
|
|
left_join_microorganisms() %>%
|
|
|
|
select(genus) %>%
|
|
|
|
as.bactid() %>%
|
|
|
|
as.character(),
|
2018-07-25 14:17:04 +02:00
|
|
|
c("ESC", "ESC", "STA", "STA", "STA",
|
|
|
|
"STA", "STA", "STA", "STA", "STA"))
|
2018-07-23 14:14:03 +02:00
|
|
|
|
|
|
|
# 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")))
|
|
|
|
|
|
|
|
# print
|
|
|
|
expect_output(print(as.bactid(c("ESCCOL", NA))))
|
|
|
|
|
|
|
|
# helper function
|
|
|
|
expect_identical(as.bactid("ESCCOL"),
|
|
|
|
guess_bactid("ESCCOL"))
|
|
|
|
|
2018-07-29 22:14:51 +02:00
|
|
|
# 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)
|
2018-07-23 14:14:03 +02:00
|
|
|
|
2018-07-30 00:14:06 +02:00
|
|
|
# check empty values
|
|
|
|
expect_equal(as.character(suppressWarnings(as.bactid(""))),
|
|
|
|
NA_character_)
|
|
|
|
|
2018-07-23 14:14:03 +02:00
|
|
|
})
|