diff --git a/R/mo.R b/R/mo.R index bdc9d8a6..84303048 100644 --- a/R/mo.R +++ b/R/mo.R @@ -182,7 +182,7 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = # defined df to check for if (!is.null(reference_df)) { if (!is.data.frame(reference_df) | NCOL(reference_df) < 2) { - stop('`reference_df` must be a data.frame with at least two columns.') + stop('`reference_df` must be a data.frame with at least two columns.', call. = FALSE) } # remove factors, just keep characters suppressWarnings( diff --git a/R/mo_property.R b/R/mo_property.R index a7104b15..574785e4 100644 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -231,16 +231,7 @@ mo_property <- function(x, property = 'fullname', language = NULL, ...) { stop("invalid property: '", property, "' - use a column name of the `microorganisms` data set") } - # this will give a warning if x cannot be coerced - res <- exec_as.mo(x = x, Becker = Becker, Lancefield = Lancefield, property = property) - - if (property != "tsn") { - res[x %in% c("", NA) | res %in% c("", NA, "(no MO)")] <- "" - if (property %in% c("fullname", "shortname", "genus", "species", "subspecies", "type", "gramstain")) { - res <- mo_translate(res, language = language) - } - } - res + mo_translate(mo_validate(x = x, property = property, ...), language = language) } #' @rdname mo_property diff --git a/tests/testthat/test-mo.R b/tests/testthat/test-mo.R index dc0e8afe..d12ee4e5 100644 --- a/tests/testthat/test-mo.R +++ b/tests/testthat/test-mo.R @@ -165,7 +165,15 @@ test_that("as.mo works", { expect_equal(as.character(as.mo(c("TestingOwnID", "E. coli"), reference_df = data.frame(a = "TestingOwnID", b = "B_ESCHR_COL"))), c("B_ESCHR_COL", "B_ESCHR_COL")) - expect_warning(as.character(as.mo("TestingOwnID", - reference_df = NULL))) + expect_warning(as.mo("TestingOwnID", reference_df = NULL)) + expect_error(as.mo("E. coli", reference_df = data.frame(a = "TestingOwnID"))) + + # combination of existing mo and certe + expect_identical(as.character(as.mo(c("B_ESCHR_COL", "ESCCOL"))), + c("B_ESCHR_COL", "B_ESCHR_COL")) + + # TSN of prevalent and non prevalent ones + expect_equal(mo_TSN(c("Gomphosphaeria aponina delicatula", "Escherichia coli")), + c(717, 285)) }) diff --git a/tests/testthat/test-mo_property.R b/tests/testthat/test-mo_property.R index 4a6696df..5d519126 100644 --- a/tests/testthat/test-mo_property.R +++ b/tests/testthat/test-mo_property.R @@ -12,6 +12,7 @@ test_that("mo_property works", { expect_equal(mo_fullname("E. coli"), "Escherichia coli") expect_equal(mo_type("E. coli", language = "en"), "Bacteria") expect_equal(mo_gramstain("E. coli", language = "en"), "Gram negative") + expect_equal(mo_TSN("E. coli"), 285) expect_equal(class(mo_taxonomy("E. coli")), "list") expect_equal(names(mo_taxonomy("E. coli")), c("subkingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies")) @@ -42,4 +43,14 @@ test_that("mo_property works", { expect_error(mo_gramstain("E. coli", language = "UNKNOWN")) + # manual property function + expect_error(mo_property("E. coli", property = c("tsn", "fullname"))) + expect_error(mo_property("E. coli", property = "UNKNOWN")) + expect_identical(mo_property("E. coli", property = "fullname"), + mo_fullname("E. coli")) + expect_identical(mo_property("E. coli", property = "genus"), + mo_genus("E. coli")) + expect_identical(mo_property("E. coli", property = "species"), + mo_species("E. coli")) + })