1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 08:06:12 +01:00

(v1.2.0.9023) ab_from_text() improvement

This commit is contained in:
dr. M.S. (Matthijs) Berends 2020-07-02 21:12:52 +02:00
parent 298e67a45b
commit 152ac5bcad
29 changed files with 175 additions and 118 deletions

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 1.2.0.9022 Version: 1.2.0.9023
Date: 2020-07-01 Date: 2020-07-02
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(
person(role = c("aut", "cre"), person(role = c("aut", "cre"),

10
NEWS.md
View File

@ -1,5 +1,5 @@
# AMR 1.2.0.9022 # AMR 1.2.0.9023
## <small>Last updated: 01-Jul-2020</small> ## <small>Last updated: 02-Jul-2020</small>
### New ### New
* Function `ab_from_text()` to retrieve antimicrobial drug names, doses and forms of administration from clinical texts in e.g. health care records, which also corrects for misspelling since it uses `as.ab()` internally * Function `ab_from_text()` to retrieve antimicrobial drug names, doses and forms of administration from clinical texts in e.g. health care records, which also corrects for misspelling since it uses `as.ab()` internally
@ -19,9 +19,9 @@
* Added Monuril as trade name for fosfomycin * Added Monuril as trade name for fosfomycin
### Changed ### Changed
* Using unexisting columns in all `count_*()`, `proportion_*()`, `susceptibility()` and `resistance()` functions wil now return an error instead of dropping them silently * Using unexisting columns in all `count_*()`, `proportion_*()`, `susceptibility()` and `resistance()` functions wil now return an error instead of dropping them silently. Using variables for column names (as well as `dplyr::all_of()`) now works again.
* Improvements for `as.ab()`: * Improvements for `as.ab()`:
* Dramatic improvement of the algorithm behind `as.ab()`, making many more input errors translatable like from digitalised health care records, using too few or too many vowels or consonants and many more * Dramatic improvement of the algorithm behind `as.ab()`, making many more input errors translatable, such as digitalised health care records, using too few or too many vowels or consonants and many more
* Added progress bar * Added progress bar
* Fixed a bug where `as.ab()` would return an error on invalid input values * Fixed a bug where `as.ab()` would return an error on invalid input values
* The `as.ab()` function will now throw a note if more than 1 antimicrobial drug could be retrieved from a single input value. * The `as.ab()` function will now throw a note if more than 1 antimicrobial drug could be retrieved from a single input value.
@ -32,7 +32,7 @@
* Fixed a bug in `bug_drug_combinations()` for when only one antibiotic was in the input data * Fixed a bug in `bug_drug_combinations()` for when only one antibiotic was in the input data
* Changed the summary for class `<mo>`, to highlight the %SI vs. %R * Changed the summary for class `<mo>`, to highlight the %SI vs. %R
* Improved error handling, giving more useful info when functions return an error * Improved error handling, giving more useful info when functions return an error
* Any progress bar will now only show in interactive mode (i.e. not in R Markdown)
# AMR 1.2.0 # AMR 1.2.0

View File

@ -27,6 +27,7 @@
#' @param type type of property to search for, either `"drug"`, `"dose"` or `"administration"`, see *Examples* #' @param type type of property to search for, either `"drug"`, `"dose"` or `"administration"`, see *Examples*
#' @param collapse character to pass on to `paste(..., collapse = ...)` to only return one character per element of `text`, see *Examples* #' @param collapse character to pass on to `paste(..., collapse = ...)` to only return one character per element of `text`, see *Examples*
#' @param translate_ab if `type = "drug"`: a column name of the [antibiotics] data set to translate the antibiotic abbreviations to, using [ab_property()]. Defaults to `FALSE`. Using `TRUE` is equal to using "name". #' @param translate_ab if `type = "drug"`: a column name of the [antibiotics] data set to translate the antibiotic abbreviations to, using [ab_property()]. Defaults to `FALSE`. Using `TRUE` is equal to using "name".
#' @param thorough_search logical to indicate whether the input must be extensively searched for misspelling and other faulty input values. Setting this to `TRUE` will take considerably more time than when using `FALSE`. At default, it will turn `TRUE` when all input elements contain a maximum of three words.
#' @param ... parameters passed on to [as.ab()] #' @param ... parameters passed on to [as.ab()]
#' @details This function is also internally used by [as.ab()], although it then only searches for the first drug name and will throw a note if more drug names could have been returned. #' @details This function is also internally used by [as.ab()], although it then only searches for the first drug name and will throw a note if more drug names could have been returned.
#' #'
@ -85,6 +86,7 @@ ab_from_text <- function(text,
type = c("drug", "dose", "administration"), type = c("drug", "dose", "administration"),
collapse = NULL, collapse = NULL,
translate_ab = FALSE, translate_ab = FALSE,
thorough_search = NULL,
...) { ...) {
if (missing(type)) { if (missing(type)) {
@ -95,30 +97,54 @@ ab_from_text <- function(text,
text <- tolower(as.character(text)) text <- tolower(as.character(text))
text_split_all <- strsplit(text, "[ ;.,:\\|]") text_split_all <- strsplit(text, "[ ;.,:\\|]")
progress <- progress_estimated(n = length(text_split_all), n_min = 5)
on.exit(close(progress))
if (type %like% "(drug|ab|anti)") { if (type %like% "(drug|ab|anti)") {
translate_ab <- get_translate_ab(translate_ab) translate_ab <- get_translate_ab(translate_ab)
abbr <- unlist(antibiotics$abbreviations) if (isTRUE(thorough_search) |
abbr <- abbr[nchar(abbr) >= 4] (isTRUE(is.null(thorough_search)) & max(sapply(text_split_all, length), na.rm = TRUE) <= 3)) {
names_atc <- substr(c(antibiotics$name, antibiotics$atc), 1, 5) text_split_all <- text_split_all[nchar(text_split_all) >= 4 & grepl("[a-z]+", text_split_all)]
synonyms <- unlist(antibiotics$synonyms) result <- lapply(text_split_all, function(text_split) {
synonyms <- synonyms[nchar(synonyms) >= 4] progress$tick()
to_regex <- function(x) { suppressWarnings(
paste0("^(", out <- as.ab(text_split, ...)
paste0(unique(gsub("[^a-z0-9]", ".*", sort(tolower(x)))), collapse = "|"), )
").*") })
} else {
# no thorough search
abbr <- unlist(antibiotics$abbreviations)
abbr <- abbr[nchar(abbr) >= 4]
names_atc <- substr(c(antibiotics$name, antibiotics$atc), 1, 5)
synonyms <- unlist(antibiotics$synonyms)
synonyms <- synonyms[nchar(synonyms) >= 4]
# regular expression must not be too long, so split synonyms in two:
synonyms_part1 <- synonyms[seq_len(0.5 * length(synonyms))]
synonyms_part2 <- synonyms[!synonyms %in% synonyms_part1]
to_regex <- function(x) {
paste0("^(",
paste0(unique(gsub("[^a-z0-9]+", "", sort(tolower(x)))), collapse = "|"),
").*")
}
result <- lapply(text_split_all, function(text_split) {
progress$tick()
suppressWarnings(
out <- as.ab(unique(c(text_split[text_split %like_case% to_regex(abbr)],
text_split[text_split %like_case% to_regex(names_atc)],
text_split[text_split %like_case% to_regex(synonyms_part1)],
text_split[text_split %like_case% to_regex(synonyms_part2)])
),
...)
)
})
} }
result <- lapply(text_split_all, function(text_split) { close(progress)
suppressWarnings(
out <- as.ab(unique(c(text_split[grep(to_regex(abbr), text_split)], result <- lapply(result, function(out) {
text_split[grep(to_regex(names_atc), text_split)],
# regular expression must not be too long, so split synonyms in two:
text_split[grep(to_regex(synonyms[c(1:0.5 * length(synonyms))]), text_split)],
text_split[grep(to_regex(synonyms[c(0.5 * length(synonyms):length(synonyms))]), text_split)])),
...))
out <- out[!is.na(out)] out <- out[!is.na(out)]
if (length(out) == 0) { if (length(out) == 0) {
as.ab(NA) as.ab(NA)
@ -128,6 +154,7 @@ ab_from_text <- function(text,
} }
out out
} }
}) })
} else if (type %like% "dos") { } else if (type %like% "dos") {
@ -167,7 +194,7 @@ ab_from_text <- function(text,
# collapse text if needed # collapse text if needed
if (!is.null(collapse)) { if (!is.null(collapse)) {
result <- sapply(result, function(x) { result <- sapply(result, function(x) {
if(length(x) == 1 & all(is.na(x))) { if (length(x) == 1 & all(is.na(x))) {
NA_character_ NA_character_
} else { } else {
paste0(x, collapse = collapse) paste0(x, collapse = collapse)

View File

@ -135,7 +135,7 @@ format.bug_drug_combinations <- function(x,
format <- tolower(format) format <- tolower(format)
ab_txt <- rep(format, length(ab)) ab_txt <- rep(format, length(ab))
for (i in seq_len(length(ab_txt))) { for (i in seq_len(length(ab_txt))) {
ab_txt[i] <- gsub("ab", ab[i], ab_txt[i]) ab_txt[i] <- gsub("ab", as.character(as.ab(ab[i])), ab_txt[i])
ab_txt[i] <- gsub("cid", ab_cid(ab[i]), ab_txt[i]) ab_txt[i] <- gsub("cid", ab_cid(ab[i]), ab_txt[i])
ab_txt[i] <- gsub("group", ab_group(ab[i], language = language), ab_txt[i]) ab_txt[i] <- gsub("group", ab_group(ab[i], language = language), ab_txt[i])
ab_txt[i] <- gsub("atc_group1", ab_atc_group1(ab[i], language = language), ab_txt[i]) ab_txt[i] <- gsub("atc_group1", ab_atc_group1(ab[i], language = language), ab_txt[i])

View File

@ -259,25 +259,25 @@ first_isolate <- function(x,
# arrange data to the right sorting # arrange data to the right sorting
if (is.null(specimen_group)) { if (is.null(specimen_group)) {
x <- x[order(x$newvar_patient_id, x <- x[order(x$newvar_patient_id,
x$newvar_genus_species, x$newvar_genus_species,
x$newvar_date), ] x$newvar_date), ]
rownames(x) <- NULL rownames(x) <- NULL
row.start <- 1 row.start <- 1
row.end <- nrow(x) row.end <- nrow(x)
} else { } else {
# filtering on specimen and only analyse these rows to save time # filtering on specimen and only analyse these rows to save time
x <- x[order(pull(x, col_specimen), x <- x[order(pull(x, col_specimen),
x$newvar_patient_id, x$newvar_patient_id,
x$newvar_genus_species, x$newvar_genus_species,
x$newvar_date), ] x$newvar_date), ]
rownames(x) <- NULL rownames(x) <- NULL
suppressWarnings( suppressWarnings(
row.start <- which(x %>% pull(col_specimen) == specimen_group) %>% min(na.rm = TRUE) row.start <- which(x %>% pull(col_specimen) == specimen_group) %>% min(na.rm = TRUE)
) )
suppressWarnings( suppressWarnings(
row.end <- which(x %>% pull(col_specimen) == specimen_group) %>% max(na.rm = TRUE) row.end <- which(x %>% pull(col_specimen) == specimen_group) %>% max(na.rm = TRUE)
) )
} }
# no isolates found # no isolates found
@ -318,17 +318,17 @@ first_isolate <- function(x,
# Analysis of first isolate ---- # Analysis of first isolate ----
x$other_pat_or_mo <- if_else(x$newvar_patient_id == lag(x$newvar_patient_id) & x$other_pat_or_mo <- if_else(x$newvar_patient_id == lag(x$newvar_patient_id) &
x$newvar_genus_species == lag(x$newvar_genus_species), x$newvar_genus_species == lag(x$newvar_genus_species),
FALSE, FALSE,
TRUE) TRUE)
x$episode_group <- paste(x$newvar_patient_id, x$newvar_genus_species) x$episode_group <- paste(x$newvar_patient_id, x$newvar_genus_species)
x$more_than_episode_ago <- unname(unlist(lapply(unique(x$episode_group), x$more_than_episode_ago <- unlist(lapply(unique(x$episode_group),
function(g, function(g,
df = x, df = x,
days = episode_days) { days = episode_days) {
identify_new_year(x = df[which(df$episode_group == g), "newvar_date"], identify_new_year(x = df[which(df$episode_group == g), "newvar_date", drop = TRUE],
episode_days = days) episode_days = days)
}))) }))
weighted.notice <- "" weighted.notice <- ""
if (!is.null(col_keyantibiotics)) { if (!is.null(col_keyantibiotics)) {
@ -336,38 +336,38 @@ first_isolate <- function(x,
if (info == TRUE) { if (info == TRUE) {
if (type == "keyantibiotics") { if (type == "keyantibiotics") {
message(font_black(paste0("[Criterion] Base inclusion on key antibiotics, ", message(font_black(paste0("[Criterion] Base inclusion on key antibiotics, ",
ifelse(ignore_I == FALSE, "not ", ""), ifelse(ignore_I == FALSE, "not ", ""),
"ignoring I"))) "ignoring I")))
} }
if (type == "points") { if (type == "points") {
message(font_black(paste0("[Criterion] Base inclusion on key antibiotics, using points threshold of " message(font_black(paste0("[Criterion] Base inclusion on key antibiotics, using points threshold of "
, points_threshold))) , points_threshold)))
} }
} }
type_param <- type type_param <- type
x$other_key_ab <- !key_antibiotics_equal(y = x$newvar_key_ab, x$other_key_ab <- !key_antibiotics_equal(y = x$newvar_key_ab,
z = lag(x$newvar_key_ab), z = lag(x$newvar_key_ab),
type = type_param, type = type_param,
ignore_I = ignore_I, ignore_I = ignore_I,
points_threshold = points_threshold, points_threshold = points_threshold,
info = info) info = info)
# with key antibiotics # with key antibiotics
x$newvar_first_isolate <- if_else(x$newvar_row_index_sorted >= row.start & x$newvar_first_isolate <- if_else(x$newvar_row_index_sorted >= row.start &
x$newvar_row_index_sorted <= row.end & x$newvar_row_index_sorted <= row.end &
x$newvar_genus_species != "" & x$newvar_genus_species != "" &
(x$other_pat_or_mo | x$more_than_episode_ago | x$other_key_ab), (x$other_pat_or_mo | x$more_than_episode_ago | x$other_key_ab),
TRUE, TRUE,
FALSE) FALSE)
} else { } else {
# no key antibiotics # no key antibiotics
x$newvar_first_isolate <- if_else(x$newvar_row_index_sorted >= row.start & x$newvar_first_isolate <- if_else(x$newvar_row_index_sorted >= row.start &
x$newvar_row_index_sorted <= row.end & x$newvar_row_index_sorted <= row.end &
x$newvar_genus_species != "" & x$newvar_genus_species != "" &
(x$other_pat_or_mo | x$more_than_episode_ago), (x$other_pat_or_mo | x$more_than_episode_ago),
TRUE, TRUE,
FALSE) FALSE)
} }
# first one as TRUE # first one as TRUE
@ -391,17 +391,17 @@ first_isolate <- function(x,
# handle empty microorganisms # handle empty microorganisms
if (any(x$newvar_mo == "UNKNOWN", na.rm = TRUE) & info == TRUE) { if (any(x$newvar_mo == "UNKNOWN", na.rm = TRUE) & info == TRUE) {
message(font_blue(paste0("NOTE: ", ifelse(include_unknown == TRUE, "Included ", "Excluded "), message(font_blue(paste0("NOTE: ", ifelse(include_unknown == TRUE, "Included ", "Excluded "),
format(sum(x$newvar_mo == "UNKNOWN", na.rm = TRUE), format(sum(x$newvar_mo == "UNKNOWN", na.rm = TRUE),
decimal.mark = decimal.mark, big.mark = big.mark), decimal.mark = decimal.mark, big.mark = big.mark),
" isolates with a microbial ID 'UNKNOWN' (column `", font_bold(col_mo), "`)"))) " isolates with a microbial ID 'UNKNOWN' (column `", font_bold(col_mo), "`)")))
} }
x[which(x$newvar_mo == "UNKNOWN"), "newvar_first_isolate"] <- include_unknown x[which(x$newvar_mo == "UNKNOWN"), "newvar_first_isolate"] <- include_unknown
# exclude all NAs # exclude all NAs
if (any(is.na(x$newvar_mo)) & info == TRUE) { if (any(is.na(x$newvar_mo)) & info == TRUE) {
message(font_blue(paste0("NOTE: Excluded ", format(sum(is.na(x$newvar_mo), na.rm = TRUE), message(font_blue(paste0("NOTE: Excluded ", format(sum(is.na(x$newvar_mo), na.rm = TRUE),
decimal.mark = decimal.mark, big.mark = big.mark), decimal.mark = decimal.mark, big.mark = big.mark),
" isolates with a microbial ID 'NA' (column `", font_bold(col_mo), "`)"))) " isolates with a microbial ID 'NA' (column `", font_bold(col_mo), "`)")))
} }
x[which(is.na(x$newvar_mo)), "newvar_first_isolate"] <- FALSE x[which(is.na(x$newvar_mo)), "newvar_first_isolate"] <- FALSE

View File

@ -102,14 +102,19 @@ like <- function(x, pattern, ignore.case = TRUE) {
as.integer(x) %in% base::grep(pattern, levels(x), ignore.case = FALSE, fixed = fixed) as.integer(x) %in% base::grep(pattern, levels(x), ignore.case = FALSE, fixed = fixed)
} else { } else {
tryCatch(base::grepl(pattern, x, ignore.case = FALSE, fixed = fixed), tryCatch(base::grepl(pattern, x, ignore.case = FALSE, fixed = fixed),
error = function(e) ifelse(grepl("Invalid regexp", e$message), error = function(e) {
# try with perl = TRUE: if (grepl("invalid reg(ular )?exp", e$message, ignore.case = TRUE)) {
return(base::grepl(pattern = pattern, x = x, # try with perl = TRUE:
ignore.case = FALSE, return(base::grepl(pattern = pattern,
fixed = fixed, x = x,
perl = TRUE)), ignore.case = FALSE,
# stop otherwise fixed = fixed,
stop(e$message))) perl = TRUE))
} else {
# stop otherwise
stop(e$message)
}
})
} }
} }

View File

@ -40,6 +40,11 @@ rsi_calc <- function(...,
data_vars <- dots2vars(...) data_vars <- dots2vars(...)
dots_df <- switch(1, ...) dots_df <- switch(1, ...)
if (is.data.frame(dots_df)) {
# make sure to remove all other classes like tibbles, data.tables, etc
dots_df <- as.data.frame(dots_df, stringsAsFactors = FALSE)
}
dots <- base::eval(base::substitute(base::alist(...))) dots <- base::eval(base::substitute(base::alist(...)))
stop_if(length(dots) == 0, "no variables selected", call = -2) stop_if(length(dots) == 0, "no variables selected", call = -2)
@ -50,6 +55,7 @@ rsi_calc <- function(...,
if (is.data.frame(dots_df)) { if (is.data.frame(dots_df)) {
# data.frame passed with other columns, like: example_isolates %>% proportion_S(AMC, GEN) # data.frame passed with other columns, like: example_isolates %>% proportion_S(AMC, GEN)
dots <- as.character(dots) dots <- as.character(dots)
# remove first element, it's the data.frame # remove first element, it's the data.frame
if (length(dots) == 1) { if (length(dots) == 1) {
@ -62,6 +68,10 @@ rsi_calc <- function(...,
# and the old rsi function, which has "df" as name of the first parameter # and the old rsi function, which has "df" as name of the first parameter
x <- dots_df x <- dots_df
} else { } else {
# get dots that are in column names already, and the ones that will be once evaluated using dots_df or global env
# this is to support susceptibility(example_isolates, AMC, dplyr::all_of(some_vector_with_AB_names))
dots <- c(dots[dots %in% colnames(dots_df)],
eval(parse(text = dots[!dots %in% colnames(dots_df)]), envir = dots_df, enclos = globalenv()))
dots_not_exist <- dots[!dots %in% colnames(dots_df)] dots_not_exist <- dots[!dots %in% colnames(dots_df)]
stop_if(length(dots_not_exist) > 0, "column(s) not found: ", paste0("'", dots_not_exist, "'", collapse = ", "), call = -2) stop_if(length(dots_not_exist) > 0, "column(s) not found: ", paste0("'", dots_not_exist, "'", collapse = ", "), call = -2)
x <- dots_df[, dots, drop = FALSE] x <- dots_df[, dots, drop = FALSE]
@ -72,10 +82,10 @@ rsi_calc <- function(...,
} else { } else {
# multiple variables passed without pipe, like: proportion_S(example_isolates$AMC, example_isolates$GEN) # multiple variables passed without pipe, like: proportion_S(example_isolates$AMC, example_isolates$GEN)
x <- NULL x <- NULL
try(x <- as.data.frame(dots), silent = TRUE) try(x <- as.data.frame(dots, stringsAsFactors = FALSE), silent = TRUE)
if (is.null(x)) { if (is.null(x)) {
# support for example_isolates %>% group_by(hospital_id) %>% summarise(amox = susceptibility(GEN, AMX)) # support for example_isolates %>% group_by(hospital_id) %>% summarise(amox = susceptibility(GEN, AMX))
x <- as.data.frame(list(...)) x <- as.data.frame(list(...), stringsAsFactors = FALSE)
} }
} }
@ -92,9 +102,9 @@ rsi_calc <- function(...,
rsi_integrity_check <- character(0) rsi_integrity_check <- character(0)
for (i in seq_len(ncol(x))) { for (i in seq_len(ncol(x))) {
# check integrity of columns: force rsi class # check integrity of columns: force rsi class
if (!is.rsi(x %>% pull(i))) { if (!is.rsi(x[, i, drop = TRUE])) {
rsi_integrity_check <- c(rsi_integrity_check, x %>% pull(i) %>% as.character()) rsi_integrity_check <- c(rsi_integrity_check, as.character(x[, i, drop = TRUE]))
x[, i] <- suppressWarnings(x %>% pull(i) %>% as.rsi()) # warning will be given later x[, i] <- suppressWarnings(as.rsi(x[, i, drop = TRUE])) # warning will be given later
print_warning <- TRUE print_warning <- TRUE
} }
} }

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="https://msberends.gitlab.io/AMR/index.html">AMR (for R)</a> <a class="navbar-link" href="https://msberends.gitlab.io/AMR/index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9022</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9022</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9022</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9022</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -43,7 +43,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a> <a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9022</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9022</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>
@ -229,13 +229,13 @@
<small>Source: <a href='https://gitlab.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small> <small>Source: <a href='https://gitlab.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div> </div>
<div id="amr-1209022" class="section level1"> <div id="amr-1209023" class="section level1">
<h1 class="page-header" data-toc-text="1.2.0.9022"> <h1 class="page-header" data-toc-text="1.2.0.9023">
<a href="#amr-1209022" class="anchor"></a>AMR 1.2.0.9022<small> Unreleased </small> <a href="#amr-1209023" class="anchor"></a>AMR 1.2.0.9023<small> Unreleased </small>
</h1> </h1>
<div id="last-updated-01-jul-2020" class="section level2"> <div id="last-updated-02-jul-2020" class="section level2">
<h2 class="hasAnchor"> <h2 class="hasAnchor">
<a href="#last-updated-01-jul-2020" class="anchor"></a><small>Last updated: 01-Jul-2020</small> <a href="#last-updated-02-jul-2020" class="anchor"></a><small>Last updated: 02-Jul-2020</small>
</h2> </h2>
<div id="new" class="section level3"> <div id="new" class="section level3">
<h3 class="hasAnchor"> <h3 class="hasAnchor">
@ -262,10 +262,10 @@
<h3 class="hasAnchor"> <h3 class="hasAnchor">
<a href="#changed" class="anchor"></a>Changed</h3> <a href="#changed" class="anchor"></a>Changed</h3>
<ul> <ul>
<li>Using unexisting columns in all <code>count_*()</code>, <code>proportion_*()</code>, <code><a href="../reference/proportion.html">susceptibility()</a></code> and <code><a href="../reference/proportion.html">resistance()</a></code> functions wil now return an error instead of dropping them silently</li> <li>Using unexisting columns in all <code>count_*()</code>, <code>proportion_*()</code>, <code><a href="../reference/proportion.html">susceptibility()</a></code> and <code><a href="../reference/proportion.html">resistance()</a></code> functions wil now return an error instead of dropping them silently. Using variables for column names (as well as <code><a href="https://dplyr.tidyverse.org/reference/reexports.html">dplyr::all_of()</a></code>) now works again.</li>
<li>Improvements for <code><a href="../reference/as.ab.html">as.ab()</a></code>: <li>Improvements for <code><a href="../reference/as.ab.html">as.ab()</a></code>:
<ul> <ul>
<li>Dramatic improvement of the algorithm behind <code><a href="../reference/as.ab.html">as.ab()</a></code>, making many more input errors translatable like from digitalised health care records, using too few or too many vowels or consonants and many more</li> <li>Dramatic improvement of the algorithm behind <code><a href="../reference/as.ab.html">as.ab()</a></code>, making many more input errors translatable, such as digitalised health care records, using too few or too many vowels or consonants and many more</li>
<li>Added progress bar</li> <li>Added progress bar</li>
<li>Fixed a bug where <code><a href="../reference/as.ab.html">as.ab()</a></code> would return an error on invalid input values</li> <li>Fixed a bug where <code><a href="../reference/as.ab.html">as.ab()</a></code> would return an error on invalid input values</li>
<li>The <code><a href="../reference/as.ab.html">as.ab()</a></code> function will now throw a note if more than 1 antimicrobial drug could be retrieved from a single input value.</li> <li>The <code><a href="../reference/as.ab.html">as.ab()</a></code> function will now throw a note if more than 1 antimicrobial drug could be retrieved from a single input value.</li>
@ -279,6 +279,7 @@
<li>Fixed a bug in <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> for when only one antibiotic was in the input data</li> <li>Fixed a bug in <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> for when only one antibiotic was in the input data</li>
<li>Changed the summary for class <code>&lt;mo&gt;</code>, to highlight the %SI vs. %R</li> <li>Changed the summary for class <code>&lt;mo&gt;</code>, to highlight the %SI vs. %R</li>
<li>Improved error handling, giving more useful info when functions return an error</li> <li>Improved error handling, giving more useful info when functions return an error</li>
<li>Any progress bar will now only show in interactive mode (i.e. not in R Markdown)</li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -10,7 +10,7 @@ articles:
WHONET: WHONET.html WHONET: WHONET.html
benchmarks: benchmarks.html benchmarks: benchmarks.html
resistance_predict: resistance_predict.html resistance_predict: resistance_predict.html
last_built: 2020-07-01T14:20Z last_built: 2020-07-02T19:12Z
urls: urls:
reference: https://msberends.gitlab.io/AMR/reference reference: https://msberends.gitlab.io/AMR/reference
article: https://msberends.gitlab.io/AMR/articles article: https://msberends.gitlab.io/AMR/articles

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>
@ -240,6 +240,7 @@
<span class='kw'>type</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"drug"</span>, <span class='st'>"dose"</span>, <span class='st'>"administration"</span>), <span class='kw'>type</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"drug"</span>, <span class='st'>"dose"</span>, <span class='st'>"administration"</span>),
<span class='kw'>collapse</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>collapse</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>thorough_search</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='no'>...</span> <span class='no'>...</span>
)</pre> )</pre>
@ -262,6 +263,10 @@
<th>translate_ab</th> <th>translate_ab</th>
<td><p>if <code>type = "drug"</code>: a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code>. Defaults to <code>FALSE</code>. Using <code>TRUE</code> is equal to using "name".</p></td> <td><p>if <code>type = "drug"</code>: a column name of the <a href='antibiotics.html'>antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href='ab_property.html'>ab_property()</a></code>. Defaults to <code>FALSE</code>. Using <code>TRUE</code> is equal to using "name".</p></td>
</tr> </tr>
<tr>
<th>thorough_search</th>
<td><p>logical to indicate whether the input must be extensively searched for misspelling and other faulty input values. Setting this to <code>TRUE</code> will take considerably more time than when using <code>FALSE</code>. At default, it will turn <code>TRUE</code> when all input elements contain a maximum of three words.</p></td>
</tr>
<tr> <tr>
<th>...</th> <th>...</th>
<td><p>parameters passed on to <code><a href='as.ab.html'>as.ab()</a></code></p></td> <td><p>parameters passed on to <code><a href='as.ab.html'>as.ab()</a></code></p></td>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9022</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -83,7 +83,7 @@ To improve the interpretation of the antibiogram before EUCAST rules are applied
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9022</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -84,7 +84,7 @@ This page contains a section for every lifecycle (with text borrowed from the af
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -82,7 +82,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9019</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.2.0.9023</span>
</span> </span>
</div> </div>

View File

@ -9,6 +9,7 @@ ab_from_text(
type = c("drug", "dose", "administration"), type = c("drug", "dose", "administration"),
collapse = NULL, collapse = NULL,
translate_ab = FALSE, translate_ab = FALSE,
thorough_search = NULL,
... ...
) )
} }
@ -21,6 +22,8 @@ ab_from_text(
\item{translate_ab}{if \code{type = "drug"}: a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}. Defaults to \code{FALSE}. Using \code{TRUE} is equal to using "name".} \item{translate_ab}{if \code{type = "drug"}: a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}. Defaults to \code{FALSE}. Using \code{TRUE} is equal to using "name".}
\item{thorough_search}{logical to indicate whether the input must be extensively searched for misspelling and other faulty input values. Setting this to \code{TRUE} will take considerably more time than when using \code{FALSE}. At default, it will turn \code{TRUE} when all input elements contain a maximum of three words.}
\item{...}{parameters passed on to \code{\link[=as.ab]{as.ab()}}} \item{...}{parameters passed on to \code{\link[=as.ab]{as.ab()}}}
} }
\value{ \value{

View File

@ -23,8 +23,14 @@ context("ab_from_text.R")
test_that("ab_from_text works", { test_that("ab_from_text works", {
skip_on_cran()
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds")[[1]], expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds")[[1]],
as.ab("Amoxicillin")) as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", thorough_search = TRUE)[[1]],
as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", thorough_search = FALSE)[[1]],
as.ab("Amoxicillin"))
expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", translate_ab = TRUE)[[1]], expect_identical(ab_from_text("28/03/2020 regular amoxicilliin 500mg po tds", translate_ab = TRUE)[[1]],
"Amoxicillin") "Amoxicillin")
expect_identical(ab_from_text("administered amoxi/clav and cipro", collapse = ", ")[[1]], expect_identical(ab_from_text("administered amoxi/clav and cipro", collapse = ", ")[[1]],