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

(v1.1.0.9005) lose dependencies

This commit is contained in:
dr. M.S. (Matthijs) Berends 2020-05-16 20:08:21 +02:00
parent 7f3da74b17
commit df2456b91f
30 changed files with 342 additions and 736 deletions

View File

@ -1,5 +1,5 @@
Package: AMR Package: AMR
Version: 1.1.0.9004 Version: 1.1.0.9005
Date: 2020-05-16 Date: 2020-05-16
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(

View File

@ -215,7 +215,6 @@ export(proportion_R)
export(proportion_S) export(proportion_S)
export(proportion_SI) export(proportion_SI)
export(proportion_df) export(proportion_df)
export(read.4D)
export(resistance) export(resistance)
export(resistance_predict) export(resistance_predict)
export(right_join_microorganisms) export(right_join_microorganisms)

View File

@ -1,4 +1,4 @@
# AMR 1.1.0.9004 # AMR 1.1.0.9005
## <small>Last updated: 16-May-2020</small> ## <small>Last updated: 16-May-2020</small>
### Breaking ### Breaking
@ -12,7 +12,7 @@
### Other ### Other
* Removed dependency on **all** packages that were needed for the `AMR` package to work properly: `crayon`, `data.table`, `dplyr`, `ggplot2`, `R6`, `rlang` and `tidyr`. This is a major code change, but will probably not be noticeable by users. Making this package independent on especially the tidyverse (packages `dplyr`, `ggplot2` and `tidyr`) tremendously increases sustainability on the long term, since tidyverse functions change quite often. Most of our functions are replaced with versions that only rely on base R, which keeps this package fully functional for many years to come, without requiring a lot of maintenance to keep up with other packages anymore. The only dependencies that remained are for extending methods of other packages, like `pillar` and `vctrs` for printing and working with tibbles using our classes `mo` and `ab`. * Removed dependency on **all** packages that were needed for the `AMR` package to work properly: `crayon`, `data.table`, `dplyr`, `ggplot2`, `R6`, `rlang` and `tidyr`. This is a major code change, but will probably not be noticeable by users. Making this package independent on especially the tidyverse (packages `dplyr`, `ggplot2` and `tidyr`) tremendously increases sustainability on the long term, since tidyverse functions change quite often. Most of our functions are replaced with versions that only rely on base R, which keeps this package fully functional for many years to come, without requiring a lot of maintenance to keep up with other packages anymore. The only dependencies that remained are for extending methods of other packages, like `pillar` and `vctrs` for printing and working with tibbles using our classes `mo` and `ab`.
* Removed function `read.4d()`, that was only useful for reading from an old test database.
# AMR 1.1.0 # AMR 1.1.0

View File

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

View File

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

View File

@ -21,7 +21,7 @@
#' Count available isolates #' 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. #' [count_resistant()] should be used to count resistant isolates, [count_susceptible()] should be used to count susceptible isolates.
#' @inheritSection lifecycle Stable lifecycle #' @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 [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. #' 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 #' @inheritSection proportion Combination therapy
@ -68,7 +68,8 @@
#' count_susceptible(example_isolates$AMX) #' count_susceptible(example_isolates$AMX)
#' susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX) #' susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX)
#' #'
#' library(dplyr) #'
#' if (!require("dplyr")) {
#' example_isolates %>% #' example_isolates %>%
#' group_by(hospital_id) %>% #' group_by(hospital_id) %>%
#' summarise(R = count_R(CIP), #' summarise(R = count_R(CIP),
@ -89,7 +90,7 @@
#' #'
#' example_isolates %>% count_susceptible(AMC, GEN) # 1764 #' example_isolates %>% count_susceptible(AMC, GEN) # 1764
#' example_isolates %>% count_all(AMC, GEN) # 1936 #' example_isolates %>% count_all(AMC, GEN) # 1936
#'
#' # Get number of S+I vs. R immediately of selected columns #' # Get number of S+I vs. R immediately of selected columns
#' example_isolates %>% #' example_isolates %>%
#' select(AMX, CIP) %>% #' select(AMX, CIP) %>%
@ -100,7 +101,7 @@
#' select(hospital_id, AMX, CIP) %>% #' select(hospital_id, AMX, CIP) %>%
#' group_by(hospital_id) %>% #' group_by(hospital_id) %>%
#' count_df(translate = FALSE) #' count_df(translate = FALSE)
#' #' }
count_resistant <- function(..., only_all_tested = FALSE) { count_resistant <- function(..., only_all_tested = FALSE) {
rsi_calc(..., rsi_calc(...,
ab_result = "R", ab_result = "R",

View File

@ -51,7 +51,7 @@
#' 3. Added total amount of explained variance as a caption in the plot #' 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 #' 4. Cleaned all syntax based on the `lintr` package and added integrity checks
#' 5. Updated documentation #' 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 #' @rdname ggplot_pca
#' @export #' @export
#' @examples #' @examples

View File

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

View File

@ -219,11 +219,7 @@ key_antibiotics <- function(x,
x$gramstain <- mo_gramstain(x[, col_mo, drop = TRUE], language = NULL) x$gramstain <- mo_gramstain(x[, col_mo, drop = TRUE], language = NULL)
x$key_ab <- NA_character_ 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 + # Gram +
x$key_ab <- if_else(x$gramstain == "Gram-positive", x$key_ab <- if_else(x$gramstain == "Gram-positive",
tryCatch(apply(X = x[, gram_positive], tryCatch(apply(X = x[, gram_positive],

View File

@ -21,7 +21,7 @@
#' Calculate microbial resistance #' 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 #' [resistance()] should be used to calculate resistance, [susceptibility()] should be used to calculate susceptibility.\cr
#' @inheritSection lifecycle Stable lifecycle #' @inheritSection lifecycle Stable lifecycle
@ -99,7 +99,7 @@
#' proportion_IR(example_isolates$AMX) #' proportion_IR(example_isolates$AMX)
#' proportion_R(example_isolates$AMX) #' proportion_R(example_isolates$AMX)
#' #'
#' \dontrun{ #' if (!require("dplyr")) {
#' library(dplyr) #' library(dplyr)
#' example_isolates %>% #' example_isolates %>%
#' group_by(hospital_id) %>% #' group_by(hospital_id) %>%
@ -131,7 +131,7 @@
#' summarise(numerator = count_susceptible(AMC, GEN), #' summarise(numerator = count_susceptible(AMC, GEN),
#' denominator = count_all(AMC, GEN), #' denominator = count_all(AMC, GEN),
#' proportion = susceptibility(AMC, GEN)) #' proportion = susceptibility(AMC, GEN))
#'
#' example_isolates %>% #' example_isolates %>%
#' summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE), #' summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE),
#' denominator = count_all(AMC, GEN, only_all_tested = TRUE), #' denominator = count_all(AMC, GEN, only_all_tested = TRUE),

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)) df$year <- as.integer(rownames(df))
rownames(df) <- NULL 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) 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]) df_matrix <- as.matrix(df[, c("R", "S"), drop = FALSE])
if (NROW(df) == 0) { if (NROW(df) == 0) {
@ -375,6 +348,9 @@ ggplot_rsi_predict <- function(x,
main = paste("Resistance Prediction of", x_name), main = paste("Resistance Prediction of", x_name),
ribbon = TRUE, ribbon = TRUE,
...) { ...) {
stopifnot_installed_package("ggplot2")
if (!"resistance_predict" %in% class(x)) { if (!"resistance_predict" %in% class(x)) {
stop("`x` must be a resistance prediction model created with resistance_predict().") 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) { if (only_all_tested == TRUE) {
# THE NUMBER OF ISOLATES WHERE *ALL* ABx ARE S/I/R # 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, MARGIN = 1,
FUN = base::min) FUN = base::min)
numerator <- sum(as.integer(x) %in% as.integer(ab_result), na.rm = TRUE) 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 { } else {
col_results$value <- rep(NA_real_, NROW(col_results)) 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, interpretation = col_results$interpretation,
value = col_results$value, value = col_results$value,
isolates = col_results$isolates, isolates = col_results$isolates,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ articles:
WHONET: WHONET.html WHONET: WHONET.html
benchmarks: benchmarks.html benchmarks: benchmarks.html
resistance_predict: resistance_predict.html resistance_predict: resistance_predict.html
last_built: 2020-05-16T11:03Z last_built: 2020-05-16T18:05Z
urls: urls:
reference: https://msberends.gitlab.io/AMR/reference reference: https://msberends.gitlab.io/AMR/reference
article: https://msberends.gitlab.io/AMR/articles article: https://msberends.gitlab.io/AMR/articles

View File

@ -49,7 +49,7 @@
<script src="../extra.js"></script> <script src="../extra.js"></script>
<meta property="og:title" content="Count available isolates — count" /> <meta property="og:title" content="Count available isolates — count" />
<meta property="og:description" content="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. <meta property="og:description" content="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." /> count_resistant() should be used to count resistant isolates, count_susceptible() should be used to count susceptible isolates." />
<meta property="og:image" content="https://msberends.gitlab.io/AMR/logo.svg" /> <meta property="og:image" content="https://msberends.gitlab.io/AMR/logo.svg" />
@ -83,7 +83,7 @@ count_resistant() should be used to count resistant isolates, count_susceptible(
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.1.0.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.1.0.9005</span>
</span> </span>
</div> </div>
@ -233,7 +233,7 @@ count_resistant() should be used to count resistant isolates, count_susceptible(
</div> </div>
<div class="ref-description"> <div class="ref-description">
<p>These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in <code>summarise()</code> and support grouped variables, see <em>Examples</em>.</p> <p>These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in <code>summarise()</code> from the <code>dplyr</code> package and also support grouped variables, please see <em>Examples</em>.</p>
<p><code>count_resistant()</code> should be used to count resistant isolates, <code>count_susceptible()</code> should be used to count susceptible isolates.</p> <p><code>count_resistant()</code> should be used to count resistant isolates, <code>count_susceptible()</code> should be used to count susceptible isolates.</p>
</div> </div>
@ -391,8 +391,9 @@ A microorganism is categorised as <em>Susceptible, Increased exposure</em> when
<span class='fu'>count_susceptible</span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>) <span class='fu'>count_susceptible</span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>)
<span class='fu'><a href='proportion.html'>susceptibility</a></span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>) * <span class='fu'>n_rsi</span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>) <span class='fu'><a href='proportion.html'>susceptibility</a></span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>) * <span class='fu'>n_rsi</span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>)
<span class='fu'><a href='https://rdrr.io/r/base/library.html'>library</a></span>(<span class='no'>dplyr</span>)
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='kw'>if</span> (!<span class='fu'><a href='https://rdrr.io/r/base/library.html'>require</a></span>(<span class='st'>"dplyr"</span>)) {
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>R</span> <span class='kw'>=</span> <span class='fu'>count_R</span>(<span class='no'>CIP</span>), <span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>R</span> <span class='kw'>=</span> <span class='fu'>count_R</span>(<span class='no'>CIP</span>),
<span class='kw'>I</span> <span class='kw'>=</span> <span class='fu'>count_I</span>(<span class='no'>CIP</span>), <span class='kw'>I</span> <span class='kw'>=</span> <span class='fu'>count_I</span>(<span class='no'>CIP</span>),
@ -401,27 +402,29 @@ A microorganism is categorised as <em>Susceptible, Increased exposure</em> when
<span class='kw'>n2</span> <span class='kw'>=</span> <span class='fu'>n_rsi</span>(<span class='no'>CIP</span>), <span class='co'># same - analogous to n_distinct</span> <span class='kw'>n2</span> <span class='kw'>=</span> <span class='fu'>n_rsi</span>(<span class='no'>CIP</span>), <span class='co'># same - analogous to n_distinct</span>
<span class='kw'>total</span> <span class='kw'>=</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/n.html'>n</a></span>()) <span class='co'># NOT the number of tested isolates!</span> <span class='kw'>total</span> <span class='kw'>=</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/n.html'>n</a></span>()) <span class='co'># NOT the number of tested isolates!</span>
<span class='co'># Count co-resistance between amoxicillin/clav acid and gentamicin,</span> <span class='co'># Count co-resistance between amoxicillin/clav acid and gentamicin,</span>
<span class='co'># so we can see that combination therapy does a lot more than mono therapy.</span> <span class='co'># so we can see that combination therapy does a lot more than mono therapy.</span>
<span class='co'># Please mind that `susceptibility()` calculates percentages right away instead.</span> <span class='co'># Please mind that `susceptibility()` calculates percentages right away instead.</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_susceptible</span>(<span class='no'>AMC</span>) <span class='co'># 1433</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_susceptible</span>(<span class='no'>AMC</span>) <span class='co'># 1433</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_all</span>(<span class='no'>AMC</span>) <span class='co'># 1879</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_all</span>(<span class='no'>AMC</span>) <span class='co'># 1879</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_susceptible</span>(<span class='no'>GEN</span>) <span class='co'># 1399</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_susceptible</span>(<span class='no'>GEN</span>) <span class='co'># 1399</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_all</span>(<span class='no'>GEN</span>) <span class='co'># 1855</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_all</span>(<span class='no'>GEN</span>) <span class='co'># 1855</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_susceptible</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>) <span class='co'># 1764</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_susceptible</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>) <span class='co'># 1764</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_all</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>) <span class='co'># 1936</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>count_all</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>) <span class='co'># 1936</span>
<span class='co'># Get number of S+I vs. R immediately of selected columns</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='co'># Get number of S+I vs. R immediately of selected columns</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>, <span class='no'>CIP</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>, <span class='no'>CIP</span>) <span class='kw'>%&gt;%</span>
<span class='fu'>count_df</span>(<span class='kw'>translate</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>) <span class='fu'>count_df</span>(<span class='kw'>translate</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)
<span class='co'># It also supports grouping variables</span> <span class='co'># It also supports grouping variables</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>hospital_id</span>, <span class='no'>AMX</span>, <span class='no'>CIP</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>hospital_id</span>, <span class='no'>AMX</span>, <span class='no'>CIP</span>) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span>
<span class='fu'>count_df</span>(<span class='kw'>translate</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)</pre> <span class='fu'>count_df</span>(<span class='kw'>translate</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)
}</pre>
</div> </div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar"> <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<nav id="toc" data-toggle="toc" class="sticky-top"> <nav id="toc" data-toggle="toc" class="sticky-top">

View File

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

View File

@ -81,7 +81,7 @@
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.1.0.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.1.0.9005</span>
</span> </span>
</div> </div>
@ -296,12 +296,6 @@
<p><code><a href="mo_source.html">set_mo_source()</a></code> <code><a href="mo_source.html">get_mo_source()</a></code> </p> <p><code><a href="mo_source.html">set_mo_source()</a></code> <code><a href="mo_source.html">get_mo_source()</a></code> </p>
</td> </td>
<td><p>Use predefined reference data set</p></td> <td><p>Use predefined reference data set</p></td>
</tr><tr>
<td>
<p><code><a href="read.4D.html">read.4D()</a></code> </p>
</td>
<td><p>Read data from 4D database</p></td>
</tr> </tr>
</tbody><tbody> </tbody><tbody>
<tr> <tr>

View File

@ -49,7 +49,7 @@
<script src="../extra.js"></script> <script src="../extra.js"></script>
<meta property="og:title" content="Calculate microbial resistance — proportion" /> <meta property="og:title" content="Calculate microbial resistance — proportion" />
<meta property="og:description" content="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. <meta property="og:description" content="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." /> resistance() should be used to calculate resistance, susceptibility() should be used to calculate susceptibility." />
<meta property="og:image" content="https://msberends.gitlab.io/AMR/logo.svg" /> <meta property="og:image" content="https://msberends.gitlab.io/AMR/logo.svg" />
@ -83,7 +83,7 @@ resistance() should be used to calculate resistance, susceptibility() should be
</button> </button>
<span class="navbar-brand"> <span class="navbar-brand">
<a class="navbar-link" href="../index.html">AMR (for R)</a> <a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.1.0.9004</span> <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.1.0.9005</span>
</span> </span>
</div> </div>
@ -233,7 +233,7 @@ resistance() should be used to calculate resistance, susceptibility() should be
</div> </div>
<div class="ref-description"> <div class="ref-description">
<p>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 <code>summarise()</code> from the <code>dplyr</code> package and also supports grouped variables, please see <em>Examples</em>.</p> <p>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 <code>summarise()</code> from the <code>dplyr</code> package and also support grouped variables, please see <em>Examples</em>.</p>
<p><code>resistance()</code> should be used to calculate resistance, <code>susceptibility()</code> should be used to calculate susceptibility.<br /></p> <p><code>resistance()</code> should be used to calculate resistance, <code>susceptibility()</code> should be used to calculate susceptibility.<br /></p>
</div> </div>
@ -398,14 +398,14 @@ A microorganism is categorised as <em>Susceptible, Increased exposure</em> when
<span class='fu'>proportion_IR</span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>) <span class='fu'>proportion_IR</span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>)
<span class='fu'>proportion_R</span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>) <span class='fu'>proportion_R</span>(<span class='no'>example_isolates</span>$<span class='no'>AMX</span>)
<span class='kw'>if</span> (<span class='fl'>FALSE</span>) { <span class='kw'>if</span> (!<span class='fu'><a href='https://rdrr.io/r/base/library.html'>require</a></span>(<span class='st'>"dplyr"</span>)) {
<span class='fu'><a href='https://rdrr.io/r/base/library.html'>library</a></span>(<span class='no'>dplyr</span>) <span class='fu'><a href='https://rdrr.io/r/base/library.html'>library</a></span>(<span class='no'>dplyr</span>)
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>r</span> <span class='kw'>=</span> <span class='fu'>resistance</span>(<span class='no'>CIP</span>), <span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>r</span> <span class='kw'>=</span> <span class='fu'>resistance</span>(<span class='no'>CIP</span>),
<span class='kw'>n</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>n_rsi</a></span>(<span class='no'>CIP</span>)) <span class='co'># n_rsi works like n_distinct in dplyr, see ?n_rsi</span> <span class='kw'>n</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>n_rsi</a></span>(<span class='no'>CIP</span>)) <span class='co'># n_rsi works like n_distinct in dplyr, see ?n_rsi</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>R</span> <span class='kw'>=</span> <span class='fu'>resistance</span>(<span class='no'>CIP</span>, <span class='kw'>as_percent</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>), <span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>R</span> <span class='kw'>=</span> <span class='fu'>resistance</span>(<span class='no'>CIP</span>, <span class='kw'>as_percent</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>),
<span class='kw'>SI</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>CIP</span>, <span class='kw'>as_percent</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>), <span class='kw'>SI</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>CIP</span>, <span class='kw'>as_percent</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>),
@ -413,30 +413,31 @@ A microorganism is categorised as <em>Susceptible, Increased exposure</em> when
<span class='kw'>n2</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>n_rsi</a></span>(<span class='no'>CIP</span>), <span class='co'># same - analogous to n_distinct</span> <span class='kw'>n2</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>n_rsi</a></span>(<span class='no'>CIP</span>), <span class='co'># same - analogous to n_distinct</span>
<span class='kw'>total</span> <span class='kw'>=</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/n.html'>n</a></span>()) <span class='co'># NOT the number of tested isolates!</span> <span class='kw'>total</span> <span class='kw'>=</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/n.html'>n</a></span>()) <span class='co'># NOT the number of tested isolates!</span>
<span class='co'># Calculate co-resistance between amoxicillin/clav acid and gentamicin,</span> <span class='co'># Calculate co-resistance between amoxicillin/clav acid and gentamicin,</span>
<span class='co'># so we can see that combination therapy does a lot more than mono therapy:</span> <span class='co'># so we can see that combination therapy does a lot more than mono therapy:</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>susceptibility</span>(<span class='no'>AMC</span>) <span class='co'># %SI = 76.3%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>susceptibility</span>(<span class='no'>AMC</span>) <span class='co'># %SI = 76.3%</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>AMC</span>) <span class='co'># n = 1879</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>AMC</span>) <span class='co'># n = 1879</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>susceptibility</span>(<span class='no'>GEN</span>) <span class='co'># %SI = 75.4%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>susceptibility</span>(<span class='no'>GEN</span>) <span class='co'># %SI = 75.4%</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>GEN</span>) <span class='co'># n = 1855</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>GEN</span>) <span class='co'># n = 1855</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>susceptibility</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>) <span class='co'># %SI = 94.1%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'>susceptibility</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>) <span class='co'># %SI = 94.1%</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>) <span class='co'># n = 1939</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>) <span class='co'># n = 1939</span>
<span class='co'># See Details on how `only_all_tested` works. Example:</span> <span class='co'># See Details on how `only_all_tested` works. Example:</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>numerator</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_susceptible</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>), <span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>numerator</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_susceptible</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>),
<span class='kw'>denominator</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>), <span class='kw'>denominator</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>),
<span class='kw'>proportion</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>)) <span class='kw'>proportion</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>))
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>numerator</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_susceptible</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>, <span class='kw'>only_all_tested</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>), <span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>numerator</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_susceptible</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>, <span class='kw'>only_all_tested</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>),
<span class='kw'>denominator</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>, <span class='kw'>only_all_tested</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>), <span class='kw'>denominator</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>, <span class='kw'>only_all_tested</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>),
<span class='kw'>proportion</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>, <span class='kw'>only_all_tested</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)) <span class='kw'>proportion</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>AMC</span>, <span class='no'>GEN</span>, <span class='kw'>only_all_tested</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>))
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>cipro_p</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>CIP</span>, <span class='kw'>as_percent</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>), <span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>cipro_p</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>CIP</span>, <span class='kw'>as_percent</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>),
<span class='kw'>cipro_n</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>CIP</span>), <span class='kw'>cipro_n</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>CIP</span>),
@ -445,19 +446,19 @@ A microorganism is categorised as <em>Susceptible, Increased exposure</em> when
<span class='kw'>combination_p</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>CIP</span>, <span class='no'>GEN</span>, <span class='kw'>as_percent</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>), <span class='kw'>combination_p</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>CIP</span>, <span class='no'>GEN</span>, <span class='kw'>as_percent</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>),
<span class='kw'>combination_n</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>CIP</span>, <span class='no'>GEN</span>)) <span class='kw'>combination_n</span> <span class='kw'>=</span> <span class='fu'><a href='count.html'>count_all</a></span>(<span class='no'>CIP</span>, <span class='no'>GEN</span>))
<span class='co'># Get proportions S/I/R immediately of all rsi columns</span> <span class='co'># Get proportions S/I/R immediately of all rsi columns</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>, <span class='no'>CIP</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>, <span class='no'>CIP</span>) <span class='kw'>%&gt;%</span>
<span class='fu'>proportion_df</span>(<span class='kw'>translate</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>) <span class='fu'>proportion_df</span>(<span class='kw'>translate</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)
<span class='co'># It also supports grouping variables</span> <span class='co'># It also supports grouping variables</span>
<span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span> <span class='no'>example_isolates</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>hospital_id</span>, <span class='no'>AMX</span>, <span class='no'>CIP</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>hospital_id</span>, <span class='no'>AMX</span>, <span class='no'>CIP</span>) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%&gt;%</span>
<span class='fu'>proportion_df</span>(<span class='kw'>translate</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>) <span class='fu'>proportion_df</span>(<span class='kw'>translate</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)
<span class='co'># calculate current empiric combination therapy of Helicobacter gastritis:</span> <span class='co'># calculate current empiric combination therapy of Helicobacter gastritis:</span>
<span class='no'>my_table</span> <span class='kw'>%&gt;%</span> <span class='no'>my_table</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='no'>first_isolate</span> <span class='kw'>==</span> <span class='fl'>TRUE</span>, <span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='no'>first_isolate</span> <span class='kw'>==</span> <span class='fl'>TRUE</span>,
<span class='no'>genus</span> <span class='kw'>==</span> <span class='st'>"Helicobacter"</span>) <span class='kw'>%&gt;%</span> <span class='no'>genus</span> <span class='kw'>==</span> <span class='st'>"Helicobacter"</span>) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>p</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>AMX</span>, <span class='no'>MTR</span>), <span class='co'># amoxicillin with metronidazole</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/summarise.html'>summarise</a></span>(<span class='kw'>p</span> <span class='kw'>=</span> <span class='fu'>susceptibility</span>(<span class='no'>AMX</span>, <span class='no'>MTR</span>), <span class='co'># amoxicillin with metronidazole</span>

View File

@ -132,9 +132,6 @@
<url> <url>
<loc>https://msberends.gitlab.io/AMR/reference/proportion.html</loc> <loc>https://msberends.gitlab.io/AMR/reference/proportion.html</loc>
</url> </url>
<url>
<loc>https://msberends.gitlab.io/AMR/reference/read.4D.html</loc>
</url>
<url> <url>
<loc>https://msberends.gitlab.io/AMR/reference/reexports.html</loc> <loc>https://msberends.gitlab.io/AMR/reference/reexports.html</loc>
</url> </url>

View File

@ -59,7 +59,7 @@ count_df(
An \code{\link{integer}} An \code{\link{integer}}
} }
\description{ \description{
These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in \code{\link[=summarise]{summarise()}} and support grouped variables, see \emph{Examples}. These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in \code{summarise()} from the \code{dplyr} package and also support grouped variables, please see \emph{Examples}.
\code{\link[=count_resistant]{count_resistant()}} should be used to count resistant isolates, \code{\link[=count_susceptible]{count_susceptible()}} should be used to count susceptible isolates. \code{\link[=count_resistant]{count_resistant()}} should be used to count resistant isolates, \code{\link[=count_susceptible]{count_susceptible()}} should be used to count susceptible isolates.
} }
@ -68,7 +68,7 @@ These functions are meant to count isolates. Use the \code{\link[=resistance]{re
The function \code{\link[=count_resistant]{count_resistant()}} is equal to the function \code{\link[=count_R]{count_R()}}. The function \code{\link[=count_susceptible]{count_susceptible()}} is equal to the function \code{\link[=count_SI]{count_SI()}}. The function \code{\link[=count_resistant]{count_resistant()}} is equal to the function \code{\link[=count_R]{count_R()}}. The function \code{\link[=count_susceptible]{count_susceptible()}} is equal to the function \code{\link[=count_SI]{count_SI()}}.
The function \code{\link[=n_rsi]{n_rsi()}} is an alias of \code{\link[=count_all]{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 \code{\link[=n_distinct]{n_distinct()}}. Their function is equal to \code{count_susceptible(...) + count_resistant(...)}. The function \code{\link[=n_rsi]{n_rsi()}} is an alias of \code{\link[=count_all]{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 \code{n_distinct()}. Their function is equal to \code{count_susceptible(...) + count_resistant(...)}.
The function \code{\link[=count_df]{count_df()}} takes any variable from \code{data} that has an \code{\link{rsi}} class (created with \code{\link[=as.rsi]{as.rsi()}}) and counts the number of S's, I's and R's. It also supports grouped variables. The function \code{\link[=rsi_df]{rsi_df()}} works exactly like \code{\link[=count_df]{count_df()}}, but adds the percentage of S, I and R. The function \code{\link[=count_df]{count_df()}} takes any variable from \code{data} that has an \code{\link{rsi}} class (created with \code{\link[=as.rsi]{as.rsi()}}) and counts the number of S's, I's and R's. It also supports grouped variables. The function \code{\link[=rsi_df]{rsi_df()}} works exactly like \code{\link[=count_df]{count_df()}}, but adds the percentage of S, I and R.
} }
@ -157,8 +157,9 @@ n_rsi(example_isolates$AMX)
count_susceptible(example_isolates$AMX) count_susceptible(example_isolates$AMX)
susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX) susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX)
library(dplyr)
example_isolates \%>\% if (!require("dplyr")) {
example_isolates \%>\%
group_by(hospital_id) \%>\% group_by(hospital_id) \%>\%
summarise(R = count_R(CIP), summarise(R = count_R(CIP),
I = count_I(CIP), I = count_I(CIP),
@ -167,28 +168,29 @@ example_isolates \%>\%
n2 = n_rsi(CIP), # same - analogous to n_distinct n2 = n_rsi(CIP), # same - analogous to n_distinct
total = n()) # NOT the number of tested isolates! total = n()) # NOT the number of tested isolates!
# Count co-resistance between amoxicillin/clav acid and gentamicin, # Count co-resistance between amoxicillin/clav acid and gentamicin,
# so we can see that combination therapy does a lot more than mono therapy. # so we can see that combination therapy does a lot more than mono therapy.
# Please mind that `susceptibility()` calculates percentages right away instead. # Please mind that `susceptibility()` calculates percentages right away instead.
example_isolates \%>\% count_susceptible(AMC) # 1433 example_isolates \%>\% count_susceptible(AMC) # 1433
example_isolates \%>\% count_all(AMC) # 1879 example_isolates \%>\% count_all(AMC) # 1879
example_isolates \%>\% count_susceptible(GEN) # 1399 example_isolates \%>\% count_susceptible(GEN) # 1399
example_isolates \%>\% count_all(GEN) # 1855 example_isolates \%>\% count_all(GEN) # 1855
example_isolates \%>\% count_susceptible(AMC, GEN) # 1764 example_isolates \%>\% count_susceptible(AMC, GEN) # 1764
example_isolates \%>\% count_all(AMC, GEN) # 1936 example_isolates \%>\% count_all(AMC, GEN) # 1936
# Get number of S+I vs. R immediately of selected columns
example_isolates \%>\% # Get number of S+I vs. R immediately of selected columns
example_isolates \%>\%
select(AMX, CIP) \%>\% select(AMX, CIP) \%>\%
count_df(translate = FALSE) count_df(translate = FALSE)
# It also supports grouping variables # It also supports grouping variables
example_isolates \%>\% example_isolates \%>\%
select(hospital_id, AMX, CIP) \%>\% select(hospital_id, AMX, CIP) \%>\%
group_by(hospital_id) \%>\% group_by(hospital_id) \%>\%
count_df(translate = FALSE) count_df(translate = FALSE)
}
} }
\seealso{ \seealso{
\code{\link[=proportion]{proportion_*}} to calculate microbial resistance and susceptibility. \code{\link[=proportion]{proportion_*}} to calculate microbial resistance and susceptibility.

View File

@ -102,7 +102,7 @@ ggplot_pca(
Produces a \code{ggplot2} variant of a so-called \href{https://en.wikipedia.org/wiki/Biplot}{biplot} for PCA (principal component analysis), but is more flexible and more appealing than the base \R \code{\link[=biplot]{biplot()}} function. Produces a \code{ggplot2} variant of a so-called \href{https://en.wikipedia.org/wiki/Biplot}{biplot} for PCA (principal component analysis), but is more flexible and more appealing than the base \R \code{\link[=biplot]{biplot()}} function.
} }
\details{ \details{
The colours for labels and points can be changed by adding another scale layer for colour, like \code{\link[=scale_colour_viridis_d]{scale_colour_viridis_d()}} or \code{\link[=scale_colour_brewer]{scale_colour_brewer()}}. The colours for labels and points can be changed by adding another scale layer for colour, like \code{scale_colour_viridis_d()} or \code{scale_colour_brewer()}.
} }
\section{Maturing lifecycle}{ \section{Maturing lifecycle}{

View File

@ -74,7 +74,7 @@ rsi_df(
A \code{\link{double}} or, when \code{as_percent = TRUE}, a \code{\link{character}}. A \code{\link{double}} or, when \code{as_percent = TRUE}, a \code{\link{character}}.
} }
\description{ \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 \code{\link[=summarise]{summarise()}} from the \code{dplyr} package and also supports grouped variables, please see \emph{Examples}. 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 \code{summarise()} from the \code{dplyr} package and also support grouped variables, please see \emph{Examples}.
\code{\link[=resistance]{resistance()}} should be used to calculate resistance, \code{\link[=susceptibility]{susceptibility()}} should be used to calculate susceptibility.\cr \code{\link[=resistance]{resistance()}} should be used to calculate resistance, \code{\link[=susceptibility]{susceptibility()}} should be used to calculate susceptibility.\cr
} }
@ -160,14 +160,14 @@ proportion_I(example_isolates$AMX)
proportion_IR(example_isolates$AMX) proportion_IR(example_isolates$AMX)
proportion_R(example_isolates$AMX) proportion_R(example_isolates$AMX)
\dontrun{ if (!require("dplyr")) {
library(dplyr) library(dplyr)
example_isolates \%>\% example_isolates \%>\%
group_by(hospital_id) \%>\% group_by(hospital_id) \%>\%
summarise(r = resistance(CIP), summarise(r = resistance(CIP),
n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr, see ?n_rsi n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr, see ?n_rsi
example_isolates \%>\% example_isolates \%>\%
group_by(hospital_id) \%>\% group_by(hospital_id) \%>\%
summarise(R = resistance(CIP, as_percent = TRUE), summarise(R = resistance(CIP, as_percent = TRUE),
SI = susceptibility(CIP, as_percent = TRUE), SI = susceptibility(CIP, as_percent = TRUE),
@ -175,30 +175,31 @@ example_isolates \%>\%
n2 = n_rsi(CIP), # same - analogous to n_distinct n2 = n_rsi(CIP), # same - analogous to n_distinct
total = n()) # NOT the number of tested isolates! total = n()) # NOT the number of tested isolates!
# Calculate co-resistance between amoxicillin/clav acid and gentamicin, # Calculate co-resistance between amoxicillin/clav acid and gentamicin,
# so we can see that combination therapy does a lot more than mono therapy: # so we can see that combination therapy does a lot more than mono therapy:
example_isolates \%>\% susceptibility(AMC) # \%SI = 76.3\% example_isolates \%>\% susceptibility(AMC) # \%SI = 76.3\%
example_isolates \%>\% count_all(AMC) # n = 1879 example_isolates \%>\% count_all(AMC) # n = 1879
example_isolates \%>\% susceptibility(GEN) # \%SI = 75.4\% example_isolates \%>\% susceptibility(GEN) # \%SI = 75.4\%
example_isolates \%>\% count_all(GEN) # n = 1855 example_isolates \%>\% count_all(GEN) # n = 1855
example_isolates \%>\% susceptibility(AMC, GEN) # \%SI = 94.1\% example_isolates \%>\% susceptibility(AMC, GEN) # \%SI = 94.1\%
example_isolates \%>\% count_all(AMC, GEN) # n = 1939 example_isolates \%>\% count_all(AMC, GEN) # n = 1939
# See Details on how `only_all_tested` works. Example: # See Details on how `only_all_tested` works. Example:
example_isolates \%>\% example_isolates \%>\%
summarise(numerator = count_susceptible(AMC, GEN), summarise(numerator = count_susceptible(AMC, GEN),
denominator = count_all(AMC, GEN), denominator = count_all(AMC, GEN),
proportion = susceptibility(AMC, GEN)) proportion = susceptibility(AMC, GEN))
example_isolates \%>\%
example_isolates \%>\%
summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE), summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE),
denominator = count_all(AMC, GEN, only_all_tested = TRUE), denominator = count_all(AMC, GEN, only_all_tested = TRUE),
proportion = susceptibility(AMC, GEN, only_all_tested = TRUE)) proportion = susceptibility(AMC, GEN, only_all_tested = TRUE))
example_isolates \%>\% example_isolates \%>\%
group_by(hospital_id) \%>\% group_by(hospital_id) \%>\%
summarise(cipro_p = susceptibility(CIP, as_percent = TRUE), summarise(cipro_p = susceptibility(CIP, as_percent = TRUE),
cipro_n = count_all(CIP), cipro_n = count_all(CIP),
@ -207,19 +208,19 @@ example_isolates \%>\%
combination_p = susceptibility(CIP, GEN, as_percent = TRUE), combination_p = susceptibility(CIP, GEN, as_percent = TRUE),
combination_n = count_all(CIP, GEN)) combination_n = count_all(CIP, GEN))
# Get proportions S/I/R immediately of all rsi columns # Get proportions S/I/R immediately of all rsi columns
example_isolates \%>\% example_isolates \%>\%
select(AMX, CIP) \%>\% select(AMX, CIP) \%>\%
proportion_df(translate = FALSE) proportion_df(translate = FALSE)
# It also supports grouping variables # It also supports grouping variables
example_isolates \%>\% example_isolates \%>\%
select(hospital_id, AMX, CIP) \%>\% select(hospital_id, AMX, CIP) \%>\%
group_by(hospital_id) \%>\% group_by(hospital_id) \%>\%
proportion_df(translate = FALSE) proportion_df(translate = FALSE)
# calculate current empiric combination therapy of Helicobacter gastritis: # calculate current empiric combination therapy of Helicobacter gastritis:
my_table \%>\% my_table \%>\%
filter(first_isolate == TRUE, filter(first_isolate == TRUE,
genus == "Helicobacter") \%>\% genus == "Helicobacter") \%>\%
summarise(p = susceptibility(AMX, MTR), # amoxicillin with metronidazole summarise(p = susceptibility(AMX, MTR), # amoxicillin with metronidazole

View File

@ -1,148 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/read.4d.R
\name{read.4D}
\alias{read.4D}
\title{Read data from 4D database}
\usage{
read.4D(
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"
)
}
\arguments{
\item{file}{the name of the file which the data are to be read from.
Each row of the table appears as one line of the file. If it does
not contain an \emph{absolute} path, the file name is
\emph{relative} to the current working directory,
\code{\link{getwd}()}. Tilde-expansion is performed where supported.
This can be a compressed file (see \code{\link{file}}).
Alternatively, \code{file} can be a readable text-mode
\link{connection} (which will be opened for reading if
necessary, and if so \code{\link{close}}d (and hence destroyed) at
the end of the function call). (If \code{\link{stdin}()} is used,
the prompts for lines may be somewhat confusing. Terminate input
with a blank line or an EOF signal, \code{Ctrl-D} on Unix and
\code{Ctrl-Z} on Windows. Any pushback on \code{stdin()} will be
cleared before return.)
\code{file} can also be a complete URL. (For the supported URL
schemes, see the \sQuote{URLs} section of the help for
\code{\link{url}}.)
}
\item{info}{a logical to indicate whether info about the import should be printed, defaults to \code{TRUE} in interactive sessions}
\item{header}{a logical value indicating whether the file contains the
names of the variables as its first line. If missing, the value is
determined from the file format: \code{header} is set to \code{TRUE}
if and only if the first row contains one fewer field than the
number of columns.}
\item{row.names}{a vector of row names. This can be a vector giving
the actual row names, or a single number giving the column of the
table which contains the row names, or character string giving the
name of the table column containing the row names.
If there is a header and the first row contains one fewer field than
the number of columns, the first column in the input is used for the
row names. Otherwise if \code{row.names} is missing, the rows are
numbered.
Using \code{row.names = NULL} forces row numbering. Missing or
\code{NULL} \code{row.names} generate row names that are considered
to be \sQuote{automatic} (and not preserved by \code{\link{as.matrix}}).
}
\item{sep}{the field separator character. Values on each line of the
file are separated by this character. If \code{sep = ""} (the
default for \code{read.table}) the separator is \sQuote{white space},
that is one or more spaces, tabs, newlines or carriage returns.}
\item{quote}{the set of quoting characters. To disable quoting
altogether, use \code{quote = ""}. See \code{\link{scan}} for the
behaviour on quotes embedded in quotes. Quoting is only considered
for columns read as character, which is all of them unless
\code{colClasses} is specified.}
\item{dec}{the character used in the file for decimal points.}
\item{na.strings}{a character vector of strings which are to be
interpreted as \code{\link{NA}} values. Blank fields are also
considered to be missing values in logical, integer, numeric and
complex fields. Note that the test happens \emph{after}
white space is stripped from the input, so \code{na.strings}
values may need their own white space stripped in advance.}
\item{skip}{integer: the number of lines of the data file to skip before
beginning to read data.}
\item{check.names}{logical. If \code{TRUE} then the names of the
variables in the data frame are checked to ensure that they are
syntactically valid variable names. If necessary they are adjusted
(by \code{\link{make.names}}) so that they are, and also to ensure
that there are no duplicates.}
\item{strip.white}{logical. Used only when \code{sep} has
been specified, and allows the stripping of leading and trailing
white space from unquoted \code{character} fields (\code{numeric} fields
are always stripped). See \code{\link{scan}} for further details
(including the exact meaning of \sQuote{white space}),
remembering that the columns may include the row names.}
\item{fill}{logical. If \code{TRUE} then in case the rows have unequal
length, blank fields are implicitly added. See \sQuote{Details}.}
\item{blank.lines.skip}{logical: if \code{TRUE} blank lines in the
input are ignored.}
\item{stringsAsFactors}{logical: should character vectors be converted
to factors? Note that this is overridden by \code{as.is} and
\code{colClasses}, both of which allow finer control.}
\item{fileEncoding}{character string: if non-empty declares the
encoding used on a file (not a connection) so the character data can
be re-encoded. See the \sQuote{Encoding} section of the help for
\code{\link{file}}, the \sQuote{R Data Import/Export Manual} and
\sQuote{Note}.
}
\item{encoding}{encoding to be assumed for input strings. It is
used to mark character strings as known to be in
Latin-1 or UTF-8 (see \code{\link{Encoding}}): it is not used to
re-encode the input, but allows \R to handle encoded strings in
their native encoding (if one of those two). See \sQuote{Value}
and \sQuote{Note}.
}
}
\description{
This function is only useful for the MMB department of the UMCG. Use this function to \strong{import data by just defining the \code{file} parameter}. It will automatically transform birth dates and calculate patients age, translate the column names to English, transform the MO codes with \code{\link[=as.mo]{as.mo()}} and transform all antimicrobial columns with \code{\link[=as.rsi]{as.rsi()}}.
}
\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.
}
\section{Dormant lifecycle}{
\if{html}{\figure{lifecycle_dormant.svg}{options: style=margin-bottom:5px} \cr}
The \link[AMR:lifecycle]{lifecycle} of this function is \strong{dormant}. A dormant function is currently not under active development and has not reached a stable phase. We might return to it in the future. As with experimental functions, you are best off waiting until a function is more mature before you use it in production code.
}
\section{Read more on our website!}{
On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}.
}

View File

@ -1,51 +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. #
# ==================================================================== #
context("read.4d.R")
test_that("read 4D works", {
library(dplyr)
test1 <- data.frame(Patientnr = "ABC",
MV = "M",
Monsternr = "0123",
Afnamedat = "10-11-12",
Bepaling = "bk",
Afd. = "ABC",
Spec = "ABC",
Matbijz. = "ABC",
Mat = "ABC",
Mocode = "esccol",
PENI = "R",
stringsAsFactors = FALSE)
tf <- tempfile()
write.table(test1, file = tf, quote = F, sep = "\t")
x <- read.4D(tf, skip = 0, info = TRUE)
unlink(tf)
expect_equal(ncol(x), 11)
expect_equal(class(x$date_received), "Date")
expect_equal(class(x$mo), "mo")
expect_equal(as.character(x$mo), "B_ESCHR_COLI")
expect_equal(is.rsi(x$peni), TRUE)
})

View File

@ -62,7 +62,7 @@ As with many uses in R, we need some additional packages for AMR analysis. Our p
Our `AMR` package depends on these packages and even extends their use and functions. Our `AMR` package depends on these packages and even extends their use and functions.
```{r lib packages, eval = FALSE} ```{r lib packages, message = FALSE, warning = FALSE, results = 'asis'}
library(dplyr) library(dplyr)
library(ggplot2) library(ggplot2)
library(AMR) library(AMR)
@ -71,11 +71,6 @@ library(AMR)
# install.packages(c("dplyr", "ggplot2", "AMR")) # install.packages(c("dplyr", "ggplot2", "AMR"))
``` ```
```{r lib packages 2, echo = FALSE, results = 'asis'}
library(AMR)
library(dplyr)
```
# Creation of data # Creation of data
We will create some fake example data to use for analysis. For antimicrobial resistance analysis, we need at least: a patient ID, name or code of a microorganism, a date and antimicrobial results (an antibiogram). It could also include a specimen type (e.g. to filter on blood or urine), the ward type (e.g. to filter on ICUs). We will create some fake example data to use for analysis. For antimicrobial resistance analysis, we need at least: a patient ID, name or code of a microorganism, a date and antimicrobial results (an antibiogram). It could also include a specimen type (e.g. to filter on blood or urine), the ward type (e.g. to filter on ICUs).