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

(v1.7.1.9077) skimr support only for newer R versions

This commit is contained in:
2021-12-23 13:38:25 +01:00
parent ed22b83c28
commit 75dac113b6
9 changed files with 45 additions and 27 deletions

16
R/ab.R
View File

@ -133,8 +133,8 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
note_if_more_than_one_found <- function(found, index, from_text) {
if (initial_search == TRUE & isTRUE(length(from_text) > 1)) {
abnames <- ab_name(from_text, tolower = TRUE, initial_search = FALSE)
if (ab_name(found[1L], language = NULL) %like% "clavulanic acid") {
abnames <- abnames[!abnames == "clavulanic acid"]
if (ab_name(found[1L], language = NULL) %like% "(clavulanic acid|avibactam)") {
abnames <- abnames[!abnames %in% c("clavulanic acid", "avibactam")]
}
if (length(abnames) > 1) {
message_("More than one result was found for item ", index, ": ",
@ -222,6 +222,16 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
next
}
# length of input is quite long, and Levenshtein distance is only max 2
if (nchar(x[i]) >= 10) {
levenshtein <- as.double(utils::adist(x[i], AB_lookup$generalised_name))
if (any(levenshtein <= 2)) {
found <- AB_lookup$ab[which(levenshtein <= 2)]
x_new[i] <- note_if_more_than_one_found(found, i, from_text)
next
}
}
# allow characters that resemble others, but only continue when having more than 3 characters
if (nchar(x[i]) <= 3) {
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
@ -238,7 +248,7 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
x_spelling <- gsub("E+", "E+", x_spelling, perl = TRUE)
x_spelling <- gsub("O+", "O+", x_spelling, perl = TRUE)
# allow any ending of -in/-ine and -im/-ime
x_spelling <- gsub("(\\[IY\\]\\+(N|M)|\\[IY\\]\\+(N|M)E\\+)$", "[IY]+(N|M)E*", x_spelling, perl = TRUE)
x_spelling <- gsub("(\\[IY\\]\\+(N|M)|\\[IY\\]\\+(N|M)E\\+?)$", "[IY]+(N|M)E*", x_spelling, perl = TRUE)
# allow any ending of -ol/-ole
x_spelling <- gsub("(O\\+L|O\\+LE\\+)$", "O+LE*", x_spelling, perl = TRUE)
# allow any ending of -on/-one

10
R/zzz.R
View File

@ -57,10 +57,12 @@ if (utf8_supported && !is_latex) {
s3_register("cleaner::freq", "mo")
s3_register("cleaner::freq", "rsi")
# Support for skim() from the skimr package
s3_register("skimr::get_skimmers", "mo")
s3_register("skimr::get_skimmers", "rsi")
s3_register("skimr::get_skimmers", "mic")
s3_register("skimr::get_skimmers", "disk")
if (pkg_is_available("skimr", also_load = FALSE, min_version = "2.0.0")) {
s3_register("skimr::get_skimmers", "mo")
s3_register("skimr::get_skimmers", "rsi")
s3_register("skimr::get_skimmers", "mic")
s3_register("skimr::get_skimmers", "disk")
}
# Support for autoplot() from the ggplot2 package
s3_register("ggplot2::autoplot", "rsi")
s3_register("ggplot2::autoplot", "mic")