mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 11:11:54 +02:00
(v1.5.0.9030) as.ab() speed improvement
This commit is contained in:
25
R/ab.R
25
R/ab.R
@ -105,14 +105,29 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = TRUE, ...) {
|
||||
already_regex <- isTRUE(list(...)$already_regex)
|
||||
fast_mode <- isTRUE(list(...)$fast_mode)
|
||||
|
||||
if (all(toupper(x) %in% antibiotics$ab)) {
|
||||
# valid AB code, but not yet right class
|
||||
return(set_clean_class(toupper(x),
|
||||
new_class = c("ab", "character")))
|
||||
}
|
||||
|
||||
x_bak <- x
|
||||
x <- toupper(x)
|
||||
x_nonNA <- x[!is.na(x)]
|
||||
|
||||
if (all(x_nonNA %in% antibiotics$ab, na.rm = TRUE)) {
|
||||
# all valid AB codes, but not yet right class
|
||||
return(set_clean_class(x,
|
||||
new_class = c("ab", "character")))
|
||||
}
|
||||
if (all(x_nonNA %in% toupper(antibiotics$name), na.rm = TRUE)) {
|
||||
# all valid AB names
|
||||
out <- antibiotics$ab[match(x, toupper(antibiotics$name))]
|
||||
out[is.na(x)] <- NA_character_
|
||||
return(out)
|
||||
}
|
||||
if (all(x_nonNA %in% antibiotics$atc, na.rm = TRUE)) {
|
||||
# all valid ATC codes
|
||||
out <- antibiotics$ab[match(x, antibiotics$atc)]
|
||||
out[is.na(x)] <- NA_character_
|
||||
return(out)
|
||||
}
|
||||
|
||||
# remove diacritics
|
||||
x <- iconv(x, from = "UTF-8", to = "ASCII//TRANSLIT")
|
||||
x <- gsub('"', "", x, fixed = TRUE)
|
||||
|
@ -131,16 +131,15 @@ catalogue_of_life_version <- function() {
|
||||
#' @export
|
||||
#' @noRd
|
||||
print.catalogue_of_life_version <- function(x, ...) {
|
||||
lst <- x
|
||||
cat(paste0(font_bold("Included in this AMR package (v", utils::packageDescription("AMR")$Version, ") are:\n\n", collapse = ""),
|
||||
font_underline(lst$CoL$version), "\n",
|
||||
" Available at: ", lst$CoL$url, "\n",
|
||||
" Number of included species: ", format(lst$CoL$n, big.mark = ","), "\n",
|
||||
font_underline(paste0(lst$LPSN$version, " (",
|
||||
lst$LPSN$yearmonth, ")")), "\n",
|
||||
" Available at: ", lst$LPSN$url, "\n",
|
||||
" Number of included species: ", format(lst$LPSN$n, big.mark = ","), "\n\n",
|
||||
"=> Total number of species included: ", format(lst$total_included$n_total_species, big.mark = ","), "\n",
|
||||
"=> Total number of synonyms included: ", format(lst$total_included$n_total_synonyms, big.mark = ","), "\n\n",
|
||||
font_underline(x$CoL$version), "\n",
|
||||
" Available at: ", font_blue(x$CoL$url), "\n",
|
||||
" Number of included microbial species: ", format(x$CoL$n, big.mark = ","), "\n",
|
||||
font_underline(paste0(x$LPSN$version, " (",
|
||||
x$LPSN$yearmonth, ")")), "\n",
|
||||
" Available at: ", font_blue(x$LPSN$url), "\n",
|
||||
" Number of included bacterial species: ", format(x$LPSN$n, big.mark = ","), "\n\n",
|
||||
"=> Total number of species included: ", format(x$total_included$n_total_species, big.mark = ","), "\n",
|
||||
"=> Total number of synonyms included: ", format(x$total_included$n_total_synonyms, big.mark = ","), "\n\n",
|
||||
"See for more info ?microorganisms and ?catalogue_of_life.\n"))
|
||||
}
|
||||
|
BIN
R/sysdata.rda
BIN
R/sysdata.rda
Binary file not shown.
Reference in New Issue
Block a user