(v1.6.0.9008) unlike, bugfix for col_mo naming

This commit is contained in:
dr. M.S. (Matthijs) Berends 2021-04-23 09:59:36 +02:00
parent c6289c3fc3
commit 70b803dbb6
33 changed files with 269 additions and 137 deletions

View File

@ -1,6 +1,6 @@
Package: AMR
Version: 1.6.0.9007
Date: 2021-04-20
Version: 1.6.0.9008
Date: 2021-04-23
Title: Antimicrobial Resistance Data Analysis
Authors@R: c(
person(role = c("aut", "cre"),

View File

@ -142,6 +142,8 @@ S3method(unique,mo)
S3method(unique,rsi)
export("%like%")
export("%like_case%")
export("%unlike%")
export("%unlike_case%")
export(ab_atc)
export(ab_atc_group1)
export(ab_atc_group2)

16
NEWS.md
View File

@ -1,5 +1,5 @@
# AMR 1.6.0.9007
## <small>Last updated: 20 April 2021</small>
# AMR 1.6.0.9008
## <small>Last updated: 23 April 2021</small>
### New
* Function `custom_eucast_rules()` that brings support for custom AMR rules in `eucast_rules()`
@ -13,9 +13,19 @@
* Fix for minor translation errors
* Printing of microbial codes in a `data.frame` or `tibble` now gives a warning if the data contains old microbial codes (from a previous AMR package version)
* `first_isolate()` can now take a vector of values for `col_keyantibiotics` and can have an episode length of `Inf`
* `like()` (and `%like%`) now checks if `pattern` is a *valid* regular expression
* Extended the `like()` functions:
* Now checks if `pattern` is a *valid* regular expression
* Added `%unlike%` and `%unlike_case%` (as negations of the existing `%like%` and `%like_case%`). This greatly improves readability:
```r
if (!grepl("EUCAST", guideline)) ...
# same:
if (guideline %unlike% "EUCAST") ...
```
* Altered the RStudio addin, so it now iterates over `%like%` -> `%unlike%` -> `%like_case%` -> `%unlike_case%` if you keep pressing your keyboard shortcut
* Fixed an installation error on R-3.0
* Added `info` argument to `as.mo()` to turn on/off the progress bar
* Fixed a bug that `col_mo` for some functions (esp. `eucast_rules()` and `mdro()`) could not be column names of the `microorganisms` data set as it would throw an error
# AMR 1.6.0

View File

@ -71,7 +71,49 @@ addin_insert_in <- function() {
# No export, no Rd
addin_insert_like <- function() {
import_fn("insertText", "rstudioapi")(" %like% ")
# we want Shift + Ctrl/Cmd + L to iterate over %like%, %unlike%, %like_case%, and %unlike_case%
getActiveDocumentContext <- import_fn("getActiveDocumentContext", "rstudioapi")
insertText <- import_fn("insertText", "rstudioapi")
modifyRange <- import_fn("modifyRange", "rstudioapi")
document_range <- import_fn("document_range", "rstudioapi")
document_position <- import_fn("document_position", "rstudioapi")
context <- getActiveDocumentContext()
current_row <- context$selection[[1]]$range$end[1]
current_col <- context$selection[[1]]$range$end[2]
current_row_txt <- context$contents[current_row]
if (is.null(current_row) || current_row_txt %unlike% "%(un)?like") {
insertText(" %like% ")
return(invisible())
}
pos_preceded_by <- function(txt) {
if (tryCatch(substr(current_row_txt, current_col - nchar(trimws(txt, which = "right")), current_col) == trimws(txt, which = "right"),
error = function(e) FALSE)) {
return(TRUE)
}
tryCatch(substr(current_row_txt, current_col - nchar(txt), current_col) %like% paste0("^", txt),
error = function(e) FALSE)
}
replace_pos <- function(old, with) {
modifyRange(document_range(document_position(current_row, current_col - nchar(old)),
document_position(current_row, current_col)),
text = with,
id = context$id)
}
if (pos_preceded_by(" %like% ")) {
replace_pos(" %like% ", with = " %unlike% ")
} else if (pos_preceded_by(" %unlike% ")) {
replace_pos(" %unlike% ", with = " %like_case% ")
} else if (pos_preceded_by(" %like_case% ")) {
replace_pos(" %like_case% ", with = " %unlike_case% ")
} else if (pos_preceded_by(" %unlike_case% ")) {
replace_pos(" %unlike_case% ", with = " %like% ")
} else {
insertText(" %like% ")
}
}
check_dataset_integrity <- function() {
@ -234,8 +276,8 @@ stop_ifnot_installed <- function(package) {
vapply(FUN.VALUE = character(1), package, function(pkg)
tryCatch(get(".packageName", envir = asNamespace(pkg)),
error = function(e) {
if (package == "rstudioapi") {
stop("This function only works in RStudio.", call. = FALSE)
if (pkg == "rstudioapi") {
stop("This function only works in RStudio when using R >= 3.2.", call. = FALSE)
} else if (pkg != "base") {
stop("This requires the '", pkg, "' package.",
"\nTry to install it with: install.packages(\"", pkg, "\")",
@ -652,7 +694,7 @@ get_current_data <- function(arg_name, call) {
return(out)
}
}
if (as.double(R.Version()$major) + (as.double(R.Version()$minor) / 10) < 3.2) {
# R-3.0 and R-3.1 do not have an `x` element in the call stack, rendering this function useless
if (is.na(arg_name)) {
@ -660,6 +702,7 @@ get_current_data <- function(arg_name, call) {
warning_("this function can only be used in R >= 3.2", call = call)
return(data.frame())
} else {
# mimic a default R error, e.g. for example_isolates[which(mo_name() %like% "^ent"), ]
stop_("argument `", arg_name, "` is missing with no default", call = call)
}
}
@ -669,12 +712,17 @@ get_current_data <- function(arg_name, call) {
frms <- lapply(sys.frames(), function(el) {
if (not_set == TRUE && ".Generic" %in% names(el)) {
if (tryCatch(".data" %in% names(el) && is.data.frame(el$`.data`), error = function(e) FALSE)) {
# dplyr? - an element `.data` will be in the system call stack
# will be used in dplyr::select() (but not in dplyr::filter(), dplyr::mutate() or dplyr::summarise())
# - - - -
# dplyr
# - - - -
# an element `.data` will be in the system call stack when using dplyr::select()
# [but not when using dplyr::filter(), dplyr::mutate() or dplyr::summarise()]
not_set <<- FALSE
el$`.data`
} else if (tryCatch(any(c("x", "xx") %in% names(el)), error = function(e) FALSE)) {
# otherwise try base R:
# - - - -
# base R
# - - - -
# an element `x` will be in this environment for only cols, e.g. `example_isolates[, carbapenems()]`
# an element `xx` will be in this environment for rows + cols, e.g. `example_isolates[c(1:3), carbapenems()]`
if (tryCatch(is.data.frame(el$xx), error = function(e) FALSE)) {
@ -694,6 +742,7 @@ get_current_data <- function(arg_name, call) {
}
})
# lookup the matched frame and return its value: a data.frame
vars_df <- tryCatch(frms[[which(!vapply(FUN.VALUE = logical(1), frms, is.null))]], error = function(e) NULL)
if (is.data.frame(vars_df)) {
return(vars_df)
@ -1157,6 +1206,7 @@ lengths <- function(x, use.names = TRUE) {
if (as.double(R.Version()$major) + (as.double(R.Version()$minor) / 10) < 3.1) {
# R-3.0 does not contain these functions, set them here to prevent installation failure
# (required for extension of the <mic> class)
cospi <- function(...) 1
sinpi <- function(...) 1
tanpi <- function(...) 1

2
R/ab.R
View File

@ -389,7 +389,7 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
# first 5 except for cephalosporins, then first 7 (those cephalosporins all start quite the same!)
found <- suppressWarnings(as.ab(substr(x[i], 1, 5), initial_search = FALSE))
if (!is.na(found) && !ab_group(found, initial_search = FALSE) %like% "cephalosporins") {
if (!is.na(found) && ab_group(found, initial_search = FALSE) %unlike% "cephalosporins") {
x_new[i] <- note_if_more_than_one_found(found, i, from_text)
next
}

View File

@ -190,7 +190,7 @@ eucast_rules <- function(x,
}
x_deparsed <- deparse(substitute(x))
if (length(x_deparsed) > 1 || !all(x_deparsed %like% "[a-z]+")) {
if (length(x_deparsed) > 1 || any(x_deparsed %unlike% "[a-z]+")) {
x_deparsed <- "your_data"
}
@ -225,8 +225,6 @@ eucast_rules <- function(x,
if (is.null(col_mo)) {
col_mo <- search_type_in_df(x = x, type = "mo", info = info)
stop_if(is.null(col_mo), "`col_mo` must be set")
} else {
stop_ifnot(col_mo %in% colnames(x), "column '", col_mo, "' (`col_mo`) not found")
}
decimal.mark <- getOption("OutDec")
@ -420,8 +418,11 @@ eucast_rules <- function(x,
pm_distinct(`.rowid`, .keep_all = TRUE) %pm>%
as.data.frame(stringsAsFactors = FALSE)
x[, col_mo] <- as.mo(as.character(x[, col_mo, drop = TRUE]))
x <- x %pm>%
left_join_microorganisms(by = col_mo, suffix = c("_oldcols", ""))
# rename col_mo to prevent interference with joined columns
colnames(x)[colnames(x) == col_mo] <- ".col_mo"
col_mo <- ".col_mo"
# join to microorganisms data set
x <- left_join_microorganisms(x, by = col_mo, suffix = c("_oldcols", ""))
x$gramstain <- mo_gramstain(x[, col_mo, drop = TRUE], language = NULL)
x$genus_species <- paste(x$genus, x$species)
if (info == TRUE & NROW(x) > 10000) {
@ -480,7 +481,6 @@ eucast_rules <- function(x,
extra_indent = 6))
}
run_changes <- edit_rsi(x = x,
col_mo = col_mo,
to = "R",
rule = c(rule_current, "Other rules", "",
paste0("Non-EUCAST: AMR package v", utils::packageDescription("AMR")$Version)),
@ -515,7 +515,6 @@ eucast_rules <- function(x,
extra_indent = 6))
}
run_changes <- edit_rsi(x = x,
col_mo = col_mo,
to = "S",
rule = c(rule_current, "Other rules", "",
paste0("Non-EUCAST: AMR package v", utils::packageDescription("AMR")$Version)),
@ -569,19 +568,19 @@ eucast_rules <- function(x,
# filter on user-set guideline versions ----
if (any(c("all", "breakpoints") %in% rules)) {
eucast_rules_df <- subset(eucast_rules_df,
!reference.rule_group %like% "breakpoint" |
reference.rule_group %unlike% "breakpoint" |
(reference.rule_group %like% "breakpoint" & reference.version == version_breakpoints))
}
if (any(c("all", "expert") %in% rules)) {
eucast_rules_df <- subset(eucast_rules_df,
!reference.rule_group %like% "expert" |
reference.rule_group %unlike% "expert" |
(reference.rule_group %like% "expert" & reference.version == version_expertrules))
}
# filter out AmpC de-repressed cephalosporin-resistant mutants ----
# cefotaxime, ceftriaxone, ceftazidime
if (is.null(ampc_cephalosporin_resistance) || isFALSE(ampc_cephalosporin_resistance)) {
eucast_rules_df <- subset(eucast_rules_df,
!reference.rule %like% "ampc")
reference.rule %unlike% "ampc")
} else {
if (isTRUE(ampc_cephalosporin_resistance)) {
ampc_cephalosporin_resistance <- "R"
@ -627,7 +626,7 @@ eucast_rules <- function(x,
if (info == TRUE) {
# Print EUCAST intro ------------------------------------------------------
if (!rule_group_current %like% "other" & eucast_notification_shown == FALSE) {
if (rule_group_current %unlike% "other" & eucast_notification_shown == FALSE) {
cat(
paste0("\n", font_grey(strrep("-", 0.95 * options()$width)), "\n",
word_wrap("Rules by the ", font_bold("European Committee on Antimicrobial Susceptibility Testing (EUCAST)")), "\n",
@ -750,7 +749,6 @@ eucast_rules <- function(x,
# Apply rule on data ------------------------------------------------------
# this will return the unique number of changes
run_changes <- edit_rsi(x = x,
col_mo = col_mo,
to = target_value,
rule = c(rule_text, rule_group_current, rule_current,
ifelse(rule_group_current %like% "breakpoint",
@ -803,7 +801,6 @@ eucast_rules <- function(x,
warned <- FALSE
}
run_changes <- edit_rsi(x = x,
col_mo = col_mo,
to = target_value,
rule = c(rule_text,
"Custom EUCAST rules",
@ -949,13 +946,12 @@ eucast_rules <- function(x,
}
# helper function for editing the table ----
edit_rsi <- function(x,
col_mo,
to,
rule,
edit_rsi <- function(x,
to,
rule,
rows,
cols,
last_verbose_info,
last_verbose_info,
original_data,
warned,
info,

View File

@ -425,7 +425,7 @@ find_ab_group <- function(ab_class) {
find_ab_names <- function(ab_group, n = 3) {
ab_group <- gsub("[^a-zA-Z0-9]", ".*", ab_group)
drugs <- antibiotics[which(antibiotics$group %like% ab_group & !antibiotics$ab %like% "[0-9]$"), ]$name
drugs <- antibiotics[which(antibiotics$group %like% ab_group & antibiotics$ab %unlike% "[0-9]$"), ]$name
paste0(sort(ab_name(sample(drugs, size = min(n, length(drugs)), replace = FALSE),
tolower = TRUE, language = NULL)),
collapse = ", ")

View File

@ -497,10 +497,10 @@ first_isolate <- function(x = NULL,
n_found <- sum(x$newvar_first_isolate, na.rm = TRUE)
p_found_total <- percentage(n_found / nrow(x[which(!is.na(x$newvar_mo)), , drop = FALSE]), digits = 1)
p_found_scope <- percentage(n_found / scope.size, digits = 1)
if (!p_found_total %like% "[.]") {
if (p_found_total %unlike% "[.]") {
p_found_total <- gsub("%", ".0%", p_found_total, fixed = TRUE)
}
if (!p_found_scope %like% "[.]") {
if (p_found_scope %unlike% "[.]") {
p_found_scope <- gsub("%", ".0%", p_found_scope, fixed = TRUE)
}
# mark up number of found

View File

@ -279,7 +279,7 @@ check_groups_before_join <- function(x, fn) {
if (is.data.frame(x) && !is.null(attributes(x)$groups)) {
x <- pm_ungroup(x)
attr(x, "groups") <- NULL
class(x) <- class(x)[!class(x) %like% "group"]
class(x) <- class(x)[class(x) %unlike% "group"]
warning_("Groups are dropped, since the ", fn, "() function relies on merge() from base R.", call = FALSE)
}
x

View File

@ -136,7 +136,7 @@ key_antibiotics <- function(x = NULL,
x <- tryCatch(get_current_data(arg_name = "x", call = -2), error = function(e) x)
}
meet_criteria(x, allow_class = "data.frame") # also checks dimensions to be >0
meet_criteria(col_mo, allow_class = "character", has_length = 1, allow_NULL = TRUE, allow_NA = TRUE)
meet_criteria(col_mo, allow_class = "character", has_length = 1, allow_NULL = TRUE, allow_NA = TRUE, is_in = colnames(x))
meet_criteria(universal_1, allow_class = "character", has_length = 1, allow_NULL = TRUE, allow_NA = TRUE)
meet_criteria(universal_2, allow_class = "character", has_length = 1, allow_NULL = TRUE, allow_NA = TRUE)
meet_criteria(universal_3, allow_class = "character", has_length = 1, allow_NULL = TRUE, allow_NA = TRUE)
@ -173,8 +173,6 @@ key_antibiotics <- function(x = NULL,
# -- mo
if (is.null(col_mo)) {
col_mo <- search_type_in_df(x = x, type = "mo")
} else {
stop_ifnot(col_mo %in% colnames(x), "column '", col_mo, "' (`col_mo`) not found")
}
if (is.null(col_mo)) {
warning_("No column found for `col_mo`, ignoring antimicrobial agents set for Gram-negative and Gram-positive bacteria", call = FALSE)

View File

@ -35,13 +35,13 @@
#' @rdname like
#' @export
#' @details
#' These [like()] and `%like%` functions:
#' * Are case-insensitive (use `%like_case%` for case-sensitive matching)
#' These [like()] and `%like%`/`%unlike%` functions:
#' * Are case-insensitive (use `%like_case%`/`%unlike_case%` for case-sensitive matching)
#' * Support multiple patterns
#' * Check if `pattern` is a valid regular expression and sets `fixed = TRUE` if not, to greatly improve speed (vectorised over `pattern`)
#' * Always use compatibility with Perl unless `fixed = TRUE`, to greatly improve speed
#'
#' Using RStudio? The text `%like%` can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like `Ctrl+Shift+L` or `Cmd+Shift+L` (see `Tools` > `Modify Keyboard Shortcuts...`).
#' Using RStudio? The `%like%`/`%unlike%` functions can also be directly inserted in your code from the Addins menu and can have its own keyboard shortcut like `Shift+Ctrl+L` or `Shift+Cmd+L` (see menu `Tools` > `Modify Keyboard Shortcuts...`). If you keep pressing your shortcut, the inserted text will be iterated over `%like%` -> `%unlike%` -> `%like_case%` -> `%unlike_case%`.
#' @source Idea from the [`like` function from the `data.table` package](https://github.com/Rdatatable/data.table/blob/ec1259af1bf13fc0c96a1d3f9e84d55d8106a9a4/R/like.R), although altered as explained in *Details*.
#' @seealso [grepl()]
#' @inheritSection AMR Read more on Our Website!
@ -58,18 +58,25 @@
#' b <- c( "case", "diff", "yet")
#' a %like% b
#' #> TRUE TRUE TRUE
#' a %unlike% b
#' #> FALSE FALSE FALSE
#'
#' a[1] %like% b
#' #> TRUE FALSE FALSE
#' a %like% b[1]
#' #> TRUE FALSE FALSE
#'
#' # get isolates whose name start with 'Ent' or 'ent'
#' example_isolates[which(mo_name(example_isolates$mo) %like% "^ent"), ]
#' \donttest{
#' # faster way, only works in R 3.2 and later:
#' example_isolates[which(mo_name() %like% "^ent"), ]
#'
#' if (require("dplyr")) {
#' example_isolates %>%
#' filter(mo_name() %like% "^ent")
#' }
#' }
like <- function(x, pattern, ignore.case = TRUE) {
meet_criteria(x, allow_NA = TRUE)
meet_criteria(pattern, allow_NA = FALSE)
@ -122,6 +129,14 @@ like <- function(x, pattern, ignore.case = TRUE) {
like(x, pattern, ignore.case = TRUE)
}
#' @rdname like
#' @export
"%unlike%" <- function(x, pattern) {
meet_criteria(x, allow_NA = TRUE)
meet_criteria(pattern, allow_NA = FALSE)
!like(x, pattern, ignore.case = TRUE)
}
#' @rdname like
#' @export
"%like_case%" <- function(x, pattern) {
@ -129,3 +144,11 @@ like <- function(x, pattern, ignore.case = TRUE) {
meet_criteria(pattern, allow_NA = FALSE)
like(x, pattern, ignore.case = FALSE)
}
#' @rdname like
#' @export
"%unlike_case%" <- function(x, pattern) {
meet_criteria(x, allow_NA = TRUE)
meet_criteria(pattern, allow_NA = FALSE)
!like(x, pattern, ignore.case = FALSE)
}

View File

@ -311,7 +311,6 @@ mdro <- function(x = NULL,
col_mo <- "mo"
}
stop_if(is.null(col_mo), "`col_mo` must be set")
stop_ifnot(col_mo %in% colnames(x), "column '", col_mo, "' (`col_mo`) not found")
if (guideline$code == "cmi2012") {
guideline$name <- "Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance."
@ -761,7 +760,11 @@ mdro <- function(x = NULL,
row_filter <- x[which(row_filter), "row_number", drop = TRUE]
rows <- rows[rows %in% row_filter]
x[rows, "MDRO"] <<- to
x[rows, "reason"] <<- paste0(any_all, " of the required antibiotics ", ifelse(any_all == "any", "is", "are"), " R")
x[rows, "reason"] <<- paste0(any_all,
" of the required antibiotics ",
ifelse(any_all == "any", "is", "are"),
" R",
ifelse(!isTRUE(combine_SI), " or I", ""))
}
}
trans_tbl2 <- function(txt, rows, lst) {
@ -814,6 +817,9 @@ mdro <- function(x = NULL,
}
x[, col_mo] <- as.mo(as.character(x[, col_mo, drop = TRUE]))
# rename col_mo to prevent interference with joined columns
colnames(x)[colnames(x) == col_mo] <- ".col_mo"
col_mo <- ".col_mo"
# join to microorganisms data set
x <- left_join_microorganisms(x, by = col_mo)
x$MDRO <- ifelse(!is.na(x$genus), 1, NA_integer_)
@ -1027,7 +1033,10 @@ mdro <- function(x = NULL,
# PDR (=4): all agents are R
x[which(x$classes_affected == 999 & x$classes_in_guideline == x$classes_available), "MDRO"] <- 4
if (verbose == TRUE) {
x[which(x$MDRO == 4), "reason"] <- paste("all antibiotics in all", x$classes_in_guideline[which(x$MDRO == 4)], "classes were tested R or I")
x[which(x$MDRO == 4), "reason"] <- paste("all antibiotics in all",
x$classes_in_guideline[which(x$MDRO == 4)],
"classes were tested R",
ifelse(!isTRUE(combine_SI), " or I", ""))
}
# not enough classes available
@ -1390,7 +1399,12 @@ mdro <- function(x = NULL,
# some more info on negative results
if (verbose == TRUE) {
if (guideline$code == "cmi2012") {
x[which(x$MDRO == 1 & !is.na(x$classes_affected)), "reason"] <- paste0(x$classes_affected[which(x$MDRO == 1 & !is.na(x$classes_affected))], " of ", x$classes_available[which(x$MDRO == 1 & !is.na(x$classes_affected))], " available classes contain R or I (3 required for MDR)")
x[which(x$MDRO == 1 & !is.na(x$classes_affected)), "reason"] <- paste0(x$classes_affected[which(x$MDRO == 1 & !is.na(x$classes_affected))],
" of ",
x$classes_available[which(x$MDRO == 1 & !is.na(x$classes_affected))],
" available classes contain R",
ifelse(!isTRUE(combine_SI), " or I", ""),
" (3 required for MDR)")
} else {
x[which(x$MDRO == 1), "reason"] <- "too few antibiotics are R"
}
@ -1431,8 +1445,10 @@ mdro <- function(x = NULL,
}
if (verbose == TRUE) {
colnames(x)[colnames(x) == col_mo] <- "microorganism"
x$microorganism <- mo_name(x$microorganism, language = NULL)
x[, c("row_number",
col_mo,
"microorganism",
"MDRO",
"reason",
"columns_nonsusceptible"),

View File

@ -133,7 +133,7 @@ as.mic <- function(x, na.rm = FALSE) {
# keep only one zero before dot
x <- gsub("0+[.]", "0.", x, perl = TRUE)
# starting 00 is probably 0.0 if there's no dot yet
x[!x %like% "[.]"] <- gsub("^00", "0.0", x[!x %like% "[.]"])
x[x %unlike% "[.]"] <- gsub("^00", "0.0", x[!x %like% "[.]"])
# remove last zeroes
x <- gsub("([.].?)0+$", "\\1", x, perl = TRUE)
x <- gsub("(.*[.])0+$", "\\10", x, perl = TRUE)

12
R/mo.R
View File

@ -708,7 +708,7 @@ exec_as.mo <- function(x,
# check for very small input, but ignore the O antigens of E. coli
if (nchar(gsub("[^a-zA-Z]", "", x_trimmed[i])) < 3
& !toupper(x_backup_without_spp[i]) %like_case% "O?(26|103|104|104|111|121|145|157)") {
& toupper(x_backup_without_spp[i]) %unlike_case% "O?(26|103|104|104|111|121|145|157)") {
# fewer than 3 chars and not looked for species, add as failure
x[i] <- lookup(mo == "UNKNOWN")
if (initial_search == TRUE) {
@ -860,7 +860,7 @@ exec_as.mo <- function(x,
x[i] <- lookup(genus == "Salmonella", uncertainty = -1)
next
} else if (x_backup[i] %like_case% "[sS]almonella [A-Z][a-z]+ ?.*" &
!x_backup[i] %like% "t[iy](ph|f)[iy]") {
x_backup[i] %unlike% "t[iy](ph|f)[iy]") {
# Salmonella with capital letter species like "Salmonella Goettingen" - they're all S. enterica
# except for S. typhi, S. paratyphi, S. typhimurium
x[i] <- lookup(fullname == "Salmonella enterica", uncertainty = -1)
@ -916,7 +916,7 @@ exec_as.mo <- function(x,
# FIRST TRY FULLNAMES AND CODES ----
# if only genus is available, return only genus
if (all(!c(x[i], b.x_trimmed) %like_case% " ")) {
if (all(c(x[i], b.x_trimmed) %unlike_case% " ")) {
found <- lookup(fullname_lower %in% c(h.x_species, i.x_trimmed_species),
haystack = data_to_check)
if (!is.na(found)) {
@ -1123,8 +1123,8 @@ exec_as.mo <- function(x,
if (isTRUE(debug)) {
cat(font_bold("\n[ UNCERTAINTY LEVEL", now_checks_for_uncertainty_level, "] (3) look for genus only, part of name\n"))
}
if (nchar(g.x_backup_without_spp) > 4 & !b.x_trimmed %like_case% " ") {
if (!b.x_trimmed %like_case% "^[A-Z][a-z]+") {
if (nchar(g.x_backup_without_spp) > 4 & b.x_trimmed %unlike_case% " ") {
if (b.x_trimmed %unlike_case% "^[A-Z][a-z]+") {
if (isTRUE(debug)) {
message("Running '", paste(b.x_trimmed, "species"), "'")
}
@ -1268,7 +1268,7 @@ exec_as.mo <- function(x,
stringsAsFactors = FALSE)
return(found)
}
if (b.x_trimmed %like_case% "(fungus|fungi)" & !b.x_trimmed %like_case% "fungiphrya") {
if (b.x_trimmed %like_case% "(fungus|fungi)" & b.x_trimmed %unlike_case% "fungiphrya") {
found <- "F_FUNGUS"
found_result <- found
found <- lookup(mo == found)

View File

@ -688,7 +688,7 @@ plot_prepare_table <- function(x, expand) {
}
plot_name_of_I <- function(guideline) {
if (!guideline %like% "CLSI" && as.double(gsub("[^0-9]+", "", guideline)) >= 2019) {
if (guideline %unlike% "CLSI" && as.double(gsub("[^0-9]+", "", guideline)) >= 2019) {
# interpretation since 2019
"Incr. exposure"
} else {

View File

@ -265,7 +265,7 @@ as.rsi.default <- function(x, ...) {
} else if (!all(is.na(x)) && !identical(levels(x), c("S", "I", "R"))) {
if (!any(x %like% "(R|S|I)", na.rm = TRUE)) {
if (all(x %unlike% "(R|S|I)", na.rm = TRUE)) {
# check if they are actually MICs or disks
if (all_valid_mics(x)) {
warning_("The input seems to be MIC values. Transform them with `as.mic()` before running `as.rsi()` to interpret them.")
@ -683,7 +683,7 @@ get_guideline <- function(guideline, reference_data) {
if (guideline_param %in% c("CLSI", "EUCAST")) {
guideline_param <- rev(sort(subset(reference_data, guideline %like% guideline_param)$guideline))[1L]
}
if (!guideline_param %like% " ") {
if (guideline_param %unlike% " ") {
# like 'EUCAST2020', should be 'EUCAST 2020'
guideline_param <- gsub("([a-z]+)([0-9]+)", "\\1 \\2", guideline_param, ignore.case = TRUE)
}
@ -776,7 +776,7 @@ exec_as.rsi <- function(method,
any_is_intrinsic_resistant <- any_is_intrinsic_resistant | is_intrinsic_r
if (isTRUE(add_intrinsic_resistance) & is_intrinsic_r) {
if (!guideline_coerced %like% "EUCAST") {
if (guideline_coerced %unlike% "EUCAST") {
if (message_not_thrown_before("as.rsi2")) {
warning_("Using 'add_intrinsic_resistance' is only useful when using EUCAST guidelines, since the rules for intrinsic resistance are based on EUCAST.", call = FALSE)
remember_thrown_message("as.rsi2")

Binary file not shown.

View File

@ -136,8 +136,8 @@ read_EUCAST <- function(sheet, file, guideline_name) {
disk_R = ifelse(has_zone_diameters, G, NA_character_)) %>%
filter(!is.na(drug),
!(is.na(MIC_S) & is.na(MIC_R) & is.na(disk_S) & is.na(disk_R)),
!MIC_S %like% "(MIC|S ≤|note)",
!MIC_S %like% "^[-]",
MIC_S %unlike% "(MIC|S ≤|note)",
MIC_S %unlike% "^[-]",
drug != MIC_S,) %>%
mutate(administration = case_when(drug %like% "[( ]oral" ~ "oral",
drug %like% "[( ]iv" ~ "iv",

View File

@ -114,8 +114,8 @@ abx_atc2 <- ab_old %>%
filter(!atc %in% abx_atc1$atc,
is.na(ears_net),
!is.na(atc_group1),
!atc_group1 %like% ("virus|vaccin|viral|immun"),
!official %like% "(combinations| with )") %>%
atc_group1 %unlike% ("virus|vaccin|viral|immun"),
official %unlike% "(combinations| with )") %>%
mutate(ab = NA_character_) %>%
as.data.frame(stringsAsFactors = FALSE) %>%
select(ab, atc, name = official)

View File

@ -382,7 +382,7 @@ MOs <- MOs %>%
# what characters are in the fullnames?
table(sort(unlist(strsplit(x = paste(MOs$fullname, collapse = ""), split = ""))))
MOs %>% filter(!fullname %like% "^[a-z ]+$") %>% arrange(fullname) %>% View()
MOs %>% filter(fullname %unlike% "^[a-z ]+$") %>% arrange(fullname) %>% View()
table(MOs$kingdom, MOs$rank)
table(AMR::microorganisms$kingdom, AMR::microorganisms$rank)

View File

@ -9,9 +9,9 @@ files <- xml2::read_html(paste0("https://github.com/nathaneastwood/poorman/tree/
# get full URLs of all raw R files
files <- sort(paste0("https://raw.githubusercontent.com", gsub("blob/", "", files[files %like% "/R/.*.R$"])))
# remove files with only pkg specific code
files <- files[!files %like% "(zzz|init)[.]R$"]
files <- files[files %unlike% "(zzz|init)[.]R$"]
# also, there's a lot of functions we don't use
files <- files[!files %like% "(slice|glimpse|recode|replace_na|coalesce)[.]R$"]
files <- files[files %unlike% "(slice|glimpse|recode|replace_na|coalesce)[.]R$"]
# add our prepend file, containing info about the source of the data
intro <- readLines("data-raw/poorman_prepend.R")

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="https://msberends.github.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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>

View File

@ -42,7 +42,7 @@
</button>
<span class="navbar-brand">
<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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>
@ -236,13 +236,13 @@
<small>Source: <a href='https://github.com/msberends/AMR/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div>
<div id="amr-1609007" class="section level1">
<h1 class="page-header" data-toc-text="1.6.0.9007">
<a href="#amr-1609007" class="anchor"></a>AMR 1.6.0.9007<small> Unreleased </small>
<div id="amr-1609008" class="section level1">
<h1 class="page-header" data-toc-text="1.6.0.9008">
<a href="#amr-1609008" class="anchor"></a>AMR 1.6.0.9008<small> Unreleased </small>
</h1>
<div id="last-updated-20-april-2021" class="section level2">
<div id="last-updated-23-april-2021" class="section level2">
<h2 class="hasAnchor">
<a href="#last-updated-20-april-2021" class="anchor"></a><small>Last updated: 20 April 2021</small>
<a href="#last-updated-23-april-2021" class="anchor"></a><small>Last updated: 23 April 2021</small>
</h2>
<div id="new" class="section level3">
<h3 class="hasAnchor">
@ -270,10 +270,23 @@
<li>
<code><a href="../reference/first_isolate.html">first_isolate()</a></code> can now take a vector of values for <code>col_keyantibiotics</code> and can have an episode length of <code>Inf</code>
</li>
<li>Extended the <code><a href="../reference/like.html">like()</a></code> functions:
<ul>
<li><p>Now checks if <code>pattern</code> is a <em>valid</em> regular expression</p></li>
<li>
<code><a href="../reference/like.html">like()</a></code> (and <code><a href="../reference/like.html">%like%</a></code>) now checks if <code>pattern</code> is a <em>valid</em> regular expression</li>
<p>Added <code><a href="../reference/like.html">%unlike%</a></code> and <code><a href="../reference/like.html">%unlike_case%</a></code> (as negations of the existing <code><a href="../reference/like.html">%like%</a></code> and <code><a href="../reference/like.html">%like_case%</a></code>). This greatly improves readability:</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="kw">if</span> <span class="op">(</span><span class="op">!</span><span class="fu"><a href="https://rdrr.io/r/base/grep.html">grepl</a></span><span class="op">(</span><span class="st">"EUCAST"</span>, <span class="va">guideline</span><span class="op">)</span><span class="op">)</span> <span class="va">...</span>
<span class="co"># same:</span>
<span class="kw">if</span> <span class="op">(</span><span class="va">guideline</span> <span class="op">%unlike%</span> <span class="st">"EUCAST"</span><span class="op">)</span> <span class="va">...</span></code></pre></div>
</li>
<li><p>Altered the RStudio addin, so it now iterates over <code><a href="../reference/like.html">%like%</a></code> -&gt; <code><a href="../reference/like.html">%unlike%</a></code> -&gt; <code><a href="../reference/like.html">%like_case%</a></code> -&gt; <code><a href="../reference/like.html">%unlike_case%</a></code> if you keep pressing your keyboard shortcut</p></li>
</ul>
</li>
<li>Fixed an installation error on R-3.0</li>
<li>Added <code>info</code> argument to <code><a href="../reference/as.mo.html">as.mo()</a></code> to turn on/off the progress bar</li>
<li>Fixed a bug that <code>col_mo</code> for some functions (esp. <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> and <code><a href="../reference/mdro.html">mdro()</a></code>) could not be column names of the <code>microorganisms</code> data set as it would throw an error</li>
</ul>
</div>
</div>
@ -307,7 +320,7 @@
</li>
<li>
<p>Functions <code><a href="../reference/antibiotic_class_selectors.html">oxazolidinones()</a></code> (an antibiotic selector function) and <code><a href="../reference/filter_ab_class.html">filter_oxazolidinones()</a></code> (an antibiotic filter function) to select/filter on e.g. linezolid and tedizolid</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
<span class="va">x</span> <span class="op">&lt;-</span> <span class="va">example_isolates</span> <span class="op">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span><span class="op">(</span><span class="va">date</span>, <span class="va">hospital_id</span>, <span class="fu"><a href="../reference/antibiotic_class_selectors.html">oxazolidinones</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span>
@ -320,7 +333,7 @@
<li><p><code>ggplot()</code> generics for classes <code>&lt;mic&gt;</code> and <code>&lt;disk&gt;</code></p></li>
<li>
<p>Function <code><a href="../reference/mo_property.html">mo_is_yeast()</a></code>, which determines whether a microorganism is a member of the taxonomic class Saccharomycetes or the taxonomic order Saccharomycetales:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/mo_property.html">mo_kingdom</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"Aspergillus"</span>, <span class="st">"Candida"</span><span class="op">)</span><span class="op">)</span>
<span class="co">#&gt; [1] "Fungi" "Fungi"</span>
@ -332,7 +345,7 @@
<span class="va">example_isolates</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/which.html">which</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_is_yeast</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span>, <span class="op">]</span> <span class="co"># base R</span>
<span class="va">example_isolates</span> <span class="op">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_is_yeast</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span> <span class="co"># dplyr</span></code></pre></div>
<p>The <code><a href="../reference/mo_property.html">mo_type()</a></code> function has also been updated to reflect this change:</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/mo_property.html">mo_type</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"Aspergillus"</span>, <span class="st">"Candida"</span><span class="op">)</span><span class="op">)</span>
<span class="co"># [1] "Fungi" "Yeasts"</span>
@ -342,7 +355,7 @@
<li><p>Added Pretomanid (PMD, J04AK08) to the <code>antibiotics</code> data set</p></li>
<li>
<p>MIC values (see <code><a href="../reference/as.mic.html">as.mic()</a></code>) can now be used in any mathematical processing, such as usage inside functions <code><a href="https://rdrr.io/r/base/Extremes.html">min()</a></code>, <code><a href="https://rdrr.io/r/base/Extremes.html">max()</a></code>, <code><a href="https://rdrr.io/r/base/range.html">range()</a></code>, and with binary operators (<code><a href="https://rdrr.io/r/base/Arithmetic.html">+</a></code>, <code><a href="https://rdrr.io/r/base/Arithmetic.html">-</a></code>, etc.). This allows for easy distribution analysis and fast filtering on MIC values:</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/random.html">random_mic</a></span><span class="op">(</span><span class="fl">10</span><span class="op">)</span>
<span class="va">x</span>
@ -426,7 +439,7 @@
<ul>
<li>
<p>Functions <code><a href="../reference/get_episode.html">get_episode()</a></code> and <code><a href="../reference/get_episode.html">is_new_episode()</a></code> to determine (patient) episodes which are not necessarily based on microorganisms. The <code><a href="../reference/get_episode.html">get_episode()</a></code> function returns the index number of the episode per group, while the <code><a href="../reference/get_episode.html">is_new_episode()</a></code> function returns values <code>TRUE</code>/<code>FALSE</code> to indicate whether an item in a vector is the start of a new episode. They also support <code>dplyr</code>s grouping (i.e. using <code><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by()</a></code>):</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
<span class="va">example_isolates</span> <span class="op">%&gt;%</span>
@ -480,7 +493,7 @@
<code><a href="../reference/mdro.html">mdr_cmi2012()</a></code>,</li>
<li><code><a href="../reference/mdro.html">eucast_exceptional_phenotypes()</a></code></li>
</ul>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># to select first isolates that are Gram-negative </span>
<span class="co"># and view results of cephalosporins and aminoglycosides:</span>
@ -492,7 +505,7 @@
</li>
<li>
<p>For antibiotic selection functions (such as <code><a href="../reference/antibiotic_class_selectors.html">cephalosporins()</a></code>, <code><a href="../reference/antibiotic_class_selectors.html">aminoglycosides()</a></code>) to select columns based on a certain antibiotic group, the dependency on the <code>tidyselect</code> package was removed, meaning that they can now also be used without the need to have this package installed and now also work in base R function calls (they rely on R 3.2 or later):</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># above example in base R:</span>
<span class="va">example_isolates</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/which.html">which</a></span><span class="op">(</span><span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span><span class="op">(</span><span class="op">)</span> <span class="op">&amp;</span> <span class="fu"><a href="../reference/mo_property.html">mo_is_gram_negative</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span>,
@ -543,7 +556,7 @@
<li>
<p>Data set <code>intrinsic_resistant</code>. This data set contains all bug-drug combinations where the bug is intrinsic resistant to the drug according to the latest EUCAST insights. It contains just two columns: <code>microorganism</code> and <code>antibiotic</code>.</p>
<p>Curious about which enterococci are actually intrinsic resistant to vancomycin?</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR/">AMR</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
@ -566,7 +579,7 @@
<ul>
<li>
<p>Support for using <code>dplyr</code>s <code><a href="https://dplyr.tidyverse.org/reference/across.html">across()</a></code> to interpret MIC values or disk zone diameters, which also automatically determines the column with microorganism names or codes.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># until dplyr 1.0.0</span>
<span class="va">your_data</span> <span class="op">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_if</a></span><span class="op">(</span><span class="va">is.mic</span>, <span class="va">as.rsi</span><span class="op">)</span>
@ -584,7 +597,7 @@
</li>
<li>
<p>Added intelligent data cleaning to <code><a href="../reference/as.disk.html">as.disk()</a></code>, so numbers can also be extracted from text and decimal numbers will always be rounded up:</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/as.disk.html">as.disk</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"disk zone: 23.4 mm"</span>, <span class="fl">23.4</span><span class="op">)</span><span class="op">)</span>
<span class="co">#&gt; Class &lt;disk&gt;</span>
@ -645,7 +658,7 @@
<li><p>Function <code><a href="../reference/ab_from_text.html">ab_from_text()</a></code> 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 <code><a href="../reference/as.ab.html">as.ab()</a></code> internally</p></li>
<li>
<p><a href="https://tidyselect.r-lib.org/reference/language.html">Tidyverse selection helpers</a> for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows selection helpers, like <code><a href="https://dplyr.tidyverse.org/reference/select.html">dplyr::select()</a></code> and <code><a href="https://tidyr.tidyverse.org/reference/pivot_longer.html">tidyr::pivot_longer()</a></code>:</p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
@ -834,7 +847,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Fixed important floating point error for some MIC comparisons in EUCAST 2020 guideline</p></li>
<li>
<p>Interpretation from MIC values (and disk zones) to R/SI can now be used with <code><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at()</a></code> of the <code>dplyr</code> package:</p>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">yourdata</span> <span class="op">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at</a></span><span class="op">(</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span><span class="op">(</span><span class="va">antibiotic1</span><span class="op">:</span><span class="va">antibiotic25</span><span class="op">)</span>, <span class="va">as.rsi</span>, mo <span class="op">=</span> <span class="st">"E. coli"</span><span class="op">)</span>
@ -863,7 +876,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>Support for LOINC codes in the <code>antibiotics</code> data set. Use <code><a href="../reference/ab_property.html">ab_loinc()</a></code> to retrieve LOINC codes, or use a LOINC code for input in any <code>ab_*</code> function:</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/ab_property.html">ab_loinc</a></span><span class="op">(</span><span class="st">"ampicillin"</span><span class="op">)</span>
<span class="co">#&gt; [1] "21066-6" "3355-5" "33562-0" "33919-2" "43883-8" "43884-6" "87604-5"</span>
@ -874,7 +887,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
<li>
<p>Support for SNOMED CT codes in the <code>microorganisms</code> data set. Use <code><a href="../reference/mo_property.html">mo_snomed()</a></code> to retrieve SNOMED codes, or use a SNOMED code for input in any <code>mo_*</code> function:</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/mo_property.html">mo_snomed</a></span><span class="op">(</span><span class="st">"S. aureus"</span><span class="op">)</span>
<span class="co">#&gt; [1] 115329001 3092008 113961008</span>
@ -939,11 +952,11 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>If you were dependent on the old Enterobacteriaceae family e.g. by using in your code:</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="kw">if</span> <span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_family</a></span><span class="op">(</span><span class="va">somebugs</span><span class="op">)</span> <span class="op">==</span> <span class="st">"Enterobacteriaceae"</span><span class="op">)</span> <span class="va">...</span></code></pre></div>
<p>then please adjust this to:</p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="kw">if</span> <span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_order</a></span><span class="op">(</span><span class="va">somebugs</span><span class="op">)</span> <span class="op">==</span> <span class="st">"Enterobacterales"</span><span class="op">)</span> <span class="va">...</span></code></pre></div>
</li>
@ -957,7 +970,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>Functions <code><a href="../reference/proportion.html">susceptibility()</a></code> and <code><a href="../reference/proportion.html">resistance()</a></code> as aliases of <code><a href="../reference/proportion.html">proportion_SI()</a></code> and <code><a href="../reference/proportion.html">proportion_R()</a></code>, respectively. These functions were added to make it more clear that “I” should be considered susceptible and not resistant.</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
<span class="va">example_isolates</span> <span class="op">%&gt;%</span>
@ -986,7 +999,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>More intelligent way of coping with some consonants like “l” and “r”</p></li>
<li>
<p>Added a score (a certainty percentage) to <code><a href="../reference/as.mo.html">mo_uncertainties()</a></code>, that is calculated using the <a href="https://en.wikipedia.org/wiki/Levenshtein_distance">Levenshtein distance</a>:</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb19"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"Stafylococcus aureus"</span>,
<span class="st">"staphylokok aureuz"</span><span class="op">)</span><span class="op">)</span>
@ -1045,14 +1058,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>Determination of first isolates now <strong>excludes</strong> all unknown microorganisms at default, i.e. microbial code <code>"UNKNOWN"</code>. They can be included with the new argument <code>include_unknown</code>:</p>
<div class="sourceCode" id="cb19"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span><span class="op">(</span><span class="va">...</span>, include_unknown <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></code></pre></div>
<p>For WHONET users, this means that all records/isolates with organism code <code>"con"</code> (<em>contamination</em>) will be excluded at default, since <code>as.mo("con") = "UNKNOWN"</code>. The function always shows a note with the number of unknown microorganisms that were included or excluded.</p>
</li>
<li>
<p>For code consistency, classes <code>ab</code> and <code>mo</code> will now be preserved in any subsetting or assignment. For the sake of data integrity, this means that invalid assignments will now result in <code>NA</code>:</p>
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># how it works in base R:</span>
<span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/factor.html">factor</a></span><span class="op">(</span><span class="st">"A"</span><span class="op">)</span>
@ -1077,7 +1090,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>Function <code><a href="../reference/bug_drug_combinations.html">bug_drug_combinations()</a></code> to quickly get a <code>data.frame</code> with the results of all bug-drug combinations in a data set. The column containing microorganism codes is guessed automatically and its input is transformed with <code><a href="../reference/mo_property.html">mo_shortname()</a></code> at default:</p>
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/bug_drug_combinations.html">bug_drug_combinations</a></span><span class="op">(</span><span class="va">example_isolates</span><span class="op">)</span>
<span class="co">#&gt; NOTE: Using column `mo` as input for `col_mo`.</span>
@ -1100,13 +1113,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<span class="co">#&gt; 4 Gram-negative AMX 227 0 405 632</span>
<span class="co">#&gt; NOTE: Use 'format()' on this result to get a publicable/printable format.</span></code></pre></div>
<p>You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R <code><a href="https://rdrr.io/r/base/format.html">format()</a></code> function:</p>
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="https://rdrr.io/r/base/format.html">format</a></span><span class="op">(</span><span class="va">x</span>, combine_IR <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></code></pre></div>
</li>
<li>
<p>Additional way to calculate co-resistance, i.e. when using multiple antimicrobials as input for <code>portion_*</code> functions or <code>count_*</code> functions. This can be used to determine the empiric susceptibility of a combination therapy. A new argument <code>only_all_tested</code> (<strong>which defaults to <code>FALSE</code></strong>) replaces the old <code>also_single_tested</code> and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on the <code>portion</code> and <code>count</code> help pages), where the %SI is being determined:</p>
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb24"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># --------------------------------------------------------------------</span>
<span class="co"># only_all_tested = FALSE only_all_tested = TRUE</span>
@ -1128,7 +1141,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
<li>
<p><code>tibble</code> printing support for classes <code>rsi</code>, <code>mic</code>, <code>disk</code>, <code>ab</code> <code>mo</code>. When using <code>tibble</code>s containing antimicrobial columns, values <code>S</code> will print in green, values <code>I</code> will print in yellow and values <code>R</code> will print in red. Microbial IDs (class <code>mo</code>) will emphasise on the genus and species, not on the kingdom.</p>
<div class="sourceCode" id="cb24"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb25"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># (run this on your own console, as this page does not support colour printing)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
@ -1211,7 +1224,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>Function <code><a href="../reference/proportion.html">rsi_df()</a></code> to transform a <code>data.frame</code> to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions <code><a href="../reference/count.html">count_df()</a></code> and <code>portion_df()</code> to immediately show resistance percentages and number of available isolates:</p>
<div class="sourceCode" id="cb25"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb26"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">septic_patients</span> <span class="op">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span><span class="op">(</span><span class="va">AMX</span>, <span class="va">CIP</span><span class="op">)</span> <span class="op">%&gt;%</span>
@ -1238,7 +1251,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li>UPEC (Uropathogenic <em>E. coli</em>)</li>
</ul>
<p>All these lead to the microbial ID of <em>E. coli</em>:</p>
<div class="sourceCode" id="cb26"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb27"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"UPEC"</span><span class="op">)</span>
<span class="co"># B_ESCHR_COL</span>
@ -1343,7 +1356,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>when all values are unique it now shows a message instead of a warning</p></li>
<li>
<p>support for boxplots:</p>
<div class="sourceCode" id="cb27"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb28"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">septic_patients</span> <span class="op">%&gt;%</span>
<span class="fu">freq</span><span class="op">(</span><span class="va">age</span><span class="op">)</span> <span class="op">%&gt;%</span>
@ -1438,7 +1451,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
<li>
<p>New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:</p>
<div class="sourceCode" id="cb28"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb29"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/filter_ab_class.html">filter_aminoglycosides</a></span><span class="op">(</span><span class="op">)</span>
<span class="fu"><a href="../reference/filter_ab_class.html">filter_carbapenems</a></span><span class="op">(</span><span class="op">)</span>
@ -1452,7 +1465,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<span class="fu"><a href="../reference/filter_ab_class.html">filter_macrolides</a></span><span class="op">(</span><span class="op">)</span>
<span class="fu"><a href="../reference/filter_ab_class.html">filter_tetracyclines</a></span><span class="op">(</span><span class="op">)</span></code></pre></div>
<p>The <code>antibiotics</code> data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in the <code>antibiotics</code> data set. For example:</p>
<div class="sourceCode" id="cb29"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb30"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">septic_patients</span> <span class="op">%&gt;%</span> <span class="fu"><a href="../reference/filter_ab_class.html">filter_glycopeptides</a></span><span class="op">(</span>result <span class="op">=</span> <span class="st">"R"</span><span class="op">)</span>
<span class="co"># Filtering on glycopeptide antibacterials: any of `vanc` or `teic` is R</span>
@ -1461,7 +1474,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
<li>
<p>All <code>ab_*</code> functions are deprecated and replaced by <code>atc_*</code> functions:</p>
<div class="sourceCode" id="cb30"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb31"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">ab_property</span> <span class="op">-&gt;</span> <span class="fu">atc_property</span><span class="op">(</span><span class="op">)</span>
<span class="va">ab_name</span> <span class="op">-&gt;</span> <span class="fu">atc_name</span><span class="op">(</span><span class="op">)</span>
@ -1482,7 +1495,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>New function <code><a href="../reference/age_groups.html">age_groups()</a></code> to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic AMR data analysis per age group.</p></li>
<li>
<p>New function <code><a href="../reference/resistance_predict.html">ggplot_rsi_predict()</a></code> as well as the base R <code><a href="../reference/plot.html">plot()</a></code> function can now be used for resistance prediction calculated with <code><a href="../reference/resistance_predict.html">resistance_predict()</a></code>:</p>
<div class="sourceCode" id="cb31"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb32"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span><span class="va">septic_patients</span>, col_ab <span class="op">=</span> <span class="st">"amox"</span><span class="op">)</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>
@ -1490,13 +1503,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
<li>
<p>Functions <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code> and <code><a href="../reference/first_isolate.html">filter_first_weighted_isolate()</a></code> to shorten and fasten filtering on data sets with antimicrobial results, e.g.:</p>
<div class="sourceCode" id="cb32"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb33"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">septic_patients</span> <span class="op">%&gt;%</span> <span class="fu"><a href="../reference/first_isolate.html">filter_first_isolate</a></span><span class="op">(</span><span class="va">...</span><span class="op">)</span>
<span class="co"># or</span>
<span class="fu"><a href="../reference/first_isolate.html">filter_first_isolate</a></span><span class="op">(</span><span class="va">septic_patients</span>, <span class="va">...</span><span class="op">)</span></code></pre></div>
<p>is equal to:</p>
<div class="sourceCode" id="cb33"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb34"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">septic_patients</span> <span class="op">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span>only_firsts <span class="op">=</span> <span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span><span class="op">(</span><span class="va">septic_patients</span>, <span class="va">...</span><span class="op">)</span><span class="op">)</span> <span class="op">%&gt;%</span>
@ -1529,7 +1542,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>Now handles incorrect spelling, like <code>i</code> instead of <code>y</code> and <code>f</code> instead of <code>ph</code>:</p>
<div class="sourceCode" id="cb34"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb35"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># mo_fullname() uses as.mo() internally</span>
@ -1541,7 +1554,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
<li>
<p>Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default <code>allow_uncertain = TRUE</code> is equal to uncertainty level 2. Run <code><a href="../reference/as.mo.html">?as.mo</a></code> for more info about these levels.</p>
<div class="sourceCode" id="cb35"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb36"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># equal:</span>
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="va">...</span>, allow_uncertain <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>
@ -1556,7 +1569,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>All microbial IDs that found are now saved to a local file <code>~/.Rhistory_mo</code>. Use the new function <code>clean_mo_history()</code> to delete this file, which resets the algorithms.</p></li>
<li>
<p>Incoercible results will now be considered unknown, MO code <code>UNKNOWN</code>. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:</p>
<div class="sourceCode" id="cb36"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb37"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span><span class="op">(</span><span class="st">"qwerty"</span>, language <span class="op">=</span> <span class="st">"es"</span><span class="op">)</span>
<span class="co"># Warning: </span>
@ -1606,7 +1619,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:</p>
<div class="sourceCode" id="cb37"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb38"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="co"># Determine genus of microorganisms (mo) in `septic_patients` data set:</span>
<span class="co"># OLD WAY</span>
@ -1690,7 +1703,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Fewer than 3 characters as input for <code>as.mo</code> will return NA</p></li>
<li>
<p>Function <code>as.mo</code> (and all <code>mo_*</code> wrappers) now supports genus abbreviations with “species” attached</p>
<div class="sourceCode" id="cb38"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb39"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"E. species"</span><span class="op">)</span> <span class="co"># B_ESCHR</span>
<span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span><span class="op">(</span><span class="st">"E. spp."</span><span class="op">)</span> <span class="co"># "Escherichia species"</span>
@ -1707,7 +1720,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<ul>
<li>
<p>Support for grouping variables, test with:</p>
<div class="sourceCode" id="cb39"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb40"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">septic_patients</span> <span class="op">%&gt;%</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op">(</span><span class="va">hospital_id</span><span class="op">)</span> <span class="op">%&gt;%</span>
@ -1715,7 +1728,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
<li>
<p>Support for (un)selecting columns:</p>
<div class="sourceCode" id="cb40"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb41"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">septic_patients</span> <span class="op">%&gt;%</span>
<span class="fu">freq</span><span class="op">(</span><span class="va">hospital_id</span><span class="op">)</span> <span class="op">%&gt;%</span>
@ -1795,7 +1808,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
</li>
</ul>
<p>They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:</p>
<div class="sourceCode" id="cb41"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb42"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span><span class="op">(</span><span class="st">"E. coli"</span><span class="op">)</span>
<span class="co"># [1] "Gram negative"</span>
@ -1806,7 +1819,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<span class="fu"><a href="../reference/mo_property.html">mo_fullname</a></span><span class="op">(</span><span class="st">"S. group A"</span>, language <span class="op">=</span> <span class="st">"pt"</span><span class="op">)</span> <span class="co"># Portuguese</span>
<span class="co"># [1] "Streptococcus grupo A"</span></code></pre></div>
<p>Furthermore, former taxonomic names will give a note about the current taxonomic name:</p>
<div class="sourceCode" id="cb42"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb43"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span><span class="op">(</span><span class="st">"Esc blattae"</span><span class="op">)</span>
<span class="co"># Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010)</span>
@ -1821,7 +1834,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Function <code>is.rsi.eligible</code> to check for columns that have valid antimicrobial results, but do not have the <code>rsi</code> class yet. Transform the columns of your raw data with: <code>data %&gt;% mutate_if(is.rsi.eligible, as.rsi)</code></p></li>
<li>
<p>Functions <code>as.mo</code> and <code>is.mo</code> as replacements for <code>as.bactid</code> and <code>is.bactid</code> (since the <code>microoganisms</code> data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The <code>as.mo</code> function determines microbial IDs using intelligent rules:</p>
<div class="sourceCode" id="cb43"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb44"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"E. coli"</span><span class="op">)</span>
<span class="co"># [1] B_ESCHR_COL</span>
@ -1830,7 +1843,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"S group A"</span><span class="op">)</span>
<span class="co"># [1] B_STRPTC_GRA</span></code></pre></div>
<p>And with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items:</p>
<div class="sourceCode" id="cb44"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb45"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">thousands_of_E_colis</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span><span class="op">(</span><span class="st">"E. coli"</span>, <span class="fl">25000</span><span class="op">)</span>
<span class="fu">microbenchmark</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/microbenchmark/man/microbenchmark.html">microbenchmark</a></span><span class="op">(</span><span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="va">thousands_of_E_colis</span><span class="op">)</span>, unit <span class="op">=</span> <span class="st">"s"</span><span class="op">)</span>
@ -1864,7 +1877,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Added three antimicrobial agents to the <code>antibiotics</code> data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)</p></li>
<li>
<p>Added 163 trade names to the <code>antibiotics</code> data set, it now contains 298 different trade names in total, e.g.:</p>
<div class="sourceCode" id="cb45"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb46"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="fu">ab_official</span><span class="op">(</span><span class="st">"Bactroban"</span><span class="op">)</span>
<span class="co"># [1] "Mupirocin"</span>
@ -1881,7 +1894,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Added arguments <code>minimum</code> and <code>as_percent</code> to <code>portion_df</code></p></li>
<li>
<p>Support for quasiquotation in the functions series <code>count_*</code> and <code>portions_*</code>, and <code>n_rsi</code>. This allows to check for more than 2 vectors or columns.</p>
<div class="sourceCode" id="cb46"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb47"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">septic_patients</span> <span class="op">%&gt;%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span><span class="op">(</span><span class="va">amox</span>, <span class="va">cipr</span><span class="op">)</span> <span class="op">%&gt;%</span> <span class="fu"><a href="../reference/count.html">count_IR</a></span><span class="op">(</span><span class="op">)</span>
<span class="co"># which is the same as:</span>
@ -1901,12 +1914,12 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
<li><p>Added longest en shortest character length in the frequency table (<code>freq</code>) header of class <code>character</code></p></li>
<li>
<p>Support for types (classes) list and matrix for <code>freq</code></p>
<div class="sourceCode" id="cb47"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb48"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">my_matrix</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/with.html">with</a></span><span class="op">(</span><span class="va">septic_patients</span>, <span class="fu"><a href="https://rdrr.io/r/base/matrix.html">matrix</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="va">age</span>, <span class="va">gender</span><span class="op">)</span>, ncol <span class="op">=</span> <span class="fl">2</span><span class="op">)</span><span class="op">)</span>
<span class="fu">freq</span><span class="op">(</span><span class="va">my_matrix</span><span class="op">)</span></code></pre></div>
<p>For lists, subsetting is possible:</p>
<div class="sourceCode" id="cb48"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb49"><pre class="downlit sourceCode r">
<code class="sourceCode R">
<span class="va">my_list</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html">list</a></span><span class="op">(</span>age <span class="op">=</span> <span class="va">septic_patients</span><span class="op">$</span><span class="va">age</span>, gender <span class="op">=</span> <span class="va">septic_patients</span><span class="op">$</span><span class="va">gender</span><span class="op">)</span>
<span class="va">my_list</span> <span class="op">%&gt;%</span> <span class="fu">freq</span><span class="op">(</span><span class="va">age</span><span class="op">)</span>

View File

@ -12,7 +12,7 @@ articles:
datasets: datasets.html
resistance_predict: resistance_predict.html
welcome_to_AMR: welcome_to_AMR.html
last_built: 2021-04-20T08:46Z
last_built: 2021-04-23T07:52Z
urls:
reference: https://msberends.github.io/AMR//reference
article: https://msberends.github.io/AMR//articles

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>
@ -599,7 +599,7 @@
</tr><tr>
<td>
<p><code><a href="like.html">like()</a></code> <code><a href="like.html">`%like%`</a></code> <code><a href="like.html">`%like_case%`</a></code> </p>
<p><code><a href="like.html">like()</a></code> <code><a href="like.html">`%like%`</a></code> <code><a href="like.html">`%unlike%`</a></code> <code><a href="like.html">`%like_case%`</a></code> <code><a href="like.html">`%unlike_case%`</a></code> </p>
</td>
<td><p>Vectorised Pattern Matching with Keyboard Shortcut</p></td>
</tr><tr>

View File

@ -82,7 +82,7 @@
</button>
<span class="navbar-brand">
<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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>
@ -246,7 +246,11 @@
<span class='va'>x</span> <span class='op'>%like%</span> <span class='va'>pattern</span>
<span class='va'>x</span> <span class='op'>%like_case%</span> <span class='va'>pattern</span></pre>
<span class='va'>x</span> <span class='op'>%unlike%</span> <span class='va'>pattern</span>
<span class='va'>x</span> <span class='op'>%like_case%</span> <span class='va'>pattern</span>
<span class='va'>x</span> <span class='op'>%unlike_case%</span> <span class='va'>pattern</span></pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
@ -273,14 +277,14 @@
<p>A <a href='https://rdrr.io/r/base/logical.html'>logical</a> vector</p>
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
<p>These <code>like()</code> and <code>%like%</code> functions:</p><ul>
<li><p>Are case-insensitive (use <code>%like_case%</code> for case-sensitive matching)</p></li>
<p>These <code>like()</code> and <code>%like%</code>/<code>%unlike%</code> functions:</p><ul>
<li><p>Are case-insensitive (use <code>%like_case%</code>/<code>%unlike_case%</code> for case-sensitive matching)</p></li>
<li><p>Support multiple patterns</p></li>
<li><p>Check if <code>pattern</code> is a valid regular expression and sets <code>fixed = TRUE</code> if not, to greatly improve speed (vectorised over <code>pattern</code>)</p></li>
<li><p>Always use compatibility with Perl unless <code>fixed = TRUE</code>, to greatly improve speed</p></li>
</ul>
<p>Using RStudio? The text <code>%like%</code> can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like <code>Ctrl+Shift+L</code> or <code>Cmd+Shift+L</code> (see <code>Tools</code> &gt; <code>Modify Keyboard Shortcuts...</code>).</p>
<p>Using RStudio? The <code>%like%</code>/<code>%unlike%</code> functions can also be directly inserted in your code from the Addins menu and can have its own keyboard shortcut like <code>Shift+Ctrl+L</code> or <code>Shift+Cmd+L</code> (see menu <code>Tools</code> &gt; <code>Modify Keyboard Shortcuts...</code>). If you keep pressing your shortcut, the inserted text will be iterated over <code>%like%</code> -&gt; <code>%unlike%</code> -&gt; <code>%like_case%</code> -&gt; <code>%unlike_case%</code>.</p>
<h2 class="hasAnchor" id="stable-lifecycle"><a class="anchor" href="#stable-lifecycle"></a>Stable Lifecycle</h2>
@ -310,18 +314,25 @@ The <a href='lifecycle.html'>lifecycle</a> of this function is <strong>stable</s
<span class='va'>b</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span> <span class='st'>"case"</span>, <span class='st'>"diff"</span>, <span class='st'>"yet"</span><span class='op'>)</span>
<span class='va'>a</span> <span class='op'>%like%</span> <span class='va'>b</span>
<span class='co'>#&gt; TRUE TRUE TRUE</span>
<span class='va'>a</span> <span class='op'>%unlike%</span> <span class='va'>b</span>
<span class='co'>#&gt; FALSE FALSE FALSE</span>
<span class='va'>a</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>%like%</span> <span class='va'>b</span>
<span class='co'>#&gt; TRUE FALSE FALSE</span>
<span class='va'>a</span> <span class='op'>%like%</span> <span class='va'>b</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span>
<span class='co'>#&gt; TRUE FALSE FALSE</span>
<span class='co'># get isolates whose name start with 'Ent' or 'ent'</span>
<span class='va'>example_isolates</span><span class='op'>[</span><span class='fu'><a href='https://rdrr.io/r/base/which.html'>which</a></span><span class='op'>(</span><span class='fu'><a href='mo_property.html'>mo_name</a></span><span class='op'>(</span><span class='va'>example_isolates</span><span class='op'>$</span><span class='va'>mo</span><span class='op'>)</span> <span class='op'>%like%</span> <span class='st'>"^ent"</span><span class='op'>)</span>, <span class='op'>]</span>
<span class='co'># \donttest{</span>
<span class='co'># faster way, only works in R 3.2 and later:</span>
<span class='va'>example_isolates</span><span class='op'>[</span><span class='fu'><a href='https://rdrr.io/r/base/which.html'>which</a></span><span class='op'>(</span><span class='fu'><a href='mo_property.html'>mo_name</a></span><span class='op'>(</span><span class='op'>)</span> <span class='op'>%like%</span> <span class='st'>"^ent"</span><span class='op'>)</span>, <span class='op'>]</span>
<span class='kw'>if</span> <span class='op'>(</span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>require</a></span><span class='op'>(</span><span class='st'><a href='https://dplyr.tidyverse.org'>"dplyr"</a></span><span class='op'>)</span><span class='op'>)</span> <span class='op'>{</span>
<span class='va'>example_isolates</span> <span class='op'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span><span class='op'>(</span><span class='fu'><a href='mo_property.html'>mo_name</a></span><span class='op'>(</span><span class='op'>)</span> <span class='op'>%like%</span> <span class='st'>"^ent"</span><span class='op'>)</span>
<span class='op'>}</span>
<span class='co'># }</span>
</pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">

View File

@ -81,7 +81,7 @@
</button>
<span class="navbar-brand">
<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.6.0.9007</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.6.0.9008</span>
</span>
</div>

View File

@ -2,6 +2,6 @@ Name: Insert %in%
Binding: addin_insert_in
Interactive: false
Name: Insert %like%
Name: Insert %like% or %unlike%
Binding: addin_insert_like
Interactive: false

View File

@ -3,7 +3,9 @@
\name{like}
\alias{like}
\alias{\%like\%}
\alias{\%unlike\%}
\alias{\%like_case\%}
\alias{\%unlike_case\%}
\title{Vectorised Pattern Matching with Keyboard Shortcut}
\source{
Idea from the \href{https://github.com/Rdatatable/data.table/blob/ec1259af1bf13fc0c96a1d3f9e84d55d8106a9a4/R/like.R}{\code{like} function from the \code{data.table} package}, although altered as explained in \emph{Details}.
@ -13,7 +15,11 @@ like(x, pattern, ignore.case = TRUE)
x \%like\% pattern
x \%unlike\% pattern
x \%like_case\% pattern
x \%unlike_case\% pattern
}
\arguments{
\item{x}{a character vector where matches are sought, or an object which can be coerced by \code{\link[=as.character]{as.character()}} to a character vector.}
@ -29,15 +35,15 @@ A \link{logical} vector
Convenient wrapper around \code{\link[=grepl]{grepl()}} to match a pattern: \code{x \%like\% pattern}. It always returns a \code{\link{logical}} vector and is always case-insensitive (use \code{x \%like_case\% pattern} for case-sensitive matching). Also, \code{pattern} can be as long as \code{x} to compare items of each index in both vectors, or they both can have the same length to iterate over all cases.
}
\details{
These \code{\link[=like]{like()}} and \verb{\%like\%} functions:
These \code{\link[=like]{like()}} and \verb{\%like\%}/\verb{\%unlike\%} functions:
\itemize{
\item Are case-insensitive (use \verb{\%like_case\%} for case-sensitive matching)
\item Are case-insensitive (use \verb{\%like_case\%}/\verb{\%unlike_case\%} for case-sensitive matching)
\item Support multiple patterns
\item Check if \code{pattern} is a valid regular expression and sets \code{fixed = TRUE} if not, to greatly improve speed (vectorised over \code{pattern})
\item Always use compatibility with Perl unless \code{fixed = TRUE}, to greatly improve speed
}
Using RStudio? The text \verb{\%like\%} can also be directly inserted in your code from the Addins menu and can have its own Keyboard Shortcut like \code{Ctrl+Shift+L} or \code{Cmd+Shift+L} (see \code{Tools} > \verb{Modify Keyboard Shortcuts...}).
Using RStudio? The \verb{\%like\%}/\verb{\%unlike\%} functions can also be directly inserted in your code from the Addins menu and can have its own keyboard shortcut like \code{Shift+Ctrl+L} or \code{Shift+Cmd+L} (see menu \code{Tools} > \verb{Modify Keyboard Shortcuts...}). If you keep pressing your shortcut, the inserted text will be iterated over \verb{\%like\%} -> \verb{\%unlike\%} -> \verb{\%like_case\%} -> \verb{\%unlike_case\%}.
}
\section{Stable Lifecycle}{
@ -65,12 +71,18 @@ a <- c("Test case", "Something different", "Yet another thing")
b <- c( "case", "diff", "yet")
a \%like\% b
#> TRUE TRUE TRUE
a \%unlike\% b
#> FALSE FALSE FALSE
a[1] \%like\% b
#> TRUE FALSE FALSE
a \%like\% b[1]
#> TRUE FALSE FALSE
# get isolates whose name start with 'Ent' or 'ent'
example_isolates[which(mo_name(example_isolates$mo) \%like\% "^ent"), ]
\donttest{
# faster way, only works in R 3.2 and later:
example_isolates[which(mo_name() \%like\% "^ent"), ]
if (require("dplyr")) {
@ -78,6 +90,7 @@ if (require("dplyr")) {
filter(mo_name() \%like\% "^ent")
}
}
}
\seealso{
\code{\link[=grepl]{grepl()}}
}