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

fix for R < 3.4

This commit is contained in:
2022-12-30 12:57:27 +01:00
parent 1db74e86cd
commit e4ea96cbf9
8 changed files with 25 additions and 24 deletions

View File

@ -380,7 +380,7 @@ import_fn <- function(name, pkg, error_on_fail = TRUE) {
error = function(e) {
if (isTRUE(error_on_fail)) {
stop_("function ", name, "() is not an exported object from package '", pkg,
"'. Please create an issue at https://github.com/msberends/AMR/issues. Many thanks!",
"'. Please create an issue at ", font_url("https://github.com/msberends/AMR/issues"), ". Many thanks!",
call = FALSE
)
} else {
@ -476,6 +476,7 @@ word_wrap <- function(...,
# remove extra space that was introduced (e.g. "Smith et al., 2022")
msg <- gsub(". ,", ".,", msg, fixed = TRUE)
msg <- gsub("[ ,", "[,", msg, fixed = TRUE)
msg <- gsub("/ /", "//", msg, fixed = TRUE)
msg
}

View File

@ -135,7 +135,7 @@ add_custom_antimicrobials <- function(x) {
x$generalised_name <- generalise_antibiotic_name(x$name)
x$generalised_all <- as.list(x$generalised_name)
for (col in colnames(x)) {
if (is.list(AMR_env$AB_lookup[, col, drop = TRUE])) {
if (is.list(AMR_env$AB_lookup[, col, drop = TRUE]) & !is.list(x[, col, drop = TRUE])) {
x[, col] <- as.list(x[, col, drop = TRUE])
}
}
@ -155,7 +155,8 @@ add_custom_antimicrobials <- function(x) {
new_df[, col] <- x[, col, drop = TRUE]
}
AMR_env$AB_lookup <- unique(rbind(AMR_env$AB_lookup, new_df))
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$ab %in% new_df$ab), , drop = FALSE]
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$ab %in% x$ab), , drop = FALSE]
class(AMR_env$AB_lookup$ab) <- c("ab", "character")
message_("Added ", nr2char(nrow(x)), " record", ifelse(nrow(x) > 1, "s", ""), " to the internal `antibiotics` data set.")
}
@ -167,5 +168,6 @@ clear_custom_antimicrobials <- function() {
AMR_env$AB_lookup <- create_AB_lookup()
n2 <- nrow(AMR_env$AB_lookup)
AMR_env$custom_ab_codes <- character(0)
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(AMR_env$ab_previously_coerced$ab %in% AMR_env$AB_lookup$ab), , drop = FALSE]
message_("Cleared ", nr2char(n - n2), " custom record", ifelse(n - n2 > 1, "s", ""), " from the internal `antibiotics` data set.")
}

View File

@ -185,11 +185,10 @@ add_custom_microorganisms <- function(x) {
x$mo <- trimws2(x$mo)
x$mo[x$mo == ""] <- NA_character_
x$mo[is.na(x$mo)] <- paste0("CUSTOM_",
toupper(abbreviate(gsub(" +", " _ ",
gsub("[^A-Za-z0-9-]", " ",
trimws2(paste(x$genus, x$species, x$subspecies)))),
minlength = 10,
named = FALSE)))
toupper(unname(abbreviate(gsub(" +", " _ ",
gsub("[^A-Za-z0-9-]", " ",
trimws2(paste(x$genus, x$species, x$subspecies)))),
minlength = 10))))
# add to package ----

View File

@ -804,7 +804,7 @@ as_rsi_method <- function(method_short,
for (i in seq_len(length(messages))) {
messages[i] <- word_wrap(extra_indent = 5, messages[i])
}
message(font_green(font_bold(" * NOTE *\n")),
message(font_green(font_bold(" Note:\n")),
paste0(" ", font_black(AMR_env$bullet_icon)," ", font_black(messages, collapse = NULL) , collapse = "\n"))
}

View File

@ -230,7 +230,7 @@ translate_into_language <- function(from,
any_form_in_patterns <- tryCatch(
any(from_unique %like% paste0("(", paste(gsub(" +\\(.*", "", df_trans$pattern), collapse = "|"), ")")),
error = function(e) {
warning_("Translation not possible. Please open an issue on GitHub (https://github.com/msberends/AMR/issues).")
warning_("Translation not possible. Please create an issue at ", font_url("https://github.com/msberends/AMR/issues"), ". Many thanks!")
return(FALSE)
}
)