1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 11:01:57 +02:00

as.mo improvements

This commit is contained in:
2019-02-25 16:07:21 +01:00
parent c506d2893b
commit f25a4b3679
8 changed files with 294 additions and 272 deletions

15
R/mo.R
View File

@ -166,6 +166,21 @@
#' mutate(mo = as.mo(paste(genus, species)))
#' }
as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE, reference_df = get_mo_source()) {
if (all(x %in% AMR::microorganisms$fullname)
& isFALSE(Becker)
& isFALSE(Lancefield)
& is.null(reference_df)) {
# we need special treatment for very prevalent full names, they are likely!
# e.g. as.mo("Staphylococcus aureus")
y <- microorganismsDT[prevalence == 1][data.table(fullname = x), on = "fullname", "mo"][[1]]
if (any(is.na(y))) {
y[is.na(y)] <- microorganismsDT[prevalence == 2][data.table(fullname = x[is.na(y)]), on = "fullname", "mo"][[1]]
}
if (any(is.na(y))) {
y[is.na(y)] <- microorganismsDT[prevalence == 3][data.table(fullname = x[is.na(y)]), on = "fullname", "mo"][[1]]
}
return(y)
}
# will be checked for mo class in validation
mo_validate(x = x, property = "mo",
Becker = Becker, Lancefield = Lancefield,