1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 05:26:13 +01:00

(v0.7.1.9084) CI fix

This commit is contained in:
dr. M.S. (Matthijs) Berends 2019-09-23 20:55:54 +02:00
parent 8ce252fbc5
commit 76dc948067
12 changed files with 61 additions and 64 deletions

View File

@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 0.7.1.9083 Version: 0.7.1.9084
Date: 2019-09-23 Date: 2019-09-23
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(

View File

@ -1,4 +1,4 @@
# AMR 0.7.1.9083 # AMR 0.7.1.9084
<small>Last updated: 23-Sep-2019</small> <small>Last updated: 23-Sep-2019</small>
### Breaking ### Breaking

View File

@ -53,6 +53,7 @@ globalVariables(c(".",
"mdr", "mdr",
"median", "median",
"microorganisms", "microorganisms",
"microorganisms.codes",
"missing_names", "missing_names",
"mo", "mo",
"mono_count", "mono_count",

9
R/mo.R
View File

@ -652,9 +652,9 @@ exec_as.mo <- function(x,
if (!is.null(reference_df)) { if (!is.null(reference_df)) {
# self-defined reference # self-defined reference
if (x_backup[i] %in% reference_df[, 1]) { if (x_backup[i] %in% reference_df[, 1]) {
ref_mo <- reference_df[reference_df[, 1] == x_backup[i], "mo"] ref_mo <- reference_df[reference_df[, 1] == x_backup[i], "mo"][[1L]]
if (ref_mo %in% data_to_check[, mo]) { if (ref_mo %in% microorganismsDT[, mo]) {
x[i] <- data_to_check[mo == ref_mo, ..property][[1]][1L] x[i] <- microorganismsDT[mo == ref_mo, ..property][[1]][1L]
next next
} else { } else {
warning("Value '", x_backup[i], "' was found in reference_df, but '", ref_mo, "' is not a valid MO code.", call. = FALSE) warning("Value '", x_backup[i], "' was found in reference_df, but '", ref_mo, "' is not a valid MO code.", call. = FALSE)
@ -769,8 +769,7 @@ exec_as.mo <- function(x,
} }
next next
} }
if (toupper(x_backup_without_spp[i]) == 'CRS' if (toupper(x_backup_without_spp[i]) == 'CRSM') {
| toupper(x_backup_without_spp[i]) == 'CRSM') {
# co-trim resistant S. maltophilia # co-trim resistant S. maltophilia
x[i] <- microorganismsDT[mo == 'B_STNTR_MLTP', ..property][[1]][1L] x[i] <- microorganismsDT[mo == 'B_STNTR_MLTP', ..property][[1]][1L]
if (initial_search == TRUE) { if (initial_search == TRUE) {

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9084</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9084</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9084</span>
</span> </span>
</div> </div>

View File

@ -42,7 +42,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9084</span>
</span> </span>
</div> </div>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9084</span>
</span> </span>
</div> </div>
@ -225,9 +225,9 @@
</div> </div>
<div id="amr-0-7-1-9083" class="section level1"> <div id="amr-0-7-1-9084" class="section level1">
<h1 class="page-header"> <h1 class="page-header">
<a href="#amr-0-7-1-9083" class="anchor"></a>AMR 0.7.1.9083<small> Unreleased </small> <a href="#amr-0-7-1-9084" class="anchor"></a>AMR 0.7.1.9084<small> Unreleased </small>
</h1> </h1>
<p><small>Last updated: 23-Sep-2019</small></p> <p><small>Last updated: 23-Sep-2019</small></p>
<div id="breaking" class="section level3"> <div id="breaking" class="section level3">
@ -1280,7 +1280,7 @@ Using <code><a href="../reference/as.mo.html">as.mo(..., allow_uncertain = 3)</a
<div id="tocnav"> <div id="tocnav">
<h2>Contents</h2> <h2>Contents</h2>
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
<li><a href="#amr-0-7-1-9083">0.7.1.9083</a></li> <li><a href="#amr-0-7-1-9084">0.7.1.9084</a></li>
<li><a href="#amr-0-7-1">0.7.1</a></li> <li><a href="#amr-0-7-1">0.7.1</a></li>
<li><a href="#amr-0-7-0">0.7.0</a></li> <li><a href="#amr-0-7-0">0.7.0</a></li>
<li><a href="#amr-0-6-1">0.6.1</a></li> <li><a href="#amr-0-6-1">0.6.1</a></li>

View File

@ -78,7 +78,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9083</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">0.7.1.9084</span>
</span> </span>
</div> </div>

View File

@ -24,15 +24,15 @@ context("mo.R")
test_that("as.mo works", { test_that("as.mo works", {
clear_mo_history(force = TRUE) clear_mo_history(force = TRUE)
library(dplyr) library(dplyr)
MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3) MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3)
expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo))) expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo)))
expect_identical( expect_identical(
as.character(as.mo(c("E. coli", "H. influenzae"))), as.character(as.mo(c("E. coli", "H. influenzae"))),
c("B_ESCHR_COLI", "B_HMPHL_INFL")) c("B_ESCHR_COLI", "B_HMPHL_INFL"))
expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COLI") expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COLI")
expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COLI") expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COLI")
expect_equal(as.character(as.mo(22242416)), "B_ESCHR_COLI") expect_equal(as.character(as.mo(22242416)), "B_ESCHR_COLI")
@ -53,14 +53,14 @@ test_that("as.mo works", {
expect_equal(as.character(as.mo("Group B Streptococci")), "B_STRPT_GRPB") expect_equal(as.character(as.mo("Group B Streptococci")), "B_STRPT_GRPB")
expect_equal(as.character(suppressWarnings(as.mo("B_STRPTC"))), "B_STRPT") # old MO code (<=v0.5.0) expect_equal(as.character(suppressWarnings(as.mo("B_STRPTC"))), "B_STRPT") # old MO code (<=v0.5.0)
expect_equal(as.character(suppressWarnings(as.mo("B_STRPT_PNE"))), "B_STRPT_PNMN") # old MO code (<=v0.8.0) expect_equal(as.character(suppressWarnings(as.mo("B_STRPT_PNE"))), "B_STRPT_PNMN") # old MO code (<=v0.8.0)
expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPT_GRPA", "B_STRPT_GRPB")) expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPT_GRPA", "B_STRPT_GRPB"))
expect_equal(as.character(as.mo("S. pyo")), "B_STRPT_PYGN") # not Actinomyces pyogenes expect_equal(as.character(as.mo("S. pyo")), "B_STRPT_PYGN") # not Actinomyces pyogenes
# GLIMS # GLIMS
expect_equal(as.character(as.mo("bctfgr")), "B_BCTRD_FRGL") expect_equal(as.character(as.mo("bctfgr")), "B_BCTRD_FRGL")
expect_equal(as.character(as.mo("MRSE")), "B_STPHY_EPDR") 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("VRE")), "B_ENTRC")
expect_equal(as.character(as.mo("MRPA")), "B_PSDMN_ARGN") expect_equal(as.character(as.mo("MRPA")), "B_PSDMN_ARGN")
@ -68,7 +68,7 @@ test_that("as.mo works", {
expect_equal(as.character(as.mo("PRSP")), "B_STRPT_PNMN") expect_equal(as.character(as.mo("PRSP")), "B_STRPT_PNMN")
expect_equal(as.character(as.mo("VISP")), "B_STRPT_PNMN") expect_equal(as.character(as.mo("VISP")), "B_STRPT_PNMN")
expect_equal(as.character(as.mo("VRSP")), "B_STRPT_PNMN") expect_equal(as.character(as.mo("VRSP")), "B_STRPT_PNMN")
expect_equal(as.character(as.mo("CNS")), "B_STPHY_CONS") expect_equal(as.character(as.mo("CNS")), "B_STPHY_CONS")
expect_equal(as.character(as.mo("CoNS")), "B_STPHY_CONS") expect_equal(as.character(as.mo("CoNS")), "B_STPHY_CONS")
expect_equal(as.character(as.mo("CPS")), "B_STPHY_COPS") expect_equal(as.character(as.mo("CPS")), "B_STPHY_COPS")
@ -76,9 +76,9 @@ test_that("as.mo works", {
expect_equal(as.character(as.mo("VGS")), "B_STRPT_VIRI") expect_equal(as.character(as.mo("VGS")), "B_STRPT_VIRI")
expect_equal(as.character(as.mo("streptococcus milleri")), "B_STRPT_MILL") expect_equal(as.character(as.mo("streptococcus milleri")), "B_STRPT_MILL")
expect_equal(as.character(as.mo(c("Gram negative", "Gram positive"))), c("B_GRAMN", "B_GRAMP")) expect_equal(as.character(as.mo(c("Gram negative", "Gram positive"))), c("B_GRAMN", "B_GRAMP"))
# prevalent MO # prevalent MO
expect_identical( expect_identical(
suppressWarnings(as.character( suppressWarnings(as.character(
@ -104,15 +104,15 @@ test_that("as.mo works", {
"B nodosa", "B nodosa",
"Burkholderia nodosa"))), "Burkholderia nodosa"))),
rep("B_BRKHL_NODS", 4)) rep("B_BRKHL_NODS", 4))
# empty values # empty values
expect_identical(as.character(as.mo(c("", NA, NaN))), rep(NA_character_, 3)) expect_identical(as.character(as.mo(c("", NA, NaN))), rep(NA_character_, 3))
# too few characters # too few characters
expect_warning(as.mo("ab")) expect_warning(as.mo("ab"))
expect_equal(suppressWarnings(as.character(as.mo(c("Qq species", "", "CRS", "K. pneu rhino", "esco")))), expect_equal(suppressWarnings(as.character(as.mo(c("Qq species", "", "CRSM", "K. pneu rhino", "esco")))),
c("UNKNOWN", NA_character_, "B_STNTR_MLTP", "B_KLBSL_PNMN_RHNS", "B_ESCHR_COLI")) c("UNKNOWN", NA_character_, "B_STNTR_MLTP", "B_KLBSL_PNMN_RHNS", "B_ESCHR_COLI"))
# check for Becker classification # check for Becker classification
expect_identical(as.character(as.mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPDR") expect_identical(as.character(as.mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPDR")
expect_identical(as.character(as.mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CONS") expect_identical(as.character(as.mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CONS")
@ -125,7 +125,7 @@ test_that("as.mo works", {
expect_identical(as.character(as.mo("STAAUR", Becker = FALSE)), "B_STPHY_AURS") expect_identical(as.character(as.mo("STAAUR", Becker = FALSE)), "B_STPHY_AURS")
expect_identical(as.character(as.mo("STAAUR", Becker = TRUE)), "B_STPHY_AURS") expect_identical(as.character(as.mo("STAAUR", Becker = TRUE)), "B_STPHY_AURS")
expect_identical(as.character(as.mo("STAAUR", Becker = "all")), "B_STPHY_COPS") expect_identical(as.character(as.mo("STAAUR", Becker = "all")), "B_STPHY_COPS")
# check for Lancefield classification # check for Lancefield classification
expect_identical(as.character(as.mo("S. pyogenes", Lancefield = FALSE)), "B_STRPT_PYGN") expect_identical(as.character(as.mo("S. pyogenes", Lancefield = FALSE)), "B_STRPT_PYGN")
expect_identical(as.character(as.mo("S. pyogenes", Lancefield = TRUE)), "B_STRPT_GRPA") expect_identical(as.character(as.mo("S. pyogenes", Lancefield = TRUE)), "B_STRPT_GRPA")
@ -145,9 +145,9 @@ test_that("as.mo works", {
expect_identical(as.character(as.mo("S. sanguinis", Lancefield = TRUE)), "B_STRPT_GRPH") # group H expect_identical(as.character(as.mo("S. sanguinis", Lancefield = TRUE)), "B_STRPT_GRPH") # group H
expect_identical(as.character(as.mo("S. salivarius", Lancefield = FALSE)), "B_STRPT_SLVR") expect_identical(as.character(as.mo("S. salivarius", Lancefield = FALSE)), "B_STRPT_SLVR")
expect_identical(as.character(as.mo("S. salivarius", Lancefield = TRUE)), "B_STRPT_GRPK") # group K expect_identical(as.character(as.mo("S. salivarius", Lancefield = TRUE)), "B_STRPT_GRPK") # group K
library(dplyr) library(dplyr)
# select with one column # select with one column
expect_identical( expect_identical(
example_isolates[1:10,] %>% example_isolates[1:10,] %>%
@ -157,7 +157,7 @@ test_that("as.mo works", {
as.character(), as.character(),
c("B_ESCHR", "B_ESCHR", "B_STPHY", "B_STPHY", "B_STPHY", c("B_ESCHR", "B_ESCHR", "B_STPHY", "B_STPHY", "B_STPHY",
"B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY")) "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY"))
# select with two columns # select with two columns
expect_identical( expect_identical(
example_isolates[1:10,] %>% example_isolates[1:10,] %>%
@ -166,28 +166,28 @@ test_that("as.mo works", {
left_join_microorganisms() %>% left_join_microorganisms() %>%
select(genus, species) %>% select(genus, species) %>%
as.mo()) as.mo())
# unknown results # unknown results
expect_warning(as.mo(c("INVALID", "Yeah, unknown"))) expect_warning(as.mo(c("INVALID", "Yeah, unknown")))
# too many columns # too many columns
expect_error(example_isolates %>% select(1:3) %>% as.mo()) expect_error(example_isolates %>% select(1:3) %>% as.mo())
# print # print
expect_output(print(as.mo(c("B_ESCHR_COLI", NA)))) expect_output(print(as.mo(c("B_ESCHR_COLI", NA))))
# test pull # test pull
expect_equal(nrow(example_isolates %>% mutate(mo = as.mo(mo))), expect_equal(nrow(example_isolates %>% mutate(mo = as.mo(mo))),
2000) 2000)
# test data.frame # test data.frame
expect_equal(nrow(data.frame(test = as.mo("B_ESCHR_COLI"))), expect_equal(nrow(data.frame(test = as.mo("B_ESCHR_COLI"))),
1) 1)
# check empty values # check empty values
expect_equal(as.character(suppressWarnings(as.mo(""))), expect_equal(as.character(suppressWarnings(as.mo(""))),
NA_character_) NA_character_)
# check less prevalent MOs # check less prevalent MOs
expect_equal(as.character(as.mo("Gomphosphaeria aponina delicatula")), "B_GMPHS_APNN_DLCT") expect_equal(as.character(as.mo("Gomphosphaeria aponina delicatula")), "B_GMPHS_APNN_DLCT")
expect_equal(as.character(as.mo("Gomphosphaeria apo del")), "B_GMPHS_APNN_DLCT") expect_equal(as.character(as.mo("Gomphosphaeria apo del")), "B_GMPHS_APNN_DLCT")
@ -197,11 +197,11 @@ test_that("as.mo works", {
expect_equal(as.character(as.mo("Gomphosphaeria")), "B_GMPHS") expect_equal(as.character(as.mo("Gomphosphaeria")), "B_GMPHS")
expect_equal(as.character(as.mo(" B_GMPHS_APNN ")), "B_GMPHS_APNN") expect_equal(as.character(as.mo(" B_GMPHS_APNN ")), "B_GMPHS_APNN")
expect_equal(as.character(as.mo("g aponina")), "B_GMPHS_APNN") expect_equal(as.character(as.mo("g aponina")), "B_GMPHS_APNN")
# check old names # check old names
expect_equal(suppressMessages(as.character(as.mo("Escherichia blattae"))), "B_SHMWL_BLTT") expect_equal(suppressMessages(as.character(as.mo("Escherichia blattae"))), "B_SHMWL_BLTT")
print(mo_renamed()) print(mo_renamed())
# check uncertain names # check uncertain names
expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = TRUE))), "B_STPHY_AURS") expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = TRUE))), "B_STPHY_AURS")
expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = FALSE))), "UNKNOWN") expect_equal(suppressWarnings(as.character(as.mo("staaur extratest", allow_uncertain = FALSE))), "UNKNOWN")
@ -209,7 +209,7 @@ test_that("as.mo works", {
expect_equal(suppressWarnings(as.character(as.mo("unexisting aureus", allow_uncertain = 3))), "B_STPHY_AURS") expect_equal(suppressWarnings(as.character(as.mo("unexisting aureus", allow_uncertain = 3))), "B_STPHY_AURS")
expect_equal(suppressWarnings(as.character(as.mo("unexisting staphy", allow_uncertain = 3))), "B_STPHY") expect_equal(suppressWarnings(as.character(as.mo("unexisting staphy", allow_uncertain = 3))), "B_STPHY")
expect_equal(suppressWarnings(as.character(as.mo("Staphylococcus aureus unexisting", allow_uncertain = 3))), "B_STPHY_AURS") expect_equal(suppressWarnings(as.character(as.mo("Staphylococcus aureus unexisting", allow_uncertain = 3))), "B_STPHY_AURS")
# predefined reference_df # predefined reference_df
expect_equal(as.character(as.mo("TestingOwnID", expect_equal(as.character(as.mo("TestingOwnID",
reference_df = data.frame(mycol = "TestingOwnID", mo = "B_ESCHR_COLI"))), reference_df = data.frame(mycol = "TestingOwnID", mo = "B_ESCHR_COLI"))),
@ -219,21 +219,16 @@ test_that("as.mo works", {
c("B_ESCHR_COLI", "B_ESCHR_COLI")) c("B_ESCHR_COLI", "B_ESCHR_COLI"))
expect_warning(as.mo("TestingOwnID", reference_df = NULL)) expect_warning(as.mo("TestingOwnID", reference_df = NULL))
expect_error(as.mo("E. coli", reference_df = data.frame(mycol = "TestingOwnID"))) expect_error(as.mo("E. coli", reference_df = data.frame(mycol = "TestingOwnID")))
# combination of existing mo and other code # combination of existing mo and other code
expect_identical(suppressWarnings(as.character(as.mo(c("B_ESCHR_COL", "ESCCOL")))), expect_identical(as.character(as.mo(c("B_ESCHR_COL", "ESCCOL"))),
c("B_ESCHR_COLI", "B_ESCHR_COLI")) c("B_ESCHR_COLI", "B_ESCHR_COLI"))
# expect_equal(mo_fullname(c("E. spp.",
# "E. spp",
# "E. species")),
# rep("Escherichia species", 3))
# from different sources # from different sources
expect_equal(as.character(as.mo( expect_equal(as.character(as.mo(
c("PRTMIR", "bclcer", "B_ESCHR_COLI"))), c("PRTMIR", "bclcer", "B_ESCHR_COLI"))),
c("B_PROTS_MRBL", "B_BCLLS_CERS", "B_ESCHR_COLI")) c("B_PROTS_MRBL", "B_BCLLS_CERS", "B_ESCHR_COLI"))
# hard to find # hard to find
expect_equal(as.character(suppressWarnings(as.mo( expect_equal(as.character(suppressWarnings(as.mo(
c("Microbacterium paraoxidans", c("Microbacterium paraoxidans",
@ -241,43 +236,43 @@ test_that("as.mo works", {
"Raoultella (here some text) terrigena")))), "Raoultella (here some text) terrigena")))),
c("B_MCRBC_PRXY", "B_STRPT_SUIS", "B_RLTLL_TRRG")) c("B_MCRBC_PRXY", "B_STRPT_SUIS", "B_RLTLL_TRRG"))
expect_output(print(mo_uncertainties())) expect_output(print(mo_uncertainties()))
# Salmonella (City) are all actually Salmonella enterica spp (City) # Salmonella (City) are all actually Salmonella enterica spp (City)
expect_equal(as.character(suppressWarnings(as.mo("Salmonella Goettingen"))), expect_equal(as.character(suppressWarnings(as.mo("Salmonella Goettingen"))),
"B_SLMNL_ENTR") "B_SLMNL_ENTR")
expect_equal(as.character(as.mo("Salmonella Group A")), "B_SLMNL") expect_equal(as.character(as.mo("Salmonella Group A")), "B_SLMNL")
# no virusses # no virusses
expect_equal(as.character(as.mo("Virus")), NA_character_) expect_equal(as.character(as.mo("Virus")), NA_character_)
# summary # summary
expect_equal(length(summary(example_isolates$mo)), 6) expect_equal(length(summary(example_isolates$mo)), 6)
# WHONET codes and NA/NaN # WHONET codes and NA/NaN
expect_equal(as.character(as.mo(c("xxx", "na", "nan"), debug = TRUE)), expect_equal(as.character(as.mo(c("xxx", "na", "nan"), debug = TRUE)),
rep(NA_character_, 3)) rep(NA_character_, 3))
expect_equal(as.character(as.mo("con")), "UNKNOWN") expect_equal(as.character(as.mo("con")), "UNKNOWN")
expect_equal(as.character(as.mo("xxx")), NA_character_) expect_equal(as.character(as.mo("xxx")), NA_character_)
expect_equal(as.character(as.mo(c("xxx", "con", "eco"))), c(NA_character_, "UNKNOWN", "B_ESCHR_COLI")) expect_equal(as.character(as.mo(c("xxx", "con", "eco"))), c(NA_character_, "UNKNOWN", "B_ESCHR_COLI"))
expect_equal(as.character(as.mo(c("other", "none", "unknown"))), expect_equal(as.character(as.mo(c("other", "none", "unknown"))),
rep("UNKNOWN", 3)) rep("UNKNOWN", 3))
expect_null(mo_failures()) expect_null(mo_failures())
expect_true(example_isolates %>% pull(mo) %>% is.mo()) expect_true(example_isolates %>% pull(mo) %>% is.mo())
# expect_equal(get_mo_code("test", "mo"), "test") # expect_equal(get_mo_code("test", "mo"), "test")
# expect_equal(length(get_mo_code("Escherichia", "genus")), # expect_equal(length(get_mo_code("Escherichia", "genus")),
# nrow(AMR::microorganisms[base::which(AMR::microorganisms[, "genus"] %in% "Escherichia"),])) # nrow(AMR::microorganisms[base::which(AMR::microorganisms[, "genus"] %in% "Escherichia"),]))
expect_error(translate_allow_uncertain(5)) expect_error(translate_allow_uncertain(5))
# very old MO codes (<= v0.5.0) # very old MO codes (<= v0.5.0)
expect_equal(suppressWarnings(as.character(as.mo("F_CCCCS_NEO"))), "F_CRYPT_NFRM") expect_equal(suppressWarnings(as.character(as.mo("F_CCCCS_NEO"))), "F_CRYPT_NFRM")
expect_equal(suppressWarnings(as.character(as.mo("F_CANDD_GLB"))), "F_CANDD_GLBR") expect_equal(suppressWarnings(as.character(as.mo("F_CANDD_GLB"))), "F_CANDD_GLBR")
# debug mode # debug mode
expect_output(print(suppressMessages(suppressWarnings(as.mo("kshgcjkhsdgkshjdfsfvsdfv", debug = TRUE, allow_uncertain = 3))))) expect_output(print(suppressMessages(suppressWarnings(as.mo("kshgcjkhsdgkshjdfsfvsdfv", debug = TRUE, allow_uncertain = 3)))))
# ..coccus # ..coccus
expect_equal(as.character(as.mo(c("meningococ", "gonococ", "pneumococ"))), expect_equal(as.character(as.mo(c("meningococ", "gonococ", "pneumococ"))),
c("B_NESSR_MNNG", "B_NESSR_GNRR", "B_STRPT_PNMN")) c("B_NESSR_MNNG", "B_NESSR_GNRR", "B_STRPT_PNMN"))

View File

@ -90,7 +90,9 @@ test_that("mo_property works", {
expect_identical(suppressWarnings(mo_ref("Chlamydia psittaci")), "Page, 1968") expect_identical(suppressWarnings(mo_ref("Chlamydia psittaci")), "Page, 1968")
expect_identical(mo_ref("Chlamydophila psittaci"), "Everett et al., 1999") expect_identical(mo_ref("Chlamydophila psittaci"), "Everett et al., 1999")
# old codes must throw a warning in mo_* family
expect_warning(mo_name(c("B_ESCHR_COL", "B_STPHY_AUR")))
# outcome of mo_fullname must always return the fullname from the data set # outcome of mo_fullname must always return the fullname from the data set
library(dplyr) library(dplyr)
x <- microorganisms %>% x <- microorganisms %>%