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

(v1.1.0.9005) lose dependencies

This commit is contained in:
2020-05-16 20:08:21 +02:00
parent 7f3da74b17
commit df2456b91f
30 changed files with 342 additions and 736 deletions

View File

@ -63,12 +63,16 @@ filter_join_worker <- function(x, y, by = NULL, type = c("anti", "semi")) {
# No export, no Rd
addin_insert_in <- function() {
rstudioapi::insertText(" %in% ")
if (!require("rstudioapi")) {
insertText(" %in% ")
}
}
# No export, no Rd
addin_insert_like <- function() {
rstudioapi::insertText(" %like% ")
if (!require("rstudioapi")) {
insertText(" %like% ")
}
}
check_dataset_integrity <- function() {

View File

@ -83,8 +83,12 @@ atc_online_property <- function(atc_code,
if (!all(atc_code %in% antibiotics)) {
atc_code <- as.character(ab_atc(atc_code))
}
if (!curl::has_internet()) {
require("curl")
require("xml2")
require("rvest")
if (!has_internet()) {
message("There appears to be no internet connection.")
return(rep(NA, length(atc_code)))
}
@ -129,15 +133,15 @@ atc_online_property <- function(atc_code,
atc_url <- sub("%s", atc_code[i], url, fixed = TRUE)
if (property == "groups") {
tbl <- xml2::read_html(atc_url) %>%
rvest::html_node("#content") %>%
rvest::html_children() %>%
rvest::html_node("a")
tbl <- read_html(atc_url) %>%
html_node("#content") %>%
html_children() %>%
html_node("a")
# get URLS of items
hrefs <- tbl %>% rvest::html_attr("href")
hrefs <- tbl %>% html_attr("href")
# get text of items
texts <- tbl %>% rvest::html_text()
texts <- tbl %>% html_text()
# select only text items where URL like "code="
texts <- texts[grepl("?code=", tolower(hrefs), fixed = TRUE)]
# last one is antibiotics, skip it
@ -145,9 +149,9 @@ atc_online_property <- function(atc_code,
returnvalue <- c(list(texts), returnvalue)
} else {
tbl <- xml2::read_html(atc_url) %>%
rvest::html_nodes("table") %>%
rvest::html_table(header = TRUE) %>%
tbl <- read_html(atc_url) %>%
html_nodes("table") %>%
html_table(header = TRUE) %>%
as.data.frame(stringsAsFactors = FALSE)
# case insensitive column names

View File

@ -21,7 +21,7 @@
#' Count available isolates
#'
#' @description These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in [summarise()] and support grouped variables, see *Examples*.
#' @description These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in `summarise()` from the `dplyr` package and also support grouped variables, please see *Examples*.
#'
#' [count_resistant()] should be used to count resistant isolates, [count_susceptible()] should be used to count susceptible isolates.
#' @inheritSection lifecycle Stable lifecycle
@ -32,7 +32,7 @@
#'
#' The function [count_resistant()] is equal to the function [count_R()]. The function [count_susceptible()] is equal to the function [count_SI()].
#'
#' The function [n_rsi()] is an alias of [count_all()]. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to [n_distinct()]. Their function is equal to `count_susceptible(...) + count_resistant(...)`.
#' The function [n_rsi()] is an alias of [count_all()]. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to `n_distinct()`. Their function is equal to `count_susceptible(...) + count_resistant(...)`.
#'
#' The function [count_df()] takes any variable from `data` that has an [`rsi`] class (created with [as.rsi()]) and counts the number of S's, I's and R's. It also supports grouped variables. The function [rsi_df()] works exactly like [count_df()], but adds the percentage of S, I and R.
#' @inheritSection proportion Combination therapy
@ -68,39 +68,40 @@
#' count_susceptible(example_isolates$AMX)
#' susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX)
#'
#' library(dplyr)
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(R = count_R(CIP),
#' I = count_I(CIP),
#' S = count_S(CIP),
#' n1 = count_all(CIP), # the actual total; sum of all three
#' n2 = n_rsi(CIP), # same - analogous to n_distinct
#' total = n()) # NOT the number of tested isolates!
#'
#' # Count co-resistance between amoxicillin/clav acid and gentamicin,
#' # so we can see that combination therapy does a lot more than mono therapy.
#' # Please mind that `susceptibility()` calculates percentages right away instead.
#' example_isolates %>% count_susceptible(AMC) # 1433
#' example_isolates %>% count_all(AMC) # 1879
#'
#' example_isolates %>% count_susceptible(GEN) # 1399
#' example_isolates %>% count_all(GEN) # 1855
#'
#' example_isolates %>% count_susceptible(AMC, GEN) # 1764
#' example_isolates %>% count_all(AMC, GEN) # 1936
#' # Get number of S+I vs. R immediately of selected columns
#' example_isolates %>%
#' select(AMX, CIP) %>%
#' count_df(translate = FALSE)
#'
#' # It also supports grouping variables
#' example_isolates %>%
#' select(hospital_id, AMX, CIP) %>%
#' group_by(hospital_id) %>%
#' count_df(translate = FALSE)
#'
#'
#' if (!require("dplyr")) {
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(R = count_R(CIP),
#' I = count_I(CIP),
#' S = count_S(CIP),
#' n1 = count_all(CIP), # the actual total; sum of all three
#' n2 = n_rsi(CIP), # same - analogous to n_distinct
#' total = n()) # NOT the number of tested isolates!
#'
#' # Count co-resistance between amoxicillin/clav acid and gentamicin,
#' # so we can see that combination therapy does a lot more than mono therapy.
#' # Please mind that `susceptibility()` calculates percentages right away instead.
#' example_isolates %>% count_susceptible(AMC) # 1433
#' example_isolates %>% count_all(AMC) # 1879
#'
#' example_isolates %>% count_susceptible(GEN) # 1399
#' example_isolates %>% count_all(GEN) # 1855
#'
#' example_isolates %>% count_susceptible(AMC, GEN) # 1764
#' example_isolates %>% count_all(AMC, GEN) # 1936
#'
#' # Get number of S+I vs. R immediately of selected columns
#' example_isolates %>%
#' select(AMX, CIP) %>%
#' count_df(translate = FALSE)
#'
#' # It also supports grouping variables
#' example_isolates %>%
#' select(hospital_id, AMX, CIP) %>%
#' group_by(hospital_id) %>%
#' count_df(translate = FALSE)
#' }
count_resistant <- function(..., only_all_tested = FALSE) {
rsi_calc(...,
ab_result = "R",

View File

@ -51,7 +51,7 @@
#' 3. Added total amount of explained variance as a caption in the plot
#' 4. Cleaned all syntax based on the `lintr` package and added integrity checks
#' 5. Updated documentation
#' @details The colours for labels and points can be changed by adding another scale layer for colour, like [scale_colour_viridis_d()] or [scale_colour_brewer()].
#' @details The colours for labels and points can be changed by adding another scale layer for colour, like `scale_colour_viridis_d()` or `scale_colour_brewer()`.
#' @rdname ggplot_pca
#' @export
#' @examples

View File

@ -27,7 +27,10 @@ globalVariables(c(".",
"angle",
"antibiotic",
"antibiotics",
"atc_group1",
"atc_group2",
"CNS_CPS",
"code",
"col_id",
"count",
"count.x",
@ -39,6 +42,7 @@ globalVariables(c(".",
"fullname_lower",
"g_species",
"genus",
"gr",
"gramstain",
"group",
"hjust",
@ -63,6 +67,8 @@ globalVariables(c(".",
"microorganisms.old",
"missing_names",
"mo",
"mo_new",
"mo_old",
"mono_count",
"more_than_episode_ago",
"name",

View File

@ -219,11 +219,7 @@ key_antibiotics <- function(x,
x$gramstain <- mo_gramstain(x[, col_mo, drop = TRUE], language = NULL)
x$key_ab <- NA_character_
# mutate_at(vars(col_mo), as.mo) %>%
# left_join_microorganisms(by = col_mo) %>%
# mutate(key_ab = NA_character_,
# gramstain = mo_gramstain(pull(., col_mo), language = NULL))
#
# Gram +
x$key_ab <- if_else(x$gramstain == "Gram-positive",
tryCatch(apply(X = x[, gram_positive],

View File

@ -21,7 +21,7 @@
#' Calculate microbial resistance
#'
#' @description These functions can be used to calculate the (co-)resistance or susceptibility of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in [summarise()] from the `dplyr` package and also supports grouped variables, please see *Examples*.
#' @description These functions can be used to calculate the (co-)resistance or susceptibility of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in `summarise()` from the `dplyr` package and also support grouped variables, please see *Examples*.
#'
#' [resistance()] should be used to calculate resistance, [susceptibility()] should be used to calculate susceptibility.\cr
#' @inheritSection lifecycle Stable lifecycle
@ -99,71 +99,71 @@
#' proportion_IR(example_isolates$AMX)
#' proportion_R(example_isolates$AMX)
#'
#' \dontrun{
#' library(dplyr)
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(r = resistance(CIP),
#' n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr, see ?n_rsi
#'
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(R = resistance(CIP, as_percent = TRUE),
#' SI = susceptibility(CIP, as_percent = TRUE),
#' n1 = count_all(CIP), # the actual total; sum of all three
#' n2 = n_rsi(CIP), # same - analogous to n_distinct
#' total = n()) # NOT the number of tested isolates!
#'
#' # Calculate co-resistance between amoxicillin/clav acid and gentamicin,
#' # so we can see that combination therapy does a lot more than mono therapy:
#' example_isolates %>% susceptibility(AMC) # %SI = 76.3%
#' example_isolates %>% count_all(AMC) # n = 1879
#'
#' example_isolates %>% susceptibility(GEN) # %SI = 75.4%
#' example_isolates %>% count_all(GEN) # n = 1855
#'
#' example_isolates %>% susceptibility(AMC, GEN) # %SI = 94.1%
#' example_isolates %>% count_all(AMC, GEN) # n = 1939
#'
#'
#' # See Details on how `only_all_tested` works. Example:
#' example_isolates %>%
#' summarise(numerator = count_susceptible(AMC, GEN),
#' denominator = count_all(AMC, GEN),
#' proportion = susceptibility(AMC, GEN))
#' example_isolates %>%
#' summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE),
#' denominator = count_all(AMC, GEN, only_all_tested = TRUE),
#' proportion = susceptibility(AMC, GEN, only_all_tested = TRUE))
#'
#'
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(cipro_p = susceptibility(CIP, as_percent = TRUE),
#' cipro_n = count_all(CIP),
#' genta_p = susceptibility(GEN, as_percent = TRUE),
#' genta_n = count_all(GEN),
#' combination_p = susceptibility(CIP, GEN, as_percent = TRUE),
#' combination_n = count_all(CIP, GEN))
#'
#' # Get proportions S/I/R immediately of all rsi columns
#' example_isolates %>%
#' select(AMX, CIP) %>%
#' proportion_df(translate = FALSE)
#'
#' # It also supports grouping variables
#' example_isolates %>%
#' select(hospital_id, AMX, CIP) %>%
#' group_by(hospital_id) %>%
#' proportion_df(translate = FALSE)
#'
#' # calculate current empiric combination therapy of Helicobacter gastritis:
#' my_table %>%
#' filter(first_isolate == TRUE,
#' genus == "Helicobacter") %>%
#' summarise(p = susceptibility(AMX, MTR), # amoxicillin with metronidazole
#' n = count_all(AMX, MTR))
#' if (!require("dplyr")) {
#' library(dplyr)
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(r = resistance(CIP),
#' n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr, see ?n_rsi
#'
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(R = resistance(CIP, as_percent = TRUE),
#' SI = susceptibility(CIP, as_percent = TRUE),
#' n1 = count_all(CIP), # the actual total; sum of all three
#' n2 = n_rsi(CIP), # same - analogous to n_distinct
#' total = n()) # NOT the number of tested isolates!
#'
#' # Calculate co-resistance between amoxicillin/clav acid and gentamicin,
#' # so we can see that combination therapy does a lot more than mono therapy:
#' example_isolates %>% susceptibility(AMC) # %SI = 76.3%
#' example_isolates %>% count_all(AMC) # n = 1879
#'
#' example_isolates %>% susceptibility(GEN) # %SI = 75.4%
#' example_isolates %>% count_all(GEN) # n = 1855
#'
#' example_isolates %>% susceptibility(AMC, GEN) # %SI = 94.1%
#' example_isolates %>% count_all(AMC, GEN) # n = 1939
#'
#'
#' # See Details on how `only_all_tested` works. Example:
#' example_isolates %>%
#' summarise(numerator = count_susceptible(AMC, GEN),
#' denominator = count_all(AMC, GEN),
#' proportion = susceptibility(AMC, GEN))
#'
#' example_isolates %>%
#' summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE),
#' denominator = count_all(AMC, GEN, only_all_tested = TRUE),
#' proportion = susceptibility(AMC, GEN, only_all_tested = TRUE))
#'
#'
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(cipro_p = susceptibility(CIP, as_percent = TRUE),
#' cipro_n = count_all(CIP),
#' genta_p = susceptibility(GEN, as_percent = TRUE),
#' genta_n = count_all(GEN),
#' combination_p = susceptibility(CIP, GEN, as_percent = TRUE),
#' combination_n = count_all(CIP, GEN))
#'
#' # Get proportions S/I/R immediately of all rsi columns
#' example_isolates %>%
#' select(AMX, CIP) %>%
#' proportion_df(translate = FALSE)
#'
#' # It also supports grouping variables
#' example_isolates %>%
#' select(hospital_id, AMX, CIP) %>%
#' group_by(hospital_id) %>%
#' proportion_df(translate = FALSE)
#'
#' # calculate current empiric combination therapy of Helicobacter gastritis:
#' my_table %>%
#' filter(first_isolate == TRUE,
#' genus == "Helicobacter") %>%
#' summarise(p = susceptibility(AMX, MTR), # amoxicillin with metronidazole
#' n = count_all(AMX, MTR))
#' }
resistance <- function(...,
minimum = 30,

View File

@ -1,176 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2018-2020 Berends MS, Luz CF et al. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
#
#' Read data from 4D database
#'
#' This function is only useful for the MMB department of the UMCG. Use this function to **import data by just defining the `file` parameter**. It will automatically transform birth dates and calculate patients age, translate the column names to English, transform the MO codes with [as.mo()] and transform all antimicrobial columns with [as.rsi()].
#' @inheritSection lifecycle Dormant lifecycle
#' @inheritParams utils::read.table
#' @param info a logical to indicate whether info about the import should be printed, defaults to `TRUE` in interactive sessions
#' @details Column names will be transformed, but the original column names are set as a "label" attribute and can be seen in e.g. RStudio Viewer.
#' @inheritSection AMR Read more on our website!
#' @export
read.4D <- function(file,
info = interactive(),
header = TRUE,
row.names = NULL,
sep = "\t",
quote = "\"'",
dec = ",",
na.strings = c("NA", "", "."),
skip = 2,
check.names = TRUE,
strip.white = TRUE,
fill = TRUE,
blank.lines.skip = TRUE,
stringsAsFactors = FALSE,
fileEncoding = "UTF-8",
encoding = "UTF-8") {
if (info == TRUE) {
message("Importing ", file, "... ", appendLF = FALSE)
}
data_4D <- utils::read.table(file = file,
row.names = row.names,
header = header,
sep = sep,
quote = quote,
dec = dec,
na.strings = na.strings,
skip = skip,
check.names = check.names,
strip.white = strip.white,
fill = fill,
blank.lines.skip = blank.lines.skip,
stringsAsFactors = stringsAsFactors,
fileEncoding = fileEncoding,
encoding = encoding)
# helper function for dates
to_date_4D <- function(x) {
date_regular <- as.Date(x, format = "%d-%m-%y")
posixlt <- as.POSIXlt(date_regular)
# born after today will be born 100 years ago
# based on https://stackoverflow.com/a/3312971/4575331
posixlt[date_regular > Sys.Date() & !is.na(posixlt)]$year <- posixlt[date_regular > Sys.Date() & !is.na(posixlt)]$year - 100
as.Date(posixlt)
}
if (info == TRUE) {
message("OK\nTransforming column names... ", appendLF = FALSE)
}
if ("row.names" %in% colnames(data_4D) & all(is.na(data_4D[, ncol(data_4D)]))) {
# remove first column name "row.names" and remove last empty column
colnames(data_4D) <- c(colnames(data_4D)[2:ncol(data_4D)], "_skip_last")
data_4D <- data_4D[, -ncol(data_4D)]
}
colnames(data_4D) <- tolower(colnames(data_4D))
if (all(c("afnamedat", "gebdatum") %in% colnames(data_4D))) {
# add age column
data_4D$age <- NA_integer_
}
cols_wanted <- c("patientnr", "gebdatum", "age", "mv", "monsternr", "afnamedat", "bepaling",
"afd.", "spec", "mat", "matbijz.", "mocode",
"amfo", "amox", "anid", "azit", "casp", "cecl", "cefe", "cfcl",
"cfot", "cfox", "cfta", "cftr", "cfur", "chlo", "cipr", "clin",
"cocl", "ctta", "dapt", "doxy", "eryt", "fluo", "fluz", "fosf",
"fusi", "gehi", "gent", "imip", "kana", "levo", "line", "mero",
"metr", "mico", "mino", "moxi", "mupi", "nali", "nitr", "norf",
"oxac", "peni", "pipe", "pita", "poly", "posa", "quda", "rifa",
"spat", "teic", "tige", "tobr", "trim", "trsu", "vana", "vanb",
"vanc", "vori")
# this ones actually exist
cols_wanted <- cols_wanted[cols_wanted %in% colnames(data_4D)]
# order of columns
data_4D <- data_4D[, cols_wanted]
# backup original column names
colnames.bak <- toupper(colnames(data_4D))
colnames.bak[colnames.bak == "AGE"] <- NA_character_
# rename of columns
colnames(data_4D) <- gsub("patientnr", "patient_id", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("gebdatum", "date_birth", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("mv", "gender", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("monsternr", "sample_id", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("afnamedat", "date_received", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("bepaling", "sample_test", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("afd.", "department", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("spec", "specialty", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("matbijz.", "specimen_type", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("mat", "specimen_group", colnames(data_4D), fixed = TRUE)
colnames(data_4D) <- gsub("mocode", "mo", colnames(data_4D), fixed = TRUE)
if (info == TRUE) {
message("OK\nTransforming dates and age... ", appendLF = FALSE)
}
if ("date_birth" %in% colnames(data_4D)) {
data_4D$date_birth <- to_date_4D(data_4D$date_birth)
}
if ("date_received" %in% colnames(data_4D)) {
data_4D$date_received <- to_date_4D(data_4D$date_received)
}
if ("age" %in% colnames(data_4D)) {
data_4D$age <- age(data_4D$date_birth, data_4D$date_received)
}
if ("gender" %in% colnames(data_4D)) {
data_4D$gender[data_4D$gender == "V"] <- "F"
}
if (info == TRUE) {
message("OK\nTransforming MO codes... ", appendLF = FALSE)
}
if ("mo" %in% colnames(data_4D)) {
data_4D$mo <- as.mo(data_4D$mo)
# column right of mo is:
drug1 <- colnames(data_4D)[grep("^mo$", colnames(data_4D)) + 1]
if (!is.na(drug1)) {
# and last is:
drug_last <- colnames(data_4D)[length(data_4D)]
# transform those to rsi:
data_4D <- suppressWarnings(mutate_at(data_4D, vars(drug1:drug_last), as.rsi))
}
}
# set original column names as label (can be seen in RStudio Viewer)
if (info == TRUE) {
message("OK\nSetting original column names as label... ", appendLF = FALSE)
}
for (i in seq_len(ncol(data_4D))) {
if (!is.na(colnames.bak[i])) {
attr(data_4D[, i], "label") <- colnames.bak[i]
}
}
if (info == TRUE) {
message("OK\nSetting query as label to data.frame... ", appendLF = FALSE)
}
qry <- readLines(con <- file(file, open = "r"))[1]
close(con)
attr(data_4D, "label") <- qry
if (info == TRUE) {
message("OK")
}
data_4D
}

View File

@ -188,34 +188,7 @@ resistance_predict <- function(x,
df$year <- as.integer(rownames(df))
rownames(df) <- NULL
# df <- df %>%
# filter_at(col_ab, all_vars(!is.na(.))) %>%
# mutate(year = year(pull(., col_date))) %>%
# group_by_at(c("year", col_ab)) %>%
# summarise(n())
# if (df %>% pull(col_ab) %>% n_distinct(na.rm = TRUE) < 2) {
# stop("No variety in antimicrobial interpretations - all isolates are '",
# df %>% pull(col_ab) %>% unique(), "'.",
# call. = FALSE)
# }
#
# colnames(df) <- c("year", "antibiotic", "observations")
df <- subset(df, sum(df$R + df$S, na.rm = TRUE) >= minimum)
# return(df)
#
# df <- df %>%
# filter(!is.na(antibiotic)) %>%
# pivot_wider(names_from = antibiotic,
# values_from = observations,
# values_fill = list(observations = 0)) %>%
# filter((R + S) >= minimum)
# df_matrix <- df %>%
# ungroup() %>%
# select(R, S) %>%
# as.matrix()
df_matrix <- as.matrix(df[, c("R", "S"), drop = FALSE])
if (NROW(df) == 0) {
@ -375,6 +348,9 @@ ggplot_rsi_predict <- function(x,
main = paste("Resistance Prediction of", x_name),
ribbon = TRUE,
...) {
stopifnot_installed_package("ggplot2")
if (!"resistance_predict" %in% class(x)) {
stop("`x` must be a resistance prediction model created with resistance_predict().")
}

View File

@ -102,7 +102,7 @@ rsi_calc <- function(...,
if (only_all_tested == TRUE) {
# THE NUMBER OF ISOLATES WHERE *ALL* ABx ARE S/I/R
x <- apply(X = x %>% mutate_all(as.integer),
x <- apply(X = as.data.frame(lapply(x, as.integer), stringsAsFactors = FALSE),
MARGIN = 1,
FUN = base::min)
numerator <- sum(as.integer(x) %in% as.integer(ab_result), na.rm = TRUE)
@ -229,7 +229,9 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both"
} else {
col_results$value <- rep(NA_real_, NROW(col_results))
}
out_new <- data.frame(antibiotic = ab_property(colnames(.data)[i], property = translate_ab, language = language),
out_new <- data.frame(antibiotic = ifelse(isFALSE(translate_ab),
colnames(.data)[i],
ab_property(colnames(.data)[i], property = translate_ab, language = language)),
interpretation = col_results$interpretation,
value = col_results$value,
isolates = col_results$isolates,