mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 18:46:11 +01:00
check for 2.0
This commit is contained in:
parent
9179e98e12
commit
80cfc503c2
@ -1,6 +1,6 @@
|
|||||||
Package: AMR
|
Package: AMR
|
||||||
Version: 1.8.2.9151
|
Version: 1.8.2.9152
|
||||||
Date: 2023-03-11
|
Date: 2023-03-12
|
||||||
Title: Antimicrobial Resistance Data Analysis
|
Title: Antimicrobial Resistance Data Analysis
|
||||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||||
data analysis and to work with microbial and antimicrobial properties by
|
data analysis and to work with microbial and antimicrobial properties by
|
||||||
|
4
NEWS.md
4
NEWS.md
@ -1,6 +1,4 @@
|
|||||||
# AMR 1.8.2.9151
|
# AMR 1.8.2.9152
|
||||||
|
|
||||||
*(this beta version will eventually become v2.0! We're happy to reach a new major milestone soon!)*
|
|
||||||
|
|
||||||
This is a new major release of the AMR package, with great new additions but also some breaking changes for current users. These are all listed below.
|
This is a new major release of the AMR package, with great new additions but also some breaking changes for current users. These are all listed below.
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@
|
|||||||
#'
|
#'
|
||||||
#' The `AMR` package is a [free and open-source](https://msberends.github.io/AMR/#copyright) R package with [zero dependencies](https://en.wikipedia.org/wiki/Dependency_hell) to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. **Our aim is to provide a standard** for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. [Many different researchers](https://msberends.github.io/AMR/authors.html) from around the globe are continually helping us to make this a successful and durable project!
|
#' The `AMR` package is a [free and open-source](https://msberends.github.io/AMR/#copyright) R package with [zero dependencies](https://en.wikipedia.org/wiki/Dependency_hell) to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. **Our aim is to provide a standard** for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. [Many different researchers](https://msberends.github.io/AMR/authors.html) from around the globe are continually helping us to make this a successful and durable project!
|
||||||
#'
|
#'
|
||||||
#' This work was published in the Journal of Statistical Software (Volume 104(3); [DOI 10.18637/jss.v104.i03](https://doi.org/10.18637/jss.v104.i03)) and formed the basis of two PhD theses ([DOI 10.33612/diss.177417131](https://doi.org/10.33612/diss.177417131) and [DOI 10.33612/diss.192486375](https://doi.org/10.33612/diss.192486375)).
|
#' This work was published in the Journal of Statistical Software (Volume 104(3); \doi{jss.v104.i03}) and formed the basis of two PhD theses (\doi{10.33612/diss.177417131} and \doi{10.33612/diss.192486375}).
|
||||||
#'
|
#'
|
||||||
#' After installing this package, R knows [**`r format_included_data_number(AMR::microorganisms)`**](https://msberends.github.io/AMR/reference/microorganisms.html) (updated December 2022) and all [**~600 antibiotic, antimycotic and antiviral drugs**](https://msberends.github.io/AMR/reference/antibiotics.html) by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl).
|
#' After installing this package, R knows [**`r format_included_data_number(AMR::microorganisms)` microorganisms**](https://msberends.github.io/AMR/reference/microorganisms.html) (updated `r format(TAXONOMY_VERSION$GBIF$accessed_date, "%B %Y")`) and all [**`r format_included_data_number(nrow(AMR::antibiotics) + nrow(AMR::antivirals))` antibiotic, antimycotic and antiviral drugs**](https://msberends.github.io/AMR/reference/antibiotics.html) by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl).
|
||||||
#'
|
#'
|
||||||
#' The `AMR` package is available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish and Ukrainian. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages.
|
#' The `AMR` package is available in `r vector_and(vapply(FUN.VALUE = character(1), LANGUAGES_SUPPORTED_NAMES, function(x) x$exonym), quotes = FALSE, sort = FALSE)`. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages.
|
||||||
#' @section Reference Data Publicly Available:
|
#' @section Reference Data Publicly Available:
|
||||||
#' All data sets in this `AMR` package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw).
|
#' All data sets in this `AMR` package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, SAS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit [our website for the download links](https://msberends.github.io/AMR/articles/datasets.html). The actual files are of course available on [our GitHub repository](https://github.com/msberends/AMR/tree/main/data-raw).
|
||||||
#' @source
|
#' @source
|
||||||
|
@ -63,9 +63,9 @@ pm_left_join <- function(x, y, by = NULL, suffix = c(".x", ".y")) {
|
|||||||
merged
|
merged
|
||||||
}
|
}
|
||||||
|
|
||||||
# support where() like tidyverse:
|
# support where() like tidyverse (this function will also be used when running `antibiogram()`):
|
||||||
where <- function(fn) {
|
where <- function(fn) {
|
||||||
# adapted from https://github.com/nathaneastwood/poorman/blob/52eb6947e0b4430cd588976ed8820013eddf955f/R/where.R#L17-L32
|
# based on https://github.com/nathaneastwood/poorman/blob/52eb6947e0b4430cd588976ed8820013eddf955f/R/where.R#L17-L32
|
||||||
if (!is.function(fn)) {
|
if (!is.function(fn)) {
|
||||||
stop_("`", deparse(substitute(fn)), "()` is not a valid predicate function.")
|
stop_("`", deparse(substitute(fn)), "()` is not a valid predicate function.")
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ where <- function(fn) {
|
|||||||
|
|
||||||
# copied and slightly rewritten from {poorman} under permissive license (2021-10-15)
|
# copied and slightly rewritten from {poorman} under permissive license (2021-10-15)
|
||||||
# https://github.com/nathaneastwood/poorman, MIT licensed, Nathan Eastwood, 2020
|
# https://github.com/nathaneastwood/poorman, MIT licensed, Nathan Eastwood, 2020
|
||||||
quick_case_when <- function(...) {
|
case_when_AMR <- function(...) {
|
||||||
fs <- list(...)
|
fs <- list(...)
|
||||||
lapply(fs, function(x) {
|
lapply(fs, function(x) {
|
||||||
if (!inherits(x, "formula")) {
|
if (!inherits(x, "formula")) {
|
||||||
@ -163,8 +163,8 @@ quick_case_when <- function(...) {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
rbind2 <- function(...) {
|
rbind_AMR <- function(...) {
|
||||||
# this is just rbind(), but then with the functionality of dplyr::bind_rows(),
|
# this is just rbind(), but with the functionality of dplyr::bind_rows(),
|
||||||
# to allow differences in available columns
|
# to allow differences in available columns
|
||||||
l <- list(...)
|
l <- list(...)
|
||||||
l_names <- unique(unlist(lapply(l, names)))
|
l_names <- unique(unlist(lapply(l, names)))
|
||||||
@ -633,7 +633,9 @@ documentation_date <- function(d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
format_included_data_number <- function(data) {
|
format_included_data_number <- function(data) {
|
||||||
if (is.data.frame(data)) {
|
if (is.numeric(data) && length(data) == 1) {
|
||||||
|
n <- data
|
||||||
|
} else if (is.data.frame(data)) {
|
||||||
n <- nrow(data)
|
n <- nrow(data)
|
||||||
} else {
|
} else {
|
||||||
n <- length(unique(data))
|
n <- length(unique(data))
|
||||||
@ -1502,7 +1504,7 @@ trimws2 <- function(..., whitespace = "[\u0009\u000A\u000B\u000C\u000D\u0020\u00
|
|||||||
trimws(..., whitespace = whitespace)
|
trimws(..., whitespace = whitespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
readRDS2 <- function(file, refhook = NULL) {
|
readRDS_AMR <- function(file, refhook = NULL) {
|
||||||
# this is readRDS with remote file support
|
# this is readRDS with remote file support
|
||||||
con <- file(file)
|
con <- file(file)
|
||||||
on.exit(close(con))
|
on.exit(close(con))
|
||||||
|
2
R/ab.R
2
R/ab.R
@ -495,7 +495,7 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
|
|||||||
# save to package env to save time for next time
|
# save to package env to save time for next time
|
||||||
if (isTRUE(initial_search)) {
|
if (isTRUE(initial_search)) {
|
||||||
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$x %in% x), , drop = FALSE]
|
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$x %in% x), , drop = FALSE]
|
||||||
AMR_env$ab_previously_coerced <- unique(rbind2(
|
AMR_env$ab_previously_coerced <- unique(rbind_AMR(
|
||||||
AMR_env$ab_previously_coerced,
|
AMR_env$ab_previously_coerced,
|
||||||
data.frame(
|
data.frame(
|
||||||
x = x,
|
x = x,
|
||||||
|
@ -179,7 +179,7 @@
|
|||||||
#' select(penicillins()) # only the 'J01CA01' column will be selected
|
#' select(penicillins()) # only the 'J01CA01' column will be selected
|
||||||
#' }
|
#' }
|
||||||
#' if (require("dplyr")) {
|
#' if (require("dplyr")) {
|
||||||
#' # with recent versions of dplyr this is all equal:
|
#' # with recent versions of dplyr, this is all equal:
|
||||||
#' x <- example_isolates[carbapenems() == "R", ]
|
#' x <- example_isolates[carbapenems() == "R", ]
|
||||||
#' y <- example_isolates %>% filter(carbapenems() == "R")
|
#' y <- example_isolates %>% filter(carbapenems() == "R")
|
||||||
#' z <- example_isolates %>% filter(if_all(carbapenems(), ~ .x == "R"))
|
#' z <- example_isolates %>% filter(if_all(carbapenems(), ~ .x == "R"))
|
||||||
@ -190,29 +190,33 @@
|
|||||||
#' # data.table --------------------------------------------------------------
|
#' # data.table --------------------------------------------------------------
|
||||||
#'
|
#'
|
||||||
#' # data.table is supported as well, just use it in the same way as with
|
#' # data.table is supported as well, just use it in the same way as with
|
||||||
#' # base R, but add `with = FALSE` if using a single AB selector:
|
#' # base R, but add `with = FALSE` if using a single AB selector.
|
||||||
#'
|
#'
|
||||||
#' if (require("data.table")) {
|
#' if (require("data.table")) {
|
||||||
#' dt <- as.data.table(example_isolates)
|
#' dt <- as.data.table(example_isolates)
|
||||||
#'
|
#'
|
||||||
#' print(
|
#' # this does not work, it returns column *names*
|
||||||
#' dt[, carbapenems()] # incorrect, returns column *names*
|
#' dt[, carbapenems()]
|
||||||
#' )
|
#' }
|
||||||
#' print(
|
#' if (require("data.table")) {
|
||||||
#' dt[, carbapenems(), with = FALSE] # so `with = FALSE` is required
|
#' # so `with = FALSE` is required
|
||||||
#' )
|
#' dt[, carbapenems(), with = FALSE]
|
||||||
|
#' }
|
||||||
#'
|
#'
|
||||||
#' # for multiple selections or AB selectors, `with = FALSE` is not needed:
|
#' # for multiple selections or AB selectors, `with = FALSE` is not needed:
|
||||||
#' print(
|
#' if (require("data.table")) {
|
||||||
#' dt[, c("mo", aminoglycosides())]
|
#' dt[, c("mo", aminoglycosides())]
|
||||||
#' )
|
#' }
|
||||||
#' print(
|
#' if (require("data.table")) {
|
||||||
#' dt[, c(carbapenems(), aminoglycosides())]
|
#' dt[, c(carbapenems(), aminoglycosides())]
|
||||||
#' )
|
#' }
|
||||||
#'
|
#'
|
||||||
#' # row filters are also supported:
|
#' # row filters are also supported:
|
||||||
#' print(dt[any(carbapenems() == "S"), ])
|
#' if (require("data.table")) {
|
||||||
#' print(dt[any(carbapenems() == "S"), penicillins(), with = FALSE])
|
#' dt[any(carbapenems() == "S"), ]
|
||||||
|
#' }
|
||||||
|
#' if (require("data.table")) {
|
||||||
|
#' dt[any(carbapenems() == "S"), penicillins(), with = FALSE]
|
||||||
#' }
|
#' }
|
||||||
#' }
|
#' }
|
||||||
ab_class <- function(ab_class,
|
ab_class <- function(ab_class,
|
||||||
|
@ -458,7 +458,7 @@ antibiogram <- function(x,
|
|||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
new_df <- long_to_wide(out[which(out$syndromic_group == grp), , drop = FALSE], digs = digits)
|
new_df <- long_to_wide(out[which(out$syndromic_group == grp), , drop = FALSE], digs = digits)
|
||||||
} else {
|
} else {
|
||||||
new_df <- rbind2(
|
new_df <- rbind_AMR(
|
||||||
new_df,
|
new_df,
|
||||||
long_to_wide(out[which(out$syndromic_group == grp), , drop = FALSE], digs = digits)
|
long_to_wide(out[which(out$syndromic_group == grp), , drop = FALSE], digs = digits)
|
||||||
)
|
)
|
||||||
|
2
R/av.R
2
R/av.R
@ -461,7 +461,7 @@ as.av <- function(x, flag_multiple_results = TRUE, info = interactive(), ...) {
|
|||||||
# save to package env to save time for next time
|
# save to package env to save time for next time
|
||||||
if (isTRUE(initial_search)) {
|
if (isTRUE(initial_search)) {
|
||||||
AMR_env$av_previously_coerced <- AMR_env$av_previously_coerced[which(!AMR_env$av_previously_coerced$x %in% x), , drop = FALSE]
|
AMR_env$av_previously_coerced <- AMR_env$av_previously_coerced[which(!AMR_env$av_previously_coerced$x %in% x), , drop = FALSE]
|
||||||
AMR_env$av_previously_coerced <- unique(rbind2(
|
AMR_env$av_previously_coerced <- unique(rbind_AMR(
|
||||||
AMR_env$av_previously_coerced,
|
AMR_env$av_previously_coerced,
|
||||||
data.frame(
|
data.frame(
|
||||||
x = x,
|
x = x,
|
||||||
|
@ -124,7 +124,7 @@ bug_drug_combinations <- function(x,
|
|||||||
m <- as.matrix(table(x))
|
m <- as.matrix(table(x))
|
||||||
data.frame(S = m["S", ], I = m["I", ], R = m["R", ], stringsAsFactors = FALSE)
|
data.frame(S = m["S", ], I = m["I", ], R = m["R", ], stringsAsFactors = FALSE)
|
||||||
})
|
})
|
||||||
merged <- do.call(rbind2, pivot)
|
merged <- do.call(rbind_AMR, pivot)
|
||||||
out_group <- data.frame(
|
out_group <- data.frame(
|
||||||
mo = rep(unique_mo[i], NROW(merged)),
|
mo = rep(unique_mo[i], NROW(merged)),
|
||||||
ab = rownames(merged),
|
ab = rownames(merged),
|
||||||
@ -144,14 +144,14 @@ bug_drug_combinations <- function(x,
|
|||||||
}
|
}
|
||||||
out_group <- cbind(group_values, out_group)
|
out_group <- cbind(group_values, out_group)
|
||||||
}
|
}
|
||||||
out <- rbind2(out, out_group)
|
out <- rbind_AMR(out, out_group)
|
||||||
}
|
}
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
# based on pm_apply_grouped_function
|
# based on pm_apply_grouped_function
|
||||||
apply_group <- function(.data, fn, groups, drop = FALSE, ...) {
|
apply_group <- function(.data, fn, groups, drop = FALSE, ...) {
|
||||||
grouped <- pm_split_into_groups(.data, groups, drop)
|
grouped <- pm_split_into_groups(.data, groups, drop)
|
||||||
res <- do.call(rbind2, unname(lapply(grouped, fn, ...)))
|
res <- do.call(rbind_AMR, unname(lapply(grouped, fn, ...)))
|
||||||
if (any(groups %in% colnames(res))) {
|
if (any(groups %in% colnames(res))) {
|
||||||
class(res) <- c("grouped_data", class(res))
|
class(res) <- c("grouped_data", class(res))
|
||||||
res <- pm_set_groups(res, groups[groups %in% colnames(res)])
|
res <- pm_set_groups(res, groups[groups %in% colnames(res)])
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#' @param x a [data.frame] resembling the [antibiotics] data set, at least containing columns "ab" and "name"
|
#' @param x a [data.frame] resembling the [antibiotics] data set, at least containing columns "ab" and "name"
|
||||||
#' @details **Important:** Due to how \R works, the [add_custom_antimicrobials()] function has to be run in every \R session - added antimicrobials are not stored between sessions and are thus lost when \R is exited.
|
#' @details **Important:** Due to how \R works, the [add_custom_antimicrobials()] function has to be run in every \R session - added antimicrobials are not stored between sessions and are thus lost when \R is exited.
|
||||||
#'
|
#'
|
||||||
#' There are two ways to automate this process:
|
#' There are two ways to circumvent this and automate the process of adding antimicrobials:
|
||||||
#'
|
#'
|
||||||
#' **Method 1:** Using the [package option][AMR-options] [`AMR_custom_ab`][AMR-options], which is the preferred method. To use this method:
|
#' **Method 1:** Using the [package option][AMR-options] [`AMR_custom_ab`][AMR-options], which is the preferred method. To use this method:
|
||||||
#'
|
#'
|
||||||
@ -48,7 +48,7 @@
|
|||||||
#'
|
#'
|
||||||
#' Upon package load, this file will be loaded and run through the [add_custom_antimicrobials()] function.
|
#' Upon package load, this file will be loaded and run through the [add_custom_antimicrobials()] function.
|
||||||
#'
|
#'
|
||||||
#' **Method 2:** Loading the antimicrobial additions directly from your `.Rprofile` file. An important downside is that this requires the `AMR` package to be installed or else this method will fail. To use this method:
|
#' **Method 2:** Loading the antimicrobial additions directly from your `.Rprofile` file. Note that the definitions will be stored in a user-specific \R file, which is a suboptimal workflow. To use this method:
|
||||||
#'
|
#'
|
||||||
#' 1. Edit the `.Rprofile` file using e.g. `utils::file.edit("~/.Rprofile")`.
|
#' 1. Edit the `.Rprofile` file using e.g. `utils::file.edit("~/.Rprofile")`.
|
||||||
#'
|
#'
|
||||||
@ -153,7 +153,7 @@ add_custom_antimicrobials <- function(x) {
|
|||||||
# assign new values
|
# assign new values
|
||||||
new_df[, col] <- x[, col, drop = TRUE]
|
new_df[, col] <- x[, col, drop = TRUE]
|
||||||
}
|
}
|
||||||
AMR_env$AB_lookup <- unique(rbind2(AMR_env$AB_lookup, new_df))
|
AMR_env$AB_lookup <- unique(rbind_AMR(AMR_env$AB_lookup, new_df))
|
||||||
|
|
||||||
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$ab %in% x$ab), , drop = FALSE]
|
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$ab %in% x$ab), , drop = FALSE]
|
||||||
class(AMR_env$AB_lookup$ab) <- c("ab", "character")
|
class(AMR_env$AB_lookup$ab) <- c("ab", "character")
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#'
|
#'
|
||||||
#' **Important:** Due to how \R works, the [add_custom_microorganisms()] function has to be run in every \R session - added microorganisms are not stored between sessions and are thus lost when \R is exited.
|
#' **Important:** Due to how \R works, the [add_custom_microorganisms()] function has to be run in every \R session - added microorganisms are not stored between sessions and are thus lost when \R is exited.
|
||||||
#'
|
#'
|
||||||
#' There are two ways to automate this process:
|
#' There are two ways to circumvent this and automate the process of adding microorganisms:
|
||||||
#'
|
#'
|
||||||
#' **Method 1:** Using the [package option][AMR-options] [`AMR_custom_mo`][AMR-options], which is the preferred method. To use this method:
|
#' **Method 1:** Using the [package option][AMR-options] [`AMR_custom_mo`][AMR-options], which is the preferred method. To use this method:
|
||||||
#'
|
#'
|
||||||
@ -50,7 +50,7 @@
|
|||||||
#'
|
#'
|
||||||
#' Upon package load, this file will be loaded and run through the [add_custom_microorganisms()] function.
|
#' Upon package load, this file will be loaded and run through the [add_custom_microorganisms()] function.
|
||||||
#'
|
#'
|
||||||
#' **Method 2:** Loading the microorganism directly from your `.Rprofile` file. An important downside is that this requires the `AMR` package to be installed or else this method will fail. To use this method:
|
#' **Method 2:** Loading the microorganism directly from your `.Rprofile` file. Note that the definitions will be stored in a user-specific \R file, which is a suboptimal workflow. To use this method:
|
||||||
#'
|
#'
|
||||||
#' 1. Edit the `.Rprofile` file using e.g. `utils::file.edit("~/.Rprofile")`.
|
#' 1. Edit the `.Rprofile` file using e.g. `utils::file.edit("~/.Rprofile")`.
|
||||||
#'
|
#'
|
||||||
@ -64,7 +64,7 @@
|
|||||||
#' )
|
#' )
|
||||||
#' ```
|
#' ```
|
||||||
#'
|
#'
|
||||||
#' Use [clear_custom_microorganisms()] to clear the previously added antimicrobials.
|
#' Use [clear_custom_microorganisms()] to clear the previously added microorganisms.
|
||||||
#' @seealso [add_custom_antimicrobials()] to add custom antimicrobials.
|
#' @seealso [add_custom_antimicrobials()] to add custom antimicrobials.
|
||||||
#' @rdname add_custom_microorganisms
|
#' @rdname add_custom_microorganisms
|
||||||
#' @export
|
#' @export
|
||||||
@ -279,7 +279,7 @@ add_custom_microorganisms <- function(x) {
|
|||||||
# clear previous coercions
|
# clear previous coercions
|
||||||
suppressMessages(mo_reset_session())
|
suppressMessages(mo_reset_session())
|
||||||
|
|
||||||
AMR_env$MO_lookup <- unique(rbind2(AMR_env$MO_lookup, new_df))
|
AMR_env$MO_lookup <- unique(rbind_AMR(AMR_env$MO_lookup, new_df))
|
||||||
class(AMR_env$MO_lookup$mo) <- c("mo", "character")
|
class(AMR_env$MO_lookup$mo) <- c("mo", "character")
|
||||||
if (nrow(x) <= 3) {
|
if (nrow(x) <= 3) {
|
||||||
message_("Added ", vector_and(italicise(x$fullname), quotes = FALSE), " to the internal `microorganisms` data set.")
|
message_("Added ", vector_and(italicise(x$fullname), quotes = FALSE), " to the internal `microorganisms` data set.")
|
||||||
@ -297,6 +297,9 @@ clear_custom_microorganisms <- function() {
|
|||||||
AMR_env$MO_lookup <- NULL
|
AMR_env$MO_lookup <- NULL
|
||||||
add_MO_lookup_to_AMR_env()
|
add_MO_lookup_to_AMR_env()
|
||||||
|
|
||||||
|
# clear previous coercions
|
||||||
|
suppressMessages(mo_reset_session())
|
||||||
|
|
||||||
n2 <- nrow(AMR_env$MO_lookup)
|
n2 <- nrow(AMR_env$MO_lookup)
|
||||||
AMR_env$custom_mo_codes <- character(0)
|
AMR_env$custom_mo_codes <- character(0)
|
||||||
AMR_env$mo_previously_coerced <- AMR_env$mo_previously_coerced[which(AMR_env$mo_previously_coerced$mo %in% AMR_env$MO_lookup$mo), , drop = FALSE]
|
AMR_env$mo_previously_coerced <- AMR_env$mo_previously_coerced[which(AMR_env$mo_previously_coerced$mo %in% AMR_env$MO_lookup$mo), , drop = FALSE]
|
||||||
|
@ -476,7 +476,7 @@ eucast_rules <- function(x,
|
|||||||
amox$base_ab <- "AMX"
|
amox$base_ab <- "AMX"
|
||||||
amox$base_name <- ab_name("AMX", language = NULL)
|
amox$base_name <- ab_name("AMX", language = NULL)
|
||||||
# merge and sort
|
# merge and sort
|
||||||
ab_enzyme <- rbind2(ab_enzyme, ampi, amox)
|
ab_enzyme <- rbind_AMR(ab_enzyme, ampi, amox)
|
||||||
ab_enzyme <- ab_enzyme[order(ab_enzyme$enzyme_name), , drop = FALSE]
|
ab_enzyme <- ab_enzyme[order(ab_enzyme$enzyme_name), , drop = FALSE]
|
||||||
|
|
||||||
for (i in seq_len(nrow(ab_enzyme))) {
|
for (i in seq_len(nrow(ab_enzyme))) {
|
||||||
@ -1162,7 +1162,7 @@ edit_sir <- function(x,
|
|||||||
)
|
)
|
||||||
verbose_new <- verbose_new %pm>% pm_filter(old != new | is.na(old) | is.na(new) & !is.na(old))
|
verbose_new <- verbose_new %pm>% pm_filter(old != new | is.na(old) | is.na(new) & !is.na(old))
|
||||||
# save changes to data set 'verbose_info'
|
# save changes to data set 'verbose_info'
|
||||||
track_changes$verbose_info <- rbind2(
|
track_changes$verbose_info <- rbind_AMR(
|
||||||
track_changes$verbose_info,
|
track_changes$verbose_info,
|
||||||
verbose_new
|
verbose_new
|
||||||
)
|
)
|
||||||
@ -1216,7 +1216,7 @@ eucast_dosage <- function(ab, administration = "iv", version_breakpoints = 12.0)
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
out <- do.call(rbind2, lapply(lst, as.data.frame, stringsAsFactors = FALSE))
|
out <- do.call(rbind_AMR, lapply(lst, as.data.frame, stringsAsFactors = FALSE))
|
||||||
rownames(out) <- NULL
|
rownames(out) <- NULL
|
||||||
out$ab <- ab
|
out$ab <- ab
|
||||||
out$name <- ab_name(ab, language = NULL)
|
out$name <- ab_name(ab, language = NULL)
|
||||||
|
4
R/mo.R
4
R/mo.R
@ -329,7 +329,7 @@ as.mo <- function(x,
|
|||||||
result_mo <- NA_character_
|
result_mo <- NA_character_
|
||||||
} else {
|
} else {
|
||||||
result_mo <- AMR_env$MO_lookup$mo[match(top_hits[1], AMR_env$MO_lookup$fullname)]
|
result_mo <- AMR_env$MO_lookup$mo[match(top_hits[1], AMR_env$MO_lookup$fullname)]
|
||||||
AMR_env$mo_uncertainties <- rbind2(
|
AMR_env$mo_uncertainties <- rbind_AMR(
|
||||||
AMR_env$mo_uncertainties,
|
AMR_env$mo_uncertainties,
|
||||||
data.frame(
|
data.frame(
|
||||||
original_input = x_search,
|
original_input = x_search,
|
||||||
@ -343,7 +343,7 @@ as.mo <- function(x,
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
# save to package env to save time for next time
|
# save to package env to save time for next time
|
||||||
AMR_env$mo_previously_coerced <- unique(rbind2(
|
AMR_env$mo_previously_coerced <- unique(rbind_AMR(
|
||||||
AMR_env$mo_previously_coerced,
|
AMR_env$mo_previously_coerced,
|
||||||
data.frame(
|
data.frame(
|
||||||
x = paste(x_search, minimum_matching_score),
|
x = paste(x_search, minimum_matching_score),
|
||||||
|
@ -149,7 +149,7 @@ set_mo_source <- function(path, destination = getOption("AMR_mo_source", "~/mo_s
|
|||||||
|
|
||||||
df <- NULL
|
df <- NULL
|
||||||
if (path %like% "[.]rds$") {
|
if (path %like% "[.]rds$") {
|
||||||
df <- readRDS2(path)
|
df <- readRDS_AMR(path)
|
||||||
} else if (path %like% "[.]xlsx?$") {
|
} else if (path %like% "[.]xlsx?$") {
|
||||||
# is Excel file (old or new)
|
# is Excel file (old or new)
|
||||||
stop_ifnot_installed("readxl")
|
stop_ifnot_installed("readxl")
|
||||||
@ -248,7 +248,7 @@ get_mo_source <- function(destination = getOption("AMR_mo_source", "~/mo_source.
|
|||||||
return(NULL)
|
return(NULL)
|
||||||
}
|
}
|
||||||
if (is.null(AMR_env$mo_source)) {
|
if (is.null(AMR_env$mo_source)) {
|
||||||
AMR_env$mo_source <- readRDS2(path.expand(destination))
|
AMR_env$mo_source <- readRDS_AMR(path.expand(destination))
|
||||||
}
|
}
|
||||||
|
|
||||||
old_time <- attributes(AMR_env$mo_source)$mo_source_timestamp
|
old_time <- attributes(AMR_env$mo_source)$mo_source_timestamp
|
||||||
|
6
R/plot.R
6
R/plot.R
@ -567,13 +567,13 @@ plot.sir <- function(x,
|
|||||||
data$s <- round((data$n / sum(data$n)) * 100, 1)
|
data$s <- round((data$n / sum(data$n)) * 100, 1)
|
||||||
|
|
||||||
if (!"S" %in% data$x) {
|
if (!"S" %in% data$x) {
|
||||||
data <- rbind2(data, data.frame(x = "S", n = 0, s = 0, stringsAsFactors = FALSE))
|
data <- rbind_AMR(data, data.frame(x = "S", n = 0, s = 0, stringsAsFactors = FALSE))
|
||||||
}
|
}
|
||||||
if (!"I" %in% data$x) {
|
if (!"I" %in% data$x) {
|
||||||
data <- rbind2(data, data.frame(x = "I", n = 0, s = 0, stringsAsFactors = FALSE))
|
data <- rbind_AMR(data, data.frame(x = "I", n = 0, s = 0, stringsAsFactors = FALSE))
|
||||||
}
|
}
|
||||||
if (!"R" %in% data$x) {
|
if (!"R" %in% data$x) {
|
||||||
data <- rbind2(data, data.frame(x = "R", n = 0, s = 0, stringsAsFactors = FALSE))
|
data <- rbind_AMR(data, data.frame(x = "R", n = 0, s = 0, stringsAsFactors = FALSE))
|
||||||
}
|
}
|
||||||
|
|
||||||
data$x <- factor(data$x, levels = c("S", "I", "R"), ordered = TRUE)
|
data$x <- factor(data$x, levels = c("S", "I", "R"), ordered = TRUE)
|
||||||
|
6
R/sir.R
6
R/sir.R
@ -999,7 +999,7 @@ as_sir_method <- function(method_short,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (method == "mic") {
|
if (method == "mic") {
|
||||||
new_sir <- quick_case_when(
|
new_sir <- case_when_AMR(
|
||||||
is.na(values) ~ NA_sir_,
|
is.na(values) ~ NA_sir_,
|
||||||
values <= breakpoints_current$breakpoint_S ~ as.sir("S"),
|
values <= breakpoints_current$breakpoint_S ~ as.sir("S"),
|
||||||
guideline_coerced %like% "EUCAST" & values > breakpoints_current$breakpoint_R ~ as.sir("R"),
|
guideline_coerced %like% "EUCAST" & values > breakpoints_current$breakpoint_R ~ as.sir("R"),
|
||||||
@ -1010,7 +1010,7 @@ as_sir_method <- function(method_short,
|
|||||||
TRUE ~ NA_sir_
|
TRUE ~ NA_sir_
|
||||||
)
|
)
|
||||||
} else if (method == "disk") {
|
} else if (method == "disk") {
|
||||||
new_sir <- quick_case_when(
|
new_sir <- case_when_AMR(
|
||||||
is.na(values) ~ NA_sir_,
|
is.na(values) ~ NA_sir_,
|
||||||
as.double(values) >= as.double(breakpoints_current$breakpoint_S) ~ as.sir("S"),
|
as.double(values) >= as.double(breakpoints_current$breakpoint_S) ~ as.sir("S"),
|
||||||
guideline_coerced %like% "EUCAST" & as.double(values) < as.double(breakpoints_current$breakpoint_R) ~ as.sir("R"),
|
guideline_coerced %like% "EUCAST" & as.double(values) < as.double(breakpoints_current$breakpoint_R) ~ as.sir("R"),
|
||||||
@ -1023,7 +1023,7 @@ as_sir_method <- function(method_short,
|
|||||||
}
|
}
|
||||||
|
|
||||||
# write to verbose output
|
# write to verbose output
|
||||||
AMR_env$sir_interpretation_history <- rbind2(
|
AMR_env$sir_interpretation_history <- rbind_AMR(
|
||||||
AMR_env$sir_interpretation_history,
|
AMR_env$sir_interpretation_history,
|
||||||
# recycling 1 to 2 rows does not seem to work, which is why rep() was added
|
# recycling 1 to 2 rows does not seem to work, which is why rep() was added
|
||||||
data.frame(
|
data.frame(
|
||||||
|
@ -322,7 +322,7 @@ sir_calc_df <- function(type, # "proportion", "count" or "both"
|
|||||||
}
|
}
|
||||||
out_new <- cbind(group_values, out_new)
|
out_new <- cbind(group_values, out_new)
|
||||||
}
|
}
|
||||||
out <- rbind2(out, out_new)
|
out <- rbind_AMR(out, out_new)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out
|
out
|
||||||
@ -331,7 +331,7 @@ sir_calc_df <- function(type, # "proportion", "count" or "both"
|
|||||||
# based on pm_apply_grouped_function
|
# based on pm_apply_grouped_function
|
||||||
apply_group <- function(.data, fn, groups, drop = FALSE, ...) {
|
apply_group <- function(.data, fn, groups, drop = FALSE, ...) {
|
||||||
grouped <- pm_split_into_groups(.data, groups, drop)
|
grouped <- pm_split_into_groups(.data, groups, drop)
|
||||||
res <- do.call(rbind2, unname(lapply(grouped, fn, ...)))
|
res <- do.call(rbind_AMR, unname(lapply(grouped, fn, ...)))
|
||||||
if (any(groups %in% colnames(res))) {
|
if (any(groups %in% colnames(res))) {
|
||||||
class(res) <- c("grouped_data", class(res))
|
class(res) <- c("grouped_data", class(res))
|
||||||
res <- pm_set_groups(res, groups[groups %in% colnames(res)])
|
res <- pm_set_groups(res, groups[groups %in% colnames(res)])
|
||||||
|
4
R/zzz.R
4
R/zzz.R
@ -195,7 +195,7 @@ if (utf8_supported && !is_latex) {
|
|||||||
# if custom ab option is available, load it
|
# if custom ab option is available, load it
|
||||||
if (!is.null(getOption("AMR_custom_ab")) && file.exists(getOption("AMR_custom_ab", default = ""))) {
|
if (!is.null(getOption("AMR_custom_ab")) && file.exists(getOption("AMR_custom_ab", default = ""))) {
|
||||||
packageStartupMessage("Adding custom antimicrobials from '", getOption("AMR_custom_ab"), "'...", appendLF = FALSE)
|
packageStartupMessage("Adding custom antimicrobials from '", getOption("AMR_custom_ab"), "'...", appendLF = FALSE)
|
||||||
x <- readRDS2(getOption("AMR_custom_ab"))
|
x <- readRDS_AMR(getOption("AMR_custom_ab"))
|
||||||
tryCatch(
|
tryCatch(
|
||||||
{
|
{
|
||||||
suppressWarnings(suppressMessages(add_custom_antimicrobials(x)))
|
suppressWarnings(suppressMessages(add_custom_antimicrobials(x)))
|
||||||
@ -207,7 +207,7 @@ if (utf8_supported && !is_latex) {
|
|||||||
# if custom mo option is available, load it
|
# if custom mo option is available, load it
|
||||||
if (!is.null(getOption("AMR_custom_mo")) && file.exists(getOption("AMR_custom_mo", default = ""))) {
|
if (!is.null(getOption("AMR_custom_mo")) && file.exists(getOption("AMR_custom_mo", default = ""))) {
|
||||||
packageStartupMessage("Adding custom microorganisms from '", getOption("AMR_custom_mo"), "'...", appendLF = FALSE)
|
packageStartupMessage("Adding custom microorganisms from '", getOption("AMR_custom_mo"), "'...", appendLF = FALSE)
|
||||||
x <- readRDS2(getOption("AMR_custom_mo"))
|
x <- readRDS_AMR(getOption("AMR_custom_mo"))
|
||||||
tryCatch(
|
tryCatch(
|
||||||
{
|
{
|
||||||
suppressWarnings(suppressMessages(add_custom_microorganisms(x)))
|
suppressWarnings(suppressMessages(add_custom_microorganisms(x)))
|
||||||
|
26
README.md
26
README.md
@ -27,26 +27,8 @@ install.packages("AMR")
|
|||||||
|
|
||||||
It will be downloaded and installed automatically. For RStudio, click on the menu *Tools* > *Install Packages...* and then type in "AMR" and press <kbd>Install</kbd>.
|
It will be downloaded and installed automatically. For RStudio, click on the menu *Tools* > *Install Packages...* and then type in "AMR" and press <kbd>Install</kbd>.
|
||||||
|
|
||||||
### Copyright
|
----
|
||||||
|
|
||||||
This R package is licensed under the [GNU General Public License (GPL) v2.0](https://github.com/msberends/AMR/blob/main/LICENSE). In a nutshell, this means that this package:
|
<small>
|
||||||
|
This AMR package for R is free, open-source software and licensed under the [GNU General Public License v2.0 (GPL-2)](https://msberends.github.io/AMR/LICENSE-text.html). These requirements are consequently legally binding: modifications must be released under the same license when distributing the package, changes made to the code must be documented, source code must be made available when the package is distributed, and a copy of the license and copyright notice must be included with the package.
|
||||||
- May be used for commercial purposes
|
</small>
|
||||||
|
|
||||||
- May be used for private purposes
|
|
||||||
|
|
||||||
- May **not** be used for patent purposes
|
|
||||||
|
|
||||||
- May be modified, although:
|
|
||||||
|
|
||||||
- Modifications **must** be released under the same license when distributing the package
|
|
||||||
- Changes made to the code **must** be documented
|
|
||||||
|
|
||||||
- May be distributed, although:
|
|
||||||
|
|
||||||
- Source code **must** be made available when the package is distributed
|
|
||||||
- A copy of the license and copyright notice **must** be included with the package.
|
|
||||||
|
|
||||||
- Comes with a LIMITATION of liability
|
|
||||||
|
|
||||||
- Comes with NO warranty
|
|
||||||
|
@ -30,11 +30,11 @@ Welcome to the \code{AMR} package.
|
|||||||
|
|
||||||
The \code{AMR} package is a \href{https://msberends.github.io/AMR/#copyright}{free and open-source} R package with \href{https://en.wikipedia.org/wiki/Dependency_hell}{zero dependencies} to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. \strong{Our aim is to provide a standard} for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. \href{https://msberends.github.io/AMR/authors.html}{Many different researchers} from around the globe are continually helping us to make this a successful and durable project!
|
The \code{AMR} package is a \href{https://msberends.github.io/AMR/#copyright}{free and open-source} R package with \href{https://en.wikipedia.org/wiki/Dependency_hell}{zero dependencies} to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. \strong{Our aim is to provide a standard} for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. \href{https://msberends.github.io/AMR/authors.html}{Many different researchers} from around the globe are continually helping us to make this a successful and durable project!
|
||||||
|
|
||||||
This work was published in the Journal of Statistical Software (Volume 104(3); \href{https://doi.org/10.18637/jss.v104.i03}{DOI 10.18637/jss.v104.i03}) and formed the basis of two PhD theses (\href{https://doi.org/10.33612/diss.177417131}{DOI 10.33612/diss.177417131} and \href{https://doi.org/10.33612/diss.192486375}{DOI 10.33612/diss.192486375}).
|
This work was published in the Journal of Statistical Software (Volume 104(3); \doi{jss.v104.i03}) and formed the basis of two PhD theses (\doi{10.33612/diss.177417131} and \doi{10.33612/diss.192486375}).
|
||||||
|
|
||||||
After installing this package, R knows \href{https://msberends.github.io/AMR/reference/microorganisms.html}{\strong{~52 000}} (updated December 2022) and all \href{https://msberends.github.io/AMR/reference/antibiotics.html}{\strong{~600 antibiotic, antimycotic and antiviral drugs}} by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). \strong{It was designed to work in any setting, including those with very limited resources}. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the \href{https://www.rug.nl}{University of Groningen}, in collaboration with non-profit organisations \href{https://www.certe.nl}{Certe Medical Diagnostics and Advice Foundation} and \href{https://www.umcg.nl}{University Medical Center Groningen}.
|
After installing this package, R knows \href{https://msberends.github.io/AMR/reference/microorganisms.html}{\strong{~52 000 microorganisms}} (updated December 2022) and all \href{https://msberends.github.io/AMR/reference/antibiotics.html}{\strong{~600 antibiotic, antimycotic and antiviral drugs}} by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data. This package works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). \strong{It was designed to work in any setting, including those with very limited resources}. It was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the \href{https://www.rug.nl}{University of Groningen}, in collaboration with non-profit organisations \href{https://www.certe.nl}{Certe Medical Diagnostics and Advice Foundation} and \href{https://www.umcg.nl}{University Medical Center Groningen}.
|
||||||
|
|
||||||
The \code{AMR} package is available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish and Ukrainian. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages.
|
The \code{AMR} package is available in English, Chinese, Czech, Danish, Dutch, Finnish, French, German, Greek, Italian, Japanese, Norwegian, Polish, Portuguese, Romanian, Russian, Spanish, Swedish, Turkish, and Ukrainian. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages.
|
||||||
}
|
}
|
||||||
\section{Reference Data Publicly Available}{
|
\section{Reference Data Publicly Available}{
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ With \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} you c
|
|||||||
\details{
|
\details{
|
||||||
\strong{Important:} Due to how \R works, the \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} function has to be run in every \R session - added antimicrobials are not stored between sessions and are thus lost when \R is exited.
|
\strong{Important:} Due to how \R works, the \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} function has to be run in every \R session - added antimicrobials are not stored between sessions and are thus lost when \R is exited.
|
||||||
|
|
||||||
There are two ways to automate this process:
|
There are two ways to circumvent this and automate the process of adding antimicrobials:
|
||||||
|
|
||||||
\strong{Method 1:} Using the \link[=AMR-options]{package option} \code{\link[=AMR-options]{AMR_custom_ab}}, which is the preferred method. To use this method:
|
\strong{Method 1:} Using the \link[=AMR-options]{package option} \code{\link[=AMR-options]{AMR_custom_ab}}, which is the preferred method. To use this method:
|
||||||
\enumerate{
|
\enumerate{
|
||||||
@ -32,7 +32,7 @@ options(AMR_custom_ab = "~/my_custom_ab.rds")
|
|||||||
Upon package load, this file will be loaded and run through the \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} function.
|
Upon package load, this file will be loaded and run through the \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} function.
|
||||||
}
|
}
|
||||||
|
|
||||||
\strong{Method 2:} Loading the antimicrobial additions directly from your \code{.Rprofile} file. An important downside is that this requires the \code{AMR} package to be installed or else this method will fail. To use this method:
|
\strong{Method 2:} Loading the antimicrobial additions directly from your \code{.Rprofile} file. Note that the definitions will be stored in a user-specific \R file, which is a suboptimal workflow. To use this method:
|
||||||
\enumerate{
|
\enumerate{
|
||||||
\item Edit the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}.
|
\item Edit the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}.
|
||||||
\item Add a text like below and save the file:
|
\item Add a text like below and save the file:
|
||||||
|
@ -20,7 +20,7 @@ This function will fill in missing taxonomy for you, if specific taxonomic colum
|
|||||||
|
|
||||||
\strong{Important:} Due to how \R works, the \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} function has to be run in every \R session - added microorganisms are not stored between sessions and are thus lost when \R is exited.
|
\strong{Important:} Due to how \R works, the \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} function has to be run in every \R session - added microorganisms are not stored between sessions and are thus lost when \R is exited.
|
||||||
|
|
||||||
There are two ways to automate this process:
|
There are two ways to circumvent this and automate the process of adding microorganisms:
|
||||||
|
|
||||||
\strong{Method 1:} Using the \link[=AMR-options]{package option} \code{\link[=AMR-options]{AMR_custom_mo}}, which is the preferred method. To use this method:
|
\strong{Method 1:} Using the \link[=AMR-options]{package option} \code{\link[=AMR-options]{AMR_custom_mo}}, which is the preferred method. To use this method:
|
||||||
\enumerate{
|
\enumerate{
|
||||||
@ -34,7 +34,7 @@ options(AMR_custom_mo = "~/my_custom_mo.rds")
|
|||||||
Upon package load, this file will be loaded and run through the \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} function.
|
Upon package load, this file will be loaded and run through the \code{\link[=add_custom_microorganisms]{add_custom_microorganisms()}} function.
|
||||||
}
|
}
|
||||||
|
|
||||||
\strong{Method 2:} Loading the microorganism directly from your \code{.Rprofile} file. An important downside is that this requires the \code{AMR} package to be installed or else this method will fail. To use this method:
|
\strong{Method 2:} Loading the microorganism directly from your \code{.Rprofile} file. Note that the definitions will be stored in a user-specific \R file, which is a suboptimal workflow. To use this method:
|
||||||
\enumerate{
|
\enumerate{
|
||||||
\item Edit the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}.
|
\item Edit the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}.
|
||||||
\item Add a text like below and save the file:
|
\item Add a text like below and save the file:
|
||||||
@ -47,7 +47,7 @@ Upon package load, this file will be loaded and run through the \code{\link[=add
|
|||||||
}\if{html}{\out{</div>}}
|
}\if{html}{\out{</div>}}
|
||||||
}
|
}
|
||||||
|
|
||||||
Use \code{\link[=clear_custom_microorganisms]{clear_custom_microorganisms()}} to clear the previously added antimicrobials.
|
Use \code{\link[=clear_custom_microorganisms]{clear_custom_microorganisms()}} to clear the previously added microorganisms.
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
\donttest{
|
\donttest{
|
||||||
|
@ -299,7 +299,7 @@ if (require("dplyr")) {
|
|||||||
select(penicillins()) # only the 'J01CA01' column will be selected
|
select(penicillins()) # only the 'J01CA01' column will be selected
|
||||||
}
|
}
|
||||||
if (require("dplyr")) {
|
if (require("dplyr")) {
|
||||||
# with recent versions of dplyr this is all equal:
|
# with recent versions of dplyr, this is all equal:
|
||||||
x <- example_isolates[carbapenems() == "R", ]
|
x <- example_isolates[carbapenems() == "R", ]
|
||||||
y <- example_isolates \%>\% filter(carbapenems() == "R")
|
y <- example_isolates \%>\% filter(carbapenems() == "R")
|
||||||
z <- example_isolates \%>\% filter(if_all(carbapenems(), ~ .x == "R"))
|
z <- example_isolates \%>\% filter(if_all(carbapenems(), ~ .x == "R"))
|
||||||
@ -310,29 +310,33 @@ if (require("dplyr")) {
|
|||||||
# data.table --------------------------------------------------------------
|
# data.table --------------------------------------------------------------
|
||||||
|
|
||||||
# data.table is supported as well, just use it in the same way as with
|
# data.table is supported as well, just use it in the same way as with
|
||||||
# base R, but add `with = FALSE` if using a single AB selector:
|
# base R, but add `with = FALSE` if using a single AB selector.
|
||||||
|
|
||||||
if (require("data.table")) {
|
if (require("data.table")) {
|
||||||
dt <- as.data.table(example_isolates)
|
dt <- as.data.table(example_isolates)
|
||||||
|
|
||||||
print(
|
# this does not work, it returns column *names*
|
||||||
dt[, carbapenems()] # incorrect, returns column *names*
|
dt[, carbapenems()]
|
||||||
)
|
}
|
||||||
print(
|
if (require("data.table")) {
|
||||||
dt[, carbapenems(), with = FALSE] # so `with = FALSE` is required
|
# so `with = FALSE` is required
|
||||||
)
|
dt[, carbapenems(), with = FALSE]
|
||||||
|
}
|
||||||
|
|
||||||
# for multiple selections or AB selectors, `with = FALSE` is not needed:
|
# for multiple selections or AB selectors, `with = FALSE` is not needed:
|
||||||
print(
|
if (require("data.table")) {
|
||||||
dt[, c("mo", aminoglycosides())]
|
dt[, c("mo", aminoglycosides())]
|
||||||
)
|
}
|
||||||
print(
|
if (require("data.table")) {
|
||||||
dt[, c(carbapenems(), aminoglycosides())]
|
dt[, c(carbapenems(), aminoglycosides())]
|
||||||
)
|
}
|
||||||
|
|
||||||
# row filters are also supported:
|
# row filters are also supported:
|
||||||
print(dt[any(carbapenems() == "S"), ])
|
if (require("data.table")) {
|
||||||
print(dt[any(carbapenems() == "S"), penicillins(), with = FALSE])
|
dt[any(carbapenems() == "S"), ]
|
||||||
|
}
|
||||||
|
if (require("data.table")) {
|
||||||
|
dt[any(carbapenems() == "S"), penicillins(), with = FALSE]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,13 @@ Note: to keep the package size as small as possible, we only included this vigne
|
|||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
The `AMR` package is a [free and open-source](https://msberends.github.io/AMR/#copyright) R package with [zero dependencies](https://en.wikipedia.org/wiki/Dependency_hell) to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. **Our aim is to provide a standard** for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting.
|
The `AMR` package is a [free and open-source](https://msberends.github.io/AMR/#copyright) R package with [zero dependencies](https://en.wikipedia.org/wiki/Dependency_hell) to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial data and properties, by using evidence-based methods. **Our aim is to provide a standard** for clean and reproducible AMR data analysis, that can therefore empower epidemiological analyses to continuously enable surveillance and treatment evaluation in any setting. [Many different researchers](https://msberends.github.io/AMR/authors.html) from around the globe are continually helping us to make this a successful and durable project!
|
||||||
|
|
||||||
This work was published in the Journal of Statistical Software (Volume 104(3); [DOI 10.18637/jss.v104.i03](https://doi.org/10.18637/jss.v104.i03)) and formed the basis of two PhD theses ([DOI 10.33612/diss.177417131](https://doi.org/10.33612/diss.177417131) and [DOI 10.33612/diss.192486375](https://doi.org/10.33612/diss.192486375)).
|
This work was published in the Journal of Statistical Software (Volume 104(3); [DOI 10.18637/jss.v104.i03](https://doi.org/10.18637/jss.v104.i03)) and formed the basis of two PhD theses ([DOI 10.33612/diss.177417131](https://doi.org/10.33612/diss.177417131) and [DOI 10.33612/diss.192486375](https://doi.org/10.33612/diss.192486375)).
|
||||||
|
|
||||||
After installing this package, R knows `r AMR:::format_included_data_number(AMR::microorganisms)` distinct microbial species and all `r AMR:::format_included_data_number(rbind(AMR::antibiotics[, "atc", drop = FALSE], AMR::antivirals[, "atc", drop = FALSE]))` antibiotic, antimycotic and antiviral drugs by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data.
|
After installing this package, R knows `r AMR:::format_included_data_number(AMR::microorganisms)` distinct microbial species and all `r AMR:::format_included_data_number(rbind(AMR::antibiotics[, "atc", drop = FALSE], AMR::antivirals[, "atc", drop = FALSE]))` antibiotic, antimycotic and antiviral drugs by name and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED CT), and knows all about valid SIR and MIC values. The integral breakpoint guidelines from CLSI and EUCAST are included from the last 10 years. It supports and can read any data format, including WHONET data.
|
||||||
|
|
||||||
The `AMR` package is available in English, Chinese, Danish, Dutch, French, German, Greek, Italian, Japanese, Polish, Portuguese, Russian, Spanish, Swedish, Turkish and Ukrainian. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages.
|
With the help of contributors from all corners of the world, the `AMR` package is available in English, Czech, Chinese, Danish, Dutch, Finnish, French, German, Greek, Italian, Japanese, Norwegian, Polish, Portuguese, Romanian, Russian, Spanish, Swedish, Turkish, and Ukrainian. Antimicrobial drug (group) names and colloquial microorganism names are provided in these languages.
|
||||||
|
|
||||||
This package is fully independent of any other R package and works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. Since its first public release in early 2018, this package has been downloaded from more than 175 countries.
|
This package is fully independent of any other R package and works on Windows, macOS and Linux with all versions of R since R-3.0 (April 2013). **It was designed to work in any setting, including those with very limited resources**. Since its first public release in early 2018, this package has been downloaded from more than 175 countries.
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ This package can be used for:
|
|||||||
|
|
||||||
All reference data sets (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) in this `AMR` package are publicly and freely available. We continually export our data sets to formats for use in R, SPSS, SAS, Stata and Excel. We also supply flat files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please find [all download links on our website](https://msberends.github.io/AMR/articles/datasets.html), which is automatically updated with every code change.
|
All reference data sets (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) in this `AMR` package are publicly and freely available. We continually export our data sets to formats for use in R, SPSS, SAS, Stata and Excel. We also supply flat files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please find [all download links on our website](https://msberends.github.io/AMR/articles/datasets.html), which is automatically updated with every code change.
|
||||||
|
|
||||||
This R package was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl), and is being [actively and durably maintained](./news) by two public healthcare organisations in the Netherlands.
|
This R package was created for both routine data analysis and academic research at the Faculty of Medical Sciences of the [University of Groningen](https://www.rug.nl), in collaboration with non-profit organisations [Certe Medical Diagnostics and Advice Foundation](https://www.certe.nl) and [University Medical Center Groningen](https://www.umcg.nl), and is being [actively and durably maintained](https://msberends.github.io/AMR/news) by two public healthcare organisations in the Netherlands.
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user