1
0
mirror of https://github.com/msberends/AMR.git synced 2025-04-17 18:30:33 +02:00

(v2.1.1.9186) replace antibiotics with antimicrobials!

This commit is contained in:
dr. M.S. (Matthijs) Berends 2025-03-07 20:43:26 +01:00
parent f2b2a450cb
commit f7938289eb
No known key found for this signature in database
140 changed files with 4870 additions and 4702 deletions

View File

@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 5128c748-a412-44db-a5fb-45c68c93dd10
RestoreWorkspace: No
SaveWorkspace: No

View File

@ -1,6 +1,6 @@
Package: AMR
Version: 2.1.1.9183
Date: 2025-03-03
Version: 2.1.1.9186
Date: 2025-03-07
Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by

View File

@ -159,6 +159,7 @@ export(amr_distance_from_row)
export(amr_selector)
export(anti_join_microorganisms)
export(antibiogram)
export(antibiotics)
export(antifungals)
export(antimicrobials_equal)
export(antimycobacterials)

View File

@ -1,4 +1,4 @@
# AMR 2.1.1.9183
# AMR 2.1.1.9186
*(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://msberends.github.io/AMR/#latest-development-version).)*
@ -6,14 +6,15 @@
This package now supports not only tools for AMR data analysis in clinical settings, but also for veterinary and environmental microbiology. This was made possible through a collaboration with the [University of Prince Edward Island's Atlantic Veterinary College](https://www.upei.ca/avc), Canada. To celebrate this great improvement of the package, we also updated the package logo to reflect this change.
## Breaking
* Removed all functions and references that used the deprecated `rsi` class, which were all replaced with their `sir` equivalents two years ago
* Dataset `antibiotics` has been renamed to `antimicrobials` as the data set contains more than just antibiotics. Calling `antibiotics` will still work, but now returns a warning.
* Removed all functions and references that used the deprecated `rsi` class, which were all replaced with their `sir` equivalents two years ago.
## New
* **One Health implementation**
* Function `as.sir()` now has extensive support for veterinary breakpoints from CLSI. Use `breakpoint_type = "animal"` and set the `host` argument to a variable that contains animal species names.
* The CLSI VET09 guideline has been implemented to address cases where veterinary breakpoints are missing (only applies when `guideline` is set to CLSI)
* The `clinical_breakpoints` data set contains all these breakpoints, and can be downloaded on our [download page](https://msberends.github.io/AMR/articles/datasets.html).
* The `antibiotics` data set contains all veterinary antibiotics, such as pradofloxacin and enrofloxacin. All WHOCC codes for veterinary use have been added as well.
* The (new) `antimicrobials` data set contains all veterinary antibiotics, such as pradofloxacin and enrofloxacin. All WHOCC codes for veterinary use have been added as well.
* `ab_atc()` now supports ATC codes of veterinary antibiotics (that all start with "Q")
* `ab_url()` now supports retrieving the WHOCC url of their ATCvet pages
* **Support for WISCA antibiograms**
@ -57,7 +58,7 @@ This package now supports not only tools for AMR data analysis in clinical setti
* Added a new argument `return_all` to all selectors, which defaults to `TRUE` to include any match. With `FALSE`, the old behaviour, only the first hit for each unique antimicrobial is returned.
* All selectors can now be run as a separate command to retrieve a vector of all possible antimicrobials that the selector can select
* The selectors `lincosamides()` and `macrolides()` do not overlap anymore - each antibiotic is now classified as either of these and not both
* `antibiotics` data set
* `antimicrobials` data set
* Added "clindamycin inducible screening" as `CLI1`. Since clindamycin is a lincosamide, the antimicrobial selector `lincosamides()` now contains the argument `only_treatable = TRUE` (similar to other antibiotic selectors that contain non-treatable drugs)
* Added Amorolfine (`AMO`, D01AE16), which is now also part of the `antifungals()` selector
* Added Efflux (`EFF`), to allow mapping to AMRFinderPlus

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.2
Name: AMR
Version: 2.1.1.9183
Version: 2.1.1.9186
Summary: A Python wrapper for the AMR R package
Home-page: https://github.com/msberends/AMR
Author: Matthijs Berends
@ -175,7 +175,7 @@ In this example, we generate an antibiogram by selecting various antibiotics.
## Taxonomic Data Sets Now in Python!
As a Python user, you might like that the most important data sets of the `AMR` R package, `microorganisms`, `antibiotics`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
As a Python user, you might like that the most important data sets of the `AMR` R package, `microorganisms`, `antimicrobials`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
```python
AMR.microorganisms
@ -196,7 +196,7 @@ AMR.microorganisms
| F_ZYZYG | Zyzygomyces | unknown | Fungi | None | 7581 | None | 2.0 |
```python
AMR.antibiotics
AMR.antimicrobials
```
| ab | cid | name | group | oral_ddd | oral_units | iv_ddd | iv_units |

View File

@ -1,6 +1,6 @@
from .datasets import example_isolates
from .datasets import microorganisms
from .datasets import antibiotics
from .datasets import antimicrobials
from .datasets import clinical_breakpoints
from .functions import ab_class
from .functions import ab_selector
@ -138,7 +138,6 @@ from .functions import semi_join_microorganisms
from .functions import anti_join_microorganisms
from .functions import key_antimicrobials
from .functions import all_antimicrobials
from .functions import antimicrobials_equal
from .functions import kurtosis
from .functions import like
from .functions import mdro

View File

@ -71,7 +71,7 @@ example_isolates['date'] = pd.to_datetime(example_isolates['date'])
# microorganisms
microorganisms = pandas2ri.rpy2py(robjects.r('AMR::microorganisms[, !sapply(AMR::microorganisms, is.list)]'))
antibiotics = pandas2ri.rpy2py(robjects.r('AMR::antibiotics[, !sapply(AMR::antibiotics, is.list)]'))
antimicrobials = pandas2ri.rpy2py(robjects.r('AMR::antimicrobials[, !sapply(AMR::antimicrobials, is.list)]'))
clinical_breakpoints = pandas2ri.rpy2py(robjects.r('AMR::clinical_breakpoints[, !sapply(AMR::clinical_breakpoints, is.list)]'))
base.options(warn = 0)

View File

@ -444,9 +444,6 @@ def key_antimicrobials(x = None, *args, **kwargs):
def all_antimicrobials(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.all_antimicrobials(x = None, *args, **kwargs))
def antimicrobials_equal(y, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.antimicrobials_equal(y, *args, **kwargs))
def kurtosis(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.kurtosis(x, *args, **kwargs))

View File

@ -147,7 +147,7 @@ In this example, we generate an antibiogram by selecting various antibiotics.
## Taxonomic Data Sets Now in Python!
As a Python user, you might like that the most important data sets of the `AMR` R package, `microorganisms`, `antibiotics`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
As a Python user, you might like that the most important data sets of the `AMR` R package, `microorganisms`, `antimicrobials`, `clinical_breakpoints`, and `example_isolates`, are now available as regular Python data frames:
```python
AMR.microorganisms
@ -168,7 +168,7 @@ AMR.microorganisms
| F_ZYZYG | Zyzygomyces | unknown | Fungi | None | 7581 | None | 2.0 |
```python
AMR.antibiotics
AMR.antimicrobials
```
| ab | cid | name | group | oral_ddd | oral_units | iv_ddd | iv_units |

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name='AMR',
version='2.1.1.9183',
version='2.1.1.9186',
packages=find_packages(),
install_requires=[
'rpy2',

View File

@ -36,11 +36,11 @@
#'
#' This work was published in the Journal of Statistical Software (Volume 104(3); \doi{10.18637/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)` 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 clinical breakpoint guidelines from CLSI and EUCAST are included, even with epidemiological cut-off (ECOFF) values. 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 public [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::antimicrobials) + nrow(AMR::antivirals))` antibiotic, antimycotic and antiviral drugs**](https://msberends.github.io/AMR/reference/antimicrobials.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 clinical breakpoint guidelines from CLSI and EUCAST are included, even with epidemiological cut-off (ECOFF) values. 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 public [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 `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:
#' 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, 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, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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
#' To cite AMR in publications use:
#'

View File

@ -134,7 +134,7 @@ globalVariables(c(
"affect_mo_name",
"angle",
"antibiotic",
"antibiotics",
"antimicrobials",
"atc_group1",
"atc_group2",
"base_ab",

View File

@ -266,7 +266,7 @@ search_type_in_df <- function(x, type, info = TRUE, add_col_prefix = TRUE) {
found <- sort(colnames(x)[colnames_formatted %like_case% "species"])
}
}
# -- key antibiotics
# -- key antimicrobials
if (type %in% c("keyantibiotics", "keyantimicrobials")) {
if (any(colnames_formatted %like_case% "^key.*(ab|antibiotics|antimicrobials)")) {
found <- sort(colnames(x)[colnames_formatted %like_case% "^key.*(ab|antibiotics|antimicrobials)"])
@ -712,7 +712,7 @@ create_eucast_ab_documentation <- function() {
ab <- character()
for (val in x) {
if (paste0("AB_", val) %in% ls(envir = asNamespace("AMR"))) {
# antibiotic group names, as defined in data-raw/_pre_commit_checks.R, such as `CARBAPENEMS`
# antimicrobial group names, as defined in data-raw/_pre_commit_checks.R, such as `CARBAPENEMS`
val <- eval(parse(text = paste0("AB_", val)), envir = asNamespace("AMR"))
} else if (val %in% AMR_env$AB_lookup$ab) {
# separate drugs, such as `AMX`

View File

@ -31,7 +31,7 @@
#'
#' This is an overview of all the package-specific [options()] you can set in the `AMR` package.
#' @section Options:
#' * `AMR_antibiogram_formatting_type` \cr A [numeric] (1-12) to use in [antibiogram()], to indicate which formatting type to use.
#' * `AMR_antibiogram_formatting_type` \cr A [numeric] (1-22) to use in [antibiogram()], to indicate which formatting type to use.
#' * `AMR_breakpoint_type` \cr A [character] to use in [as.sir()], to indicate which breakpoint type to use. This must be either `r vector_or(clinical_breakpoints$type)`.
#' * `AMR_cleaning_regex` \cr A [regular expression][base::regex] (case-insensitive) to use in [as.mo()] and all [`mo_*`][mo_property()] functions, to clean the user input. The default is the outcome of [mo_cleaning_regex()], which removes texts between brackets and texts such as "species" and "serovar".
#' * `AMR_custom_ab` \cr A file location to an RDS file, to use custom antimicrobial drugs with this package. This is explained in [add_custom_antimicrobials()].
@ -59,7 +59,7 @@
#' options(AMR_include_PKPD = TRUE)
#' ```
#'
#' ...to add Portuguese language support of antibiotics, and allow PK/PD rules when interpreting MIC values with [as.sir()].
#' ...to add Portuguese language support of antimicrobials, and allow PK/PD rules when interpreting MIC values with [as.sir()].
#'
#' ### Share Options Within Team
#'

14
R/ab.R
View File

@ -29,7 +29,7 @@
#' Transform Input to an Antibiotic ID
#'
#' Use this function to determine the antibiotic drug code of one or more antibiotics. The data set [antibiotics] will be searched for abbreviations, official names and synonyms (brand names).
#' Use this function to determine the antimicrobial drug code of one or more antimicrobials. The data set [antimicrobials] will be searched for abbreviations, official names and synonyms (brand names).
#' @param x a [character] vector to determine to antibiotic ID
#' @param flag_multiple_results a [logical] to indicate whether a note should be printed to the console that probably more than one antibiotic drug code or name can be retrieved from a single input value.
#' @param language language to coerce input values from any of the `r length(LANGUAGES_SUPPORTED)` supported languages - default to the system language if supported (see [get_AMR_locale()])
@ -37,7 +37,7 @@
#' @param ... arguments passed on to internal functions
#' @rdname as.ab
#' @inheritSection WHOCC WHOCC
#' @details All entries in the [antibiotics] data set have three different identifiers: a human readable EARS-Net code (column `ab`, used by ECDC and WHONET), an ATC code (column `atc`, used by WHO), and a CID code (column `cid`, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. Not that some drugs contain multiple ATC codes.
#' @details All entries in the [antimicrobials] data set have three different identifiers: a human readable EARS-Net code (column `ab`, used by ECDC and WHONET), an ATC code (column `atc`, used by WHO), and a CID code (column `cid`, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. Not that some drugs contain multiple ATC codes.
#'
#' All these properties will be searched for the user input. The [as.ab()] can correct for different forms of misspelling:
#'
@ -58,7 +58,7 @@
#' @aliases ab
#' @return A [character] [vector] with additional class [`ab`]
#' @seealso
#' * [antibiotics] for the [data.frame] that is being used to determine ATCs
#' * [antimicrobials] for the [data.frame] that is being used to determine ATCs
#' * [ab_from_text()] for a function to retrieve antimicrobial drugs from clinical text (from health care records)
#' @inheritSection AMR Reference Data Publicly Available
#' @export
@ -411,7 +411,7 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(),
# take failed ATC codes apart from rest
if (length(x_unknown_ATCs) > 0 && fast_mode == FALSE) {
warning_(
"in `as.ab()`: these ATC codes are not (yet) in the antibiotics data set: ",
"in `as.ab()`: these ATC codes are not (yet) in the antimicrobials data set: ",
vector_and(x_unknown_ATCs), "."
)
}
@ -629,9 +629,9 @@ get_translate_ab <- function(translate_ab) {
return(FALSE)
} else {
translate_ab <- tolower(translate_ab)
stop_ifnot(translate_ab %in% colnames(AMR::antibiotics),
"invalid value for 'translate_ab', this must be a column name of the antibiotics data set\n",
"or TRUE (equals 'name') or FALSE to not translate at all.",
stop_ifnot(translate_ab %in% colnames(AMR::antimicrobials),
"invalid value for 'translate_ab', this must be a column name of the `antimicrobials` data set\n",
"or `TRUE` (equals 'name') or `FALSE` to not translate at all.",
call = FALSE
)
translate_ab

View File

@ -33,7 +33,7 @@
#' @param text text to analyse
#' @param type type of property to search for, either `"drug"`, `"dose"` or `"administration"`, see *Examples*
#' @param collapse a [character] to pass on to `paste(, collapse = ...)` to only return one [character] per element of `text`, see *Examples*
#' @param translate_ab if `type = "drug"`: a column name of the [antibiotics] data set to translate the antibiotic abbreviations to, using [ab_property()]. The default is `FALSE`. Using `TRUE` is equal to using "name".
#' @param translate_ab if `type = "drug"`: a column name of the [antimicrobials] data set to translate the antibiotic abbreviations to, using [ab_property()]. The default is `FALSE`. Using `TRUE` is equal to using "name".
#' @param thorough_search a [logical] to indicate whether the input must be extensively searched for misspelling and other faulty input values. Setting this to `TRUE` will take considerably more time than when using `FALSE`. At default, it will turn `TRUE` when all input elements contain a maximum of three words.
#' @param info a [logical] to indicate whether a progress bar should be printed - the default is `TRUE` only in interactive mode
#' @param ... arguments passed on to [as.ab()]
@ -139,10 +139,10 @@ ab_from_text <- function(text,
})
} else {
# no thorough search
abbr <- unlist(AMR::antibiotics$abbreviations)
abbr <- unlist(AMR::antimicrobials$abbreviations)
abbr <- abbr[nchar(abbr) >= 4]
names_atc <- substr(c(AMR::antibiotics$name, AMR::antibiotics$atc), 1, 5)
synonyms <- unlist(AMR::antibiotics$synonyms)
names_atc <- substr(c(AMR::antimicrobials$name, AMR::antimicrobials$atc), 1, 5)
synonyms <- unlist(AMR::antimicrobials$synonyms)
synonyms <- synonyms[nchar(synonyms) >= 4]
# regular expression must not be too long, so split synonyms in two:
synonyms_part1 <- synonyms[seq_len(0.5 * length(synonyms))]

View File

@ -29,10 +29,10 @@
#' Get Properties of an Antibiotic
#'
#' Use these functions to return a specific property of an antibiotic from the [antibiotics] data set. All input values will be evaluated internally with [as.ab()].
#' Use these functions to return a specific property of an antibiotic from the [antimicrobials] data set. All input values will be evaluated internally with [as.ab()].
#' @param x any (vector of) text that can be coerced to a valid antibiotic drug code with [as.ab()]
#' @param tolower a [logical] to indicate whether the first [character] of every output should be transformed to a lower case [character]. This will lead to e.g. "polymyxin B" and not "polymyxin b".
#' @param property one of the column names of one of the [antibiotics] data set: `vector_or(colnames(antibiotics), sort = FALSE)`.
#' @param property one of the column names of one of the [antimicrobials] data set: `vector_or(colnames(antimicrobials), sort = FALSE)`.
#' @param language language of the returned text - the default is the current system language (see [get_AMR_locale()]) and can also be set with the package option [`AMR_locale`][AMR-options]. Use `language = NULL` or `language = ""` to prevent translation.
#' @param administration way of administration, either `"oral"` or `"iv"`
#' @param open browse the URL using [utils::browseURL()]
@ -55,7 +55,7 @@
#' - A [data.frame] in case of [set_ab_names()]
#' - A [character] in all other cases
#' @export
#' @seealso [antibiotics]
#' @seealso [antimicrobials]
#' @inheritSection AMR Reference Data Publicly Available
#' @examples
#' # all properties:
@ -337,7 +337,7 @@ ab_url <- function(x, open = FALSE, ...) {
#' @export
ab_property <- function(x, property = "name", language = get_AMR_locale(), ...) {
meet_criteria(x, allow_NA = TRUE)
meet_criteria(property, is_in = colnames(AMR::antibiotics), has_length = 1)
meet_criteria(property, is_in = colnames(AMR::antimicrobials), has_length = 1)
language <- validate_language(language)
translate_into_language(ab_validate(x = x, property = property, ...), language = language)
}
@ -347,7 +347,7 @@ ab_property <- function(x, property = "name", language = get_AMR_locale(), ...)
#' @export
set_ab_names <- function(data, ..., property = "name", language = get_AMR_locale(), snake_case = NULL) {
meet_criteria(data, allow_class = c("data.frame", "character"))
meet_criteria(property, is_in = colnames(AMR::antibiotics), has_length = 1, ignore.case = TRUE)
meet_criteria(property, is_in = colnames(AMR::antimicrobials), has_length = 1, ignore.case = TRUE)
language <- validate_language(language)
meet_criteria(snake_case, allow_class = "logical", has_length = 1, allow_NULL = TRUE)

View File

@ -38,8 +38,8 @@
#' my_data_with_all_these_columns %>%
#' select(cephalosporins())
#' ```
#' @param amr_class an antimicrobial class or a part of it, such as `"carba"` and `"carbapenems"`. The columns `group`, `atc_group1` and `atc_group2` of the [antibiotics] data set will be searched (case-insensitive) for this value.
#' @param filter an [expression] to be evaluated in the [antibiotics] data set, such as `name %like% "trim"`
#' @param amr_class an antimicrobial class or a part of it, such as `"carba"` and `"carbapenems"`. The columns `group`, `atc_group1` and `atc_group2` of the [antimicrobials] data set will be searched (case-insensitive) for this value.
#' @param filter an [expression] to be evaluated in the [antimicrobials] data set, such as `name %like% "trim"`
#' @param only_sir_columns a [logical] to indicate whether only columns of class `sir` must be selected (default is `FALSE`), see [as.sir()]
#' @param only_treatable a [logical] to indicate whether antimicrobial drugs should be excluded that are only for laboratory tests (default is `TRUE`), such as gentamicin-high (`GEH`) and imipenem/EDTA (`IPE`)
#' @param return_all a [logical] to indicate whether all matched columns must be returned (default is `TRUE`). With `FALSE`, only the first of each unique antimicrobial will be returned, e.g. if both columns `"genta"` and `"gentamicin"` exist in the data, only the first hit for gentamicin will be returned.
@ -49,9 +49,9 @@
#'
#' All selectors can also be used in `tidymodels` packages such as `recipe` and `parsnip`. See for more info [our tutorial](https://msberends.github.io/AMR/articles/AMR_with_tidymodels.html) on using antimicrobial selectors for predictive modelling.
#'
#' All columns in the data in which these functions are called will be searched for known antimicrobial names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the [antibiotics] data set. This means that a selector such as [aminoglycosides()] will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
#' All columns in the data in which these functions are called will be searched for known antimicrobial names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the [antimicrobials] data set. This means that a selector such as [aminoglycosides()] will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
#'
#' The [amr_class()] function can be used to filter/select on a manually defined antimicrobial class. It searches for results in the [antibiotics] data set within the columns `group`, `atc_group1` and `atc_group2`.
#' The [amr_class()] function can be used to filter/select on a manually defined antimicrobial class. It searches for results in the [antimicrobials] data set within the columns `group`, `atc_group1` and `atc_group2`.
#' @section Full list of supported (antimicrobial) classes:
#'
#' `r paste0(" * ", na.omit(sapply(DEFINED_AB_GROUPS, function(ab) ifelse(tolower(gsub("^AB_", "", ab)) %in% ls(envir = asNamespace("AMR")), paste0("[", tolower(gsub("^AB_", "", ab)), "()] can select: \\cr ", vector_and(paste0(ab_name(eval(parse(text = ab), envir = asNamespace("AMR")), language = NULL, tolower = TRUE), " (", eval(parse(text = ab), envir = asNamespace("AMR")), ")"), quotes = FALSE, sort = TRUE)), character(0)), USE.NAMES = FALSE)), "\n", collapse = "")`
@ -193,7 +193,7 @@
#' # and erythromycin is not a penicillin:
#' example_isolates[, penicillins() & administrable_per_os()]
#'
#' # amr_selector() applies a filter in the `antibiotics` data set and is thus
#' # amr_selector() applies a filter in the `antimicrobials` data set and is thus
#' # very flexible. For instance, to select antimicrobials with an oral DDD
#' # of at least 1 gram:
#' example_isolates[, amr_selector(oral_ddd > 1 & oral_units == "g")]
@ -483,7 +483,7 @@ ureidopenicillins <- function(only_sir_columns = FALSE, return_all = TRUE, ...)
}
#' @rdname antimicrobial_selectors
#' @details The [administrable_per_os()] and [administrable_iv()] functions also rely on the [antibiotics] data set - antimicrobials will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the [antibiotics] data set.
#' @details The [administrable_per_os()] and [administrable_iv()] functions also rely on the [antimicrobials] data set - antimicrobials will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the [antimicrobials] data set.
#' @export
amr_class <- function(amr_class,
only_sir_columns = FALSE,
@ -498,7 +498,7 @@ amr_class <- function(amr_class,
}
#' @rdname antimicrobial_selectors
#' @details The [amr_selector()] function can be used to internally filter the [antibiotics] data set on any results, see *Examples*. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
#' @details The [amr_selector()] function can be used to internally filter the [antimicrobials] data set on any results, see *Examples*. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
#' @export
amr_selector <- function(filter,
only_sir_columns = FALSE,
@ -799,9 +799,9 @@ all_any_amr_selector <- function(type, ..., na.rm = TRUE) {
df <- get_current_data(arg_name = NA, call = -3)
if (type == "all") {
scope_fn <- all
scope_fn <- base::all
} else {
scope_fn <- any
scope_fn <- base::any
}
x_transposed <- as.list(as.data.frame(t(df[, cols_ab, drop = FALSE]), stringsAsFactors = FALSE))
@ -932,12 +932,14 @@ any.amr_selector_any_all <- function(..., na.rm = FALSE) {
is_any <- function(el1) {
syscalls <- paste0(trimws2(deparse(sys.calls())), collapse = " ")
el1 <- gsub("(.*),.*", "\\1", el1)
el1 <- gsub("(", "\\(", el1, fixed = TRUE)
el1 <- gsub(")", "\\)", el1, fixed = TRUE)
syscalls %like% paste0("[^_a-zA-Z0-9]any\\(", "(c\\()?", el1)
}
is_all <- function(el1) {
syscalls <- paste0(trimws2(deparse(sys.calls())), collapse = " ")
el1 <- gsub("(.*),.*", "\\1", el1)
el1 <- gsub("(", "\\(", el1, fixed = TRUE)
el1 <- gsub(")", "\\)", el1, fixed = TRUE)
syscalls %like% paste0("[^_a-zA-Z0-9]all\\(", "(c\\()?", el1)
}

View File

@ -36,7 +36,7 @@
#' @param x a [data.frame] containing at least a column with microorganisms and columns with antimicrobial results (class 'sir', see [as.sir()])
#' @param antibiotics vector of any antimicrobial name or code (will be evaluated with [as.ab()], column name of `x`, or (any combinations of) [antimicrobial selectors][antimicrobial_selectors] such as [aminoglycosides()] or [carbapenems()]. For combination antibiograms, this can also be set to values separated with `"+"`, such as `"TZP+TOB"` or `"cipro + genta"`, given that columns resembling such antimicrobials exist in `x`. See *Examples*.
#' @param mo_transform a character to transform microorganism input - must be `"name"`, `"shortname"` (default), `"gramstain"`, or one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input or `NA` to consider all microorganisms 'unknown'.
#' @param ab_transform a character to transform antimicrobial input - must be one of the column names of the [antibiotics] data set (defaults to `"name"`): `r vector_or(colnames(antibiotics), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input.
#' @param ab_transform a character to transform antimicrobial input - must be one of the column names of the [antimicrobials] data set (defaults to `"name"`): `r vector_or(colnames(antimicrobials), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input.
#' @param syndromic_group a column name of `x`, or values calculated to split rows of `x`, e.g. by using [ifelse()] or [`case_when()`][dplyr::case_when()]. See *Examples*.
#' @param add_total_n a [logical] to indicate whether `n_tested` available numbers per pathogen should be added to the table (default is `TRUE`). This will add the lowest and highest number of available isolates per antimicrobial (e.g, if for *E. coli* 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200"). This option is unavailable when `wisca = TRUE`; in that case, use [retrieve_wisca_parameters()] to get the parameters used for WISCA.
#' @param only_all_tested (for combination antibiograms): a [logical] to indicate that isolates must be tested for all antimicrobials, see *Details*
@ -64,7 +64,7 @@
#'
#' ### Formatting Type
#'
#' The formatting of the 'cells' of the table can be set with the argument `formatting_type`. In these examples, `5` is the antimicrobial coverage (`4-6` indicates the confidence level), `15` the number of susceptible isolates, and `300` the number of tested (i.e., available) isolates:
#' The formatting of the 'cells' of the table can be set with the argument `formatting_type`. In these examples, `5` indicates the antimicrobial coverage (`4-6` the confidence level), `15` the number of susceptible isolates, and `300` the number of tested (i.e., available) isolates:
#'
#' 1. 5
#' 2. 15
@ -79,17 +79,17 @@
#' 11. 5 (N=15/300)
#' 12. 5% (N=15/300)
#' 13. 5 (4-6)
#' 14. 5% (4-6%) - **default**
#' 14. 5% (4-6%) - **default for WISCA**
#' 15. 5 (4-6,300)
#' 16. 5% (4-6%,300)
#' 17. 5 (4-6,N=300)
#' 18. 5% (4-6%,N=300)
#' 18. 5% (4-6%,N=300) - **default for non-WISCA**
#' 19. 5 (4-6,15/300)
#' 20. 5% (4-6%,15/300)
#' 21. 5 (4-6,N=15/300)
#' 22. 5% (4-6%,N=15/300)
#'
#' The default is `14`, which can be set globally with the package option [`AMR_antibiogram_formatting_type`][AMR-options], e.g. `options(AMR_antibiogram_formatting_type = 5)`. Do note that for WISCA, the total numbers of tested and susceptible isolates are less useful to report, since these are included in the Bayesian model and apparent from the susceptibility and its confidence level.
#' The default can be set globally with the package option [`AMR_antibiogram_formatting_type`][AMR-options], e.g. `options(AMR_antibiogram_formatting_type = 5)`. Do note that for WISCA, the total numbers of tested and susceptible isolates are less useful to report, since these are included in the Bayesian model and apparent from the susceptibility and its confidence level.
#'
#' Set `digits` (defaults to `0`) to alter the rounding of the susceptibility percentages.
#'
@ -412,7 +412,7 @@ antibiogram <- function(x,
add_total_n = FALSE,
only_all_tested = FALSE,
digits = ifelse(wisca, 1, 0),
formatting_type = getOption("AMR_antibiogram_formatting_type", 14),
formatting_type = getOption("AMR_antibiogram_formatting_type", ifelse(wisca, 14, 18)),
col_mo = NULL,
language = get_AMR_locale(),
minimum = 30,
@ -436,7 +436,7 @@ antibiogram.default <- function(x,
add_total_n = FALSE,
only_all_tested = FALSE,
digits = ifelse(wisca, 1, 0),
formatting_type = getOption("AMR_antibiogram_formatting_type", 14),
formatting_type = getOption("AMR_antibiogram_formatting_type", ifelse(wisca, 14, 18)),
col_mo = NULL,
language = get_AMR_locale(),
minimum = 30,
@ -460,7 +460,7 @@ antibiogram.default <- function(x,
meet_criteria(mo_transform, allow_class = "character", has_length = 1, is_in = c("name", "shortname", "gramstain", colnames(AMR::microorganisms)), allow_NULL = TRUE, allow_NA = TRUE)
}
if (!is.function(ab_transform)) {
meet_criteria(ab_transform, allow_class = "character", has_length = 1, is_in = colnames(AMR::antibiotics), allow_NULL = TRUE)
meet_criteria(ab_transform, allow_class = "character", has_length = 1, is_in = colnames(AMR::antimicrobials), allow_NULL = TRUE)
}
meet_criteria(syndromic_group, allow_class = "character", allow_NULL = TRUE, allow_NA = TRUE)
meet_criteria(add_total_n, allow_class = "logical", has_length = 1)
@ -962,7 +962,7 @@ antibiogram.grouped_df <- function(x,
add_total_n = FALSE,
only_all_tested = FALSE,
digits = ifelse(wisca, 1, 0),
formatting_type = getOption("AMR_antibiogram_formatting_type", 14),
formatting_type = getOption("AMR_antibiogram_formatting_type", ifelse(wisca, 14, 18)),
col_mo = NULL,
language = get_AMR_locale(),
minimum = 30,

View File

@ -29,8 +29,8 @@
#' Get ATC Properties from WHOCC Website
#'
#' Gets data from the WHOCC website to determine properties of an Anatomical Therapeutic Chemical (ATC) (e.g. an antibiotic), such as the name, defined daily dose (DDD) or standard unit.
#' @param atc_code a [character] (vector) with ATC code(s) of antibiotics, will be coerced with [as.ab()] and [ab_atc()] internally if not a valid ATC code
#' Gets data from the WHOCC website to determine properties of an Anatomical Therapeutic Chemical (ATC) (e.g. an antimicrobial), such as the name, defined daily dose (DDD) or standard unit.
#' @param atc_code a [character] (vector) with ATC code(s) of antimicrobials, will be coerced with [as.ab()] and [ab_atc()] internally if not a valid ATC code
#' @param property property of an ATC code. Valid values are `"ATC"`, `"Name"`, `"DDD"`, `"U"` (`"unit"`), `"Adm.R"`, `"Note"` and `groups`. For this last option, all hierarchical groups of an ATC code will be returned, see *Examples*.
#' @param administration type of administration when using `property = "Adm.R"`, see *Details*
#' @param url url of website of the WHOCC. The sign `%s` can be used as a placeholder for ATC codes.
@ -98,7 +98,7 @@ atc_online_property <- function(atc_code,
html_text <- import_fn("html_text", "rvest")
read_html <- import_fn("read_html", "xml2")
if (!all(atc_code %in% unlist(AMR::antibiotics$atc))) {
if (!all(atc_code %in% unlist(AMR::antimicrobials$atc))) {
atc_code <- as.character(ab_atc(atc_code, only_first = TRUE))
}

View File

@ -35,7 +35,7 @@
#' @param add_ab_group a [logical] to indicate where the group of the antimicrobials must be included as a first column
#' @param remove_intrinsic_resistant [logical] to indicate that rows and columns with 100% resistance for all tested antimicrobials must be removed from the table
#' @param FUN the function to call on the `mo` column to transform the microorganism codes - the default is [mo_shortname()]
#' @param translate_ab a [character] of length 1 containing column names of the [antibiotics] data set
#' @param translate_ab a [character] of length 1 containing column names of the [antimicrobials] data set
#' @param include_n_rows a [logical] to indicate if the total number of rows must be included in the output
#' @param ... arguments passed on to `FUN`
#' @inheritParams sir_df
@ -93,7 +93,7 @@ bug_drug_combinations <- function(x,
unique_mo <- sort(unique(x[, col_mo, drop = TRUE]))
# select only groups and antibiotics
# select only groups and antimicrobials
if (is_null_or_grouped_tbl(x.bak)) {
data_has_groups <- TRUE
groups <- get_group_names(x.bak)

View File

@ -39,7 +39,7 @@
#'
#' The function [count_resistant()] is equal to the function [count_R()]. The function [count_susceptible()] is equal to the function [count_SI()].
#'
#' The function [n_sir()] 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_sir()] is an alias of [count_all()]. They can be used to count all available isolates, i.e. where all input antimicrobials 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 [`sir`] class (created with [as.sir()]) and counts the number of S's, I's and R's. It also supports grouped variables. The function [sir_df()] works exactly like [count_df()], but adds the percentage of S, I and R.
#' @inheritSection proportion Combination Therapy

View File

@ -30,14 +30,14 @@
#' Add Custom Antimicrobials
#'
#' With [add_custom_antimicrobials()] you can add your own custom antimicrobial drug names and codes.
#' @param x a [data.frame] resembling the [antibiotics] data set, at least containing columns "ab" and "name"
#' @param x a [data.frame] resembling the [antimicrobials] 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.
#'
#' There are two ways to circumvent this and automate the process of adding antimicrobials:
#'
#' **Method 1:** Using the package option [`AMR_custom_ab`][AMR-options], which is the preferred method. To use this method:
#'
#' 1. Create a data set in the structure of the [antibiotics] data set (containing at the very least columns "ab" and "name") and save it with [saveRDS()] to a location of choice, e.g. `"~/my_custom_ab.rds"`, or any remote location.
#' 1. Create a data set in the structure of the [antimicrobials] data set (containing at the very least columns "ab" and "name") and save it with [saveRDS()] to a location of choice, e.g. `"~/my_custom_ab.rds"`, or any remote location.
#'
#' 2. Set the file location to the package option [`AMR_custom_ab`][AMR-options]: `options(AMR_custom_ab = "~/my_custom_ab.rds")`. This can even be a remote file location, such as an https URL. Since options are not saved between \R sessions, it is best to save this option to the `.Rprofile` file so that it will be loaded on start-up of \R. To do this, open the `.Rprofile` file using e.g. `utils::file.edit("~/.Rprofile")`, add this text and save the file:
#'
@ -79,7 +79,7 @@
#' ab = "TESTAB",
#' name = "Test Antibiotic",
#' # you can add any property present in the
#' # 'antibiotics' data set, such as 'group':
#' # 'antimicrobials' data set, such as 'group':
#' group = "Test Group"
#' )
#' )
@ -123,11 +123,11 @@ add_custom_antimicrobials <- function(x) {
)
stop_if(
any(x$ab %in% AMR_env$AB_lookup$ab),
"Antimicrobial drug code(s) ", vector_and(x$ab[x$ab %in% AMR_env$AB_lookup$ab]), " already exist in the internal `antibiotics` data set."
"Antimicrobial drug code(s) ", vector_and(x$ab[x$ab %in% AMR_env$AB_lookup$ab]), " already exist in the internal `antimicrobials` data set."
)
# remove any extra class/type, such as grouped tbl, or data.table:
x <- as.data.frame(x, stringsAsFactors = FALSE)
# keep only columns available in the antibiotics data set
# keep only columns available in the antimicrobials data set
x <- x[, colnames(AMR_env$AB_lookup)[colnames(AMR_env$AB_lookup) %in% colnames(x)], drop = FALSE]
x$generalised_name <- generalise_antibiotic_name(x$name)
x$generalised_all <- as.list(x$generalised_name)
@ -155,16 +155,16 @@ add_custom_antimicrobials <- function(x) {
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(!AMR_env$ab_previously_coerced$ab %in% c(x$ab, x$generalised_name) & !AMR_env$ab_previously_coerced$x %in% c(x$ab, x$generalised_name)), , drop = FALSE]
class(AMR_env$AB_lookup$ab) <- c("ab", "character")
message_("Added ", nr2char(nrow(x)), " record", ifelse(nrow(x) > 1, "s", ""), " to the internal `antibiotics` data set.")
message_("Added ", nr2char(nrow(x)), " record", ifelse(nrow(x) > 1, "s", ""), " to the internal `antimicrobials` data set.")
}
#' @rdname add_custom_antimicrobials
#' @export
clear_custom_antimicrobials <- function() {
n <- nrow(AMR_env$AB_lookup)
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
AMR_env$AB_lookup <- cbind(AMR::antimicrobials, AB_LOOKUP)
n2 <- nrow(AMR_env$AB_lookup)
AMR_env$custom_ab_codes <- character(0)
AMR_env$ab_previously_coerced <- AMR_env$ab_previously_coerced[which(AMR_env$ab_previously_coerced$ab %in% AMR_env$AB_lookup$ab), , drop = FALSE]
message_("Cleared ", nr2char(n - n2), " custom record", ifelse(n - n2 > 1, "s", ""), " from the internal `antibiotics` data set.")
message_("Cleared ", nr2char(n - n2), " custom record", ifelse(n - n2 > 1, "s", ""), " from the internal `antimicrobials` data set.")
}

View File

@ -89,11 +89,11 @@
#' #> 2 Klebsiella pneumoniae R R S
#' ```
#'
#' ### Usage of multiple antibiotics and antibiotic group names
#' ### Usage of multiple antimicrobials and antimicrobial group names
#'
#' You can define antibiotic groups instead of single antibiotics for the rule consequence, which is the part *after* the tilde (~). In the examples above, the antibiotic group `aminopenicillins` includes both ampicillin and amoxicillin.
#' You can define antimicrobial groups instead of single antimicrobials for the rule consequence, which is the part *after* the tilde (~). In the examples above, the antimicrobial group `aminopenicillins` includes both ampicillin and amoxicillin.
#'
#' Rules can also be applied to multiple antibiotics and antibiotic groups simultaneously. Use the `c()` function to combine multiple antibiotics. For instance, the following example sets all aminopenicillins and ureidopenicillins to "R" if column TZP (piperacillin/tazobactam) is "R":
#' Rules can also be applied to multiple antimicrobials and antimicrobial groups simultaneously. Use the `c()` function to combine multiple antimicrobials. For instance, the following example sets all aminopenicillins and ureidopenicillins to "R" if column TZP (piperacillin/tazobactam) is "R":
#'
#' ```r
#' x <- custom_eucast_rules(TZP == "R" ~ c(aminopenicillins, ureidopenicillins) == "R")
@ -104,7 +104,7 @@
#' #> amoxicillin (AMX), ampicillin (AMP), azlocillin (AZL), mezlocillin (MEZ), piperacillin (PIP), piperacillin/tazobactam (TZP)
#' ```
#'
#' These `r length(DEFINED_AB_GROUPS)` antibiotic groups are allowed in the rules (case-insensitive) and can be used in any combination:
#' These `r length(DEFINED_AB_GROUPS)` antimicrobial groups are allowed in the rules (case-insensitive) and can be used in any combination:
#'
#' `r paste0(" * ", sapply(DEFINED_AB_GROUPS, function(x) paste0(tolower(gsub("^AB_", "", x)), "\\cr(", vector_and(ab_name(eval(parse(text = x), envir = asNamespace("AMR")), language = NULL, tolower = TRUE), quotes = FALSE), ")"), USE.NAMES = FALSE), "\n", collapse = "")`
#' @returns A [list] containing the custom rules

View File

@ -27,23 +27,23 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
#' Data Sets with `r format(nrow(antibiotics) + nrow(antivirals), big.mark = " ")` Antimicrobial Drugs
#' Data Sets with `r format(nrow(antimicrobials) + nrow(antivirals), big.mark = " ")` Antimicrobial Drugs
#'
#' Two data sets containing all antibiotics/antimycotics and antivirals. Use [as.ab()] or one of the [`ab_*`][ab_property()] functions to retrieve values from the [antibiotics] data set. Three identifiers are included in this data set: an antibiotic ID (`ab`, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (`atc`) as defined by the WHO, and a Compound ID (`cid`) as found in PubChem. Other properties in this data set are derived from one or more of these codes. Note that some drugs have multiple ATC codes.
#' Two data sets containing all antimicrobials and antivirals. Use [as.ab()] or one of the [`ab_*`][ab_property()] functions to retrieve values from the [antimicrobials] data set. Three identifiers are included in this data set: an antimcrobial ID (`ab`, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (`atc`) as defined by the WHO, and a Compound ID (`cid`) as found in PubChem. Other properties in this data set are derived from one or more of these codes. Note that some drugs have multiple ATC codes.
#' @format
#' ### For the [antibiotics] data set: a [tibble][tibble::tibble] with `r nrow(antibiotics)` observations and `r ncol(antibiotics)` variables:
#' - `ab`\cr Antibiotic ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available. ***This is a unique identifier.***
#' ### For the [antimicrobials] data set: a [tibble][tibble::tibble] with `r nrow(antimicrobials)` observations and `r ncol(antimicrobials)` variables:
#' - `ab`\cr antimcrobial ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available. ***This is a unique identifier.***
#' - `cid`\cr Compound ID as found in PubChem. ***This is a unique identifier.***
#' - `name`\cr Official name as used by WHONET/EARS-Net or the WHO. ***This is a unique identifier.***
#' - `group`\cr A short and concise group name, based on WHONET and WHOCC definitions
#' - `atc`\cr ATC codes (Anatomical Therapeutic Chemical) as defined by the WHOCC, like `J01CR02`
#' - `atc_group1`\cr Official pharmacological subgroup (3rd level ATC code) as defined by the WHOCC, like `"Macrolides, lincosamides and streptogramins"`
#' - `atc_group2`\cr Official chemical subgroup (4th level ATC code) as defined by the WHOCC, like `"Macrolides"`
#' - `abbr`\cr List of abbreviations as used in many countries, also for antibiotic susceptibility testing (AST)
#' - `abbr`\cr List of abbreviations as used in many countries, also for antimcrobial susceptibility testing (AST)
#' - `synonyms`\cr Synonyms (often trade names) of a drug, as found in PubChem based on their compound ID
#' - `oral_ddd`\cr Defined Daily Dose (DDD), oral treatment, currently available for `r sum(!is.na(antibiotics$oral_ddd))` drugs
#' - `oral_ddd`\cr Defined Daily Dose (DDD), oral treatment, currently available for `r sum(!is.na(AMR::antimicrobials$oral_ddd))` drugs
#' - `oral_units`\cr Units of `oral_ddd`
#' - `iv_ddd`\cr Defined Daily Dose (DDD), parenteral (intravenous) treatment, currently available for `r sum(!is.na(antibiotics$iv_ddd))` drugs
#' - `iv_ddd`\cr Defined Daily Dose (DDD), parenteral (intravenous) treatment, currently available for `r sum(!is.na(AMR::antimicrobials$iv_ddd))` drugs
#' - `iv_units`\cr Units of `iv_ddd`
#' - `loinc`\cr All codes associated with the name of the antimicrobial drug from `r TAXONOMY_VERSION$LOINC$citation` Use [ab_loinc()] to retrieve them quickly, see [ab_property()].
#'
@ -74,12 +74,13 @@
#' * European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: <https://ec.europa.eu/health/documents/community-register/html/reg_hum_atc.htm>
#' @inheritSection WHOCC WHOCC
#' @seealso [microorganisms], [intrinsic_resistant]
#' @aliases antibiotics
#' @examples
#' antibiotics
#' antimicrobials
#' antivirals
"antibiotics"
"antimicrobials"
#' @rdname antibiotics
#' @rdname antimicrobials
"antivirals"
#' Data Set with `r format(nrow(microorganisms), big.mark = " ")` Taxonomic Records of Microorganisms
@ -214,7 +215,7 @@
#' - `gender`\cr Gender of the patient, either `r vector_or(example_isolates$gender)`
#' - `ward`\cr Ward type where the patient was admitted, either `r vector_or(example_isolates$ward)`
#' - `mo`\cr ID of microorganism created with [as.mo()], see also the [microorganisms] data set
#' - `PEN:RIF`\cr `r sum(vapply(FUN.VALUE = logical(1), example_isolates, is.sir))` different antibiotics with class [`sir`] (see [as.sir()]); these column names occur in the [antibiotics] data set and can be translated with [set_ab_names()] or [ab_name()]
#' - `PEN:RIF`\cr `r sum(vapply(FUN.VALUE = logical(1), example_isolates, is.sir))` different antimicrobials with class [`sir`] (see [as.sir()]); these column names occur in the [antimicrobials] data set and can be translated with [set_ab_names()] or [ab_name()]
#' @details
#' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, and Stata. 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).
#' @examples
@ -229,7 +230,7 @@
#' - `date`\cr date of receipt at the laboratory
#' - `hospital`\cr ID of the hospital, from A to C
#' - `bacteria`\cr info about microorganism that can be transformed with [as.mo()], see also [microorganisms]
#' - `AMX:GEN`\cr 4 different antibiotics that have to be transformed with [as.sir()]
#' - `AMX:GEN`\cr 4 different antimicrobials that have to be transformed with [as.sir()]
#' @details
#' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, and Stata. 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).
#' @examples
@ -238,7 +239,7 @@
#' Data Set with `r format(nrow(WHONET), big.mark = " ")` Isolates - WHONET Example
#'
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our [example_isolates] data set. All patient names were created using online surname generators and are only in place for practice purposes.
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antimcrobial results are from our [example_isolates] data set. All patient names were created using online surname generators and are only in place for practice purposes.
#' @format A [tibble][tibble::tibble] with `r format(nrow(WHONET), big.mark = " ")` observations and `r ncol(WHONET)` variables:
#' - `Identification number`\cr ID of the sample
#' - `Specimen number`\cr ID of the specimen
@ -265,7 +266,7 @@
#' - `Inducible clindamycin resistance`\cr Clindamycin can be induced?
#' - `Comment`\cr Other comments
#' - `Date of data entry`\cr [Date] this data was entered in WHONET
#' - `AMP_ND10:CIP_EE`\cr `r sum(vapply(FUN.VALUE = logical(1), WHONET, is.sir))` different antibiotics. You can lookup the abbreviations in the [antibiotics] data set, or use e.g. [`ab_name("AMP")`][ab_name()] to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using [as.sir()].
#' - `AMP_ND10:CIP_EE`\cr `r sum(vapply(FUN.VALUE = logical(1), WHONET, is.sir))` different antimicrobials. You can lookup the abbreviations in the [antimicrobials] data set, or use e.g. [`ab_name("AMP")`][ab_name()] to get the official name immediately. Before analysis, you should transform this to a valid antimcrobial class, using [as.sir()].
#' @details
#' Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, and Stata. 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).
#' @examples
@ -290,7 +291,7 @@
#' - `site`\cr Body site for which the breakpoint must be applied, e.g. "Oral" or "Respiratory"
#' - `mo`\cr Microbial ID, see [as.mo()]
#' - `rank_index`\cr Taxonomic rank index of `mo` from 1 (subspecies/infraspecies) to 5 (unknown microorganism)
#' - `ab`\cr Antibiotic code as used by this package, EARS-Net and WHONET, see [as.ab()]
#' - `ab`\cr Antimcrobial code as used by this package, EARS-Net and WHONET, see [as.ab()]
#' - `ref_tbl`\cr Info about where the guideline rule can be found
#' - `disk_dose`\cr Dose of the used disk diffusion method
#' - `breakpoint_S`\cr Lowest MIC value or highest number of millimetres that leads to "S"
@ -323,7 +324,7 @@
#' Data set containing defined intrinsic resistance by EUCAST of all bug-drug combinations.
#' @format A [tibble][tibble::tibble] with `r format(nrow(intrinsic_resistant), big.mark = " ")` observations and `r ncol(intrinsic_resistant)` variables:
#' - `mo`\cr Microorganism ID
#' - `ab`\cr Antibiotic ID
#' - `ab`\cr Antimcrobial ID
#' @details
#' This data set is based on `r format_eucast_version_nr(3.3)`.
#'
@ -339,7 +340,7 @@
#'
#' EUCAST breakpoints used in this package are based on the dosages in this data set. They can be retrieved with [eucast_dosage()].
#' @format A [tibble][tibble::tibble] with `r format(nrow(dosage), big.mark = " ")` observations and `r ncol(dosage)` variables:
#' - `ab`\cr Antibiotic ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available
#' - `ab`\cr Antimcrobial ID as used in this package (such as `AMC`), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available
#' - `name`\cr Official name of the antimicrobial drug as used by WHONET/EARS-Net or the WHO
#' - `type`\cr Type of the dosage, either `r vector_or(dosage$type)`
#' - `dose`\cr Dose, such as "2 g" or "25 mg/kg"

View File

@ -59,7 +59,7 @@ format_eucast_version_nr <- function(version, markdown = TRUE) {
#' Apply rules from clinical breakpoints notes and expected resistant phenotypes as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, <https://www.eucast.org>), see *Source*. Use [eucast_dosage()] to get a [data.frame] with advised dosages of a certain bug-drug combination, which is based on the [dosage] data set.
#'
#' To improve the interpretation of the antibiogram before EUCAST rules are applied, some non-EUCAST rules can applied at default, see *Details*.
#' @param x a data set with antibiotic columns, such as `amox`, `AMX` and `AMC`
#' @param x a data set with antimicrobials columns, such as `amox`, `AMX` and `AMC`
#' @param info a [logical] to indicate whether progress should be printed to the console - the default is only print while in interactive sessions
#' @param rules a [character] vector that specifies which rules should be applied. Must be one or more of `"breakpoints"`, `"expert"`, `"other"`, `"custom"`, `"all"`, and defaults to `c("breakpoints", "expert")`. The default value can be set to another value using the package option [`AMR_eucastrules`][AMR-options]: `options(AMR_eucastrules = "all")`. If using `"custom"`, be sure to fill in argument `custom_rules` too. Custom rules can be created with [custom_eucast_rules()].
#' @param verbose a [logical] to turn Verbose mode on and off (default is off). In Verbose mode, the function does not apply rules to the data, but instead returns a data set in logbook form with extensive info about which rows and columns would be effected and in which way. Using Verbose mode takes a lot more time.
@ -67,10 +67,10 @@ format_eucast_version_nr <- function(version, markdown = TRUE) {
#' @param version_expertrules the version number to use for the EUCAST Expert Rules and Intrinsic Resistance guideline. Can be `r vector_or(names(EUCAST_VERSION_EXPERT_RULES), reverse = TRUE)`.
# @param version_resistant_phenotypes the version number to use for the EUCAST Expected Resistant Phenotypes. Can be `r vector_or(names(EUCAST_VERSION_RESISTANTPHENOTYPES), reverse = TRUE)`.
#' @param ampc_cephalosporin_resistance a [character] value that should be applied to cefotaxime, ceftriaxone and ceftazidime for AmpC de-repressed cephalosporin-resistant mutants - the default is `NA`. Currently only works when `version_expertrules` is `3.2` and higher; these version of '*EUCAST Expert Rules on Enterobacterales*' state that results of cefotaxime, ceftriaxone and ceftazidime should be reported with a note, or results should be suppressed (emptied) for these three drugs. A value of `NA` (the default) for this argument will remove results for these three drugs, while e.g. a value of `"R"` will make the results for these drugs resistant. Use `NULL` or `FALSE` to not alter results for these three drugs of AmpC de-repressed cephalosporin-resistant mutants. Using `TRUE` is equal to using `"R"`. \cr For *EUCAST Expert Rules* v3.2, this rule applies to: `r vector_and(gsub("[^a-zA-Z ]+", "", unlist(strsplit(EUCAST_RULES_DF[which(EUCAST_RULES_DF$reference.version %in% c(3.2, 3.3) & EUCAST_RULES_DF$reference.rule %like% "ampc"), "this_value"][1], "|", fixed = TRUE))), quotes = "*")`.
#' @param ... column name of an antibiotic, see section *Antibiotics* below
#' @param ab any (vector of) text that can be coerced to a valid antibiotic drug code with [as.ab()]
#' @param ... column name of an antimicrobial, see section *Antimicrobials* below
#' @param ab any (vector of) text that can be coerced to a valid antimicrobial drug code with [as.ab()]
#' @param administration route of administration, either `r vector_or(dosage$administration)`
#' @param only_sir_columns a [logical] to indicate whether only antibiotic columns must be detected that were transformed to class `sir` (see [as.sir()]) on beforehand (default is `FALSE`)
#' @param only_sir_columns a [logical] to indicate whether only antimicrobial columns must be detected that were transformed to class `sir` (see [as.sir()]) on beforehand (default is `FALSE`)
#' @param custom_rules custom rules to apply, created with [custom_eucast_rules()]
#' @param overwrite a [logical] to indicate whether non-`NA` values must be overwritten (defaults to `TRUE`). With `FALSE`, only `NA` values are changed.
#' @inheritParams first_isolate
@ -101,16 +101,16 @@ format_eucast_version_nr <- function(version, markdown = TRUE) {
#' Important examples include amoxicillin and amoxicillin/clavulanic acid, and trimethoprim and trimethoprim/sulfamethoxazole. Needless to say, for these rules to work, both drugs must be available in the data set.
#'
#' Since these rules are not officially approved by EUCAST, they are not applied at default. To use these rules, include `"other"` to the `rules` argument, or use `eucast_rules(..., rules = "all")`. You can also set the package option [`AMR_eucastrules`][AMR-options], i.e. run `options(AMR_eucastrules = "all")`.
#' @section Antibiotics:
#' To define antibiotics column names, leave as it is to determine it automatically with [guess_ab_col()] or input a text (case-insensitive), or use `NULL` to skip a column (e.g. `TIC = NULL` to skip ticarcillin). Manually defined but non-existing columns will be skipped with a warning.
#' @section Antimicrobials:
#' To define antimicrobials column names, leave as it is to determine it automatically with [guess_ab_col()] or input a text (case-insensitive), or use `NULL` to skip a column (e.g. `TIC = NULL` to skip ticarcillin). Manually defined but non-existing columns will be skipped with a warning.
#'
#' The following antibiotics are eligible for the functions [eucast_rules()] and [mdro()]. These are shown below in the format 'name (`antimicrobial ID`, [ATC code](https://atcddd.fhi.no/atc/structure_and_principles/))', sorted alphabetically:
#' The following antimicrobials are eligible for the functions [eucast_rules()] and [mdro()]. These are shown below in the format 'name (`antimicrobial ID`, [ATC code](https://atcddd.fhi.no/atc/structure_and_principles/))', sorted alphabetically:
#'
#' `r create_eucast_ab_documentation()`
#' @aliases EUCAST
#' @rdname eucast_rules
#' @export
#' @return The input of `x`, possibly with edited values of antibiotics. Or, if `verbose = TRUE`, a [data.frame] with all original and new values of the affected bug-drug combinations.
#' @return The input of `x`, possibly with edited values of antimicrobials. Or, if `verbose = TRUE`, a [data.frame] with all original and new values of the affected bug-drug combinations.
#' @source
#' - EUCAST Expert Rules. Version 2.0, 2012.\cr
#' Leclercq et al. **EUCAST expert rules in antimicrobial susceptibility testing.** *Clin Microbiol Infect.* 2013;19(2):141-60; \doi{https://doi.org/10.1111/j.1469-0691.2011.03703.x}
@ -346,7 +346,7 @@ eucast_rules <- function(x,
strsplit(",") %pm>%
unlist() %pm>%
trimws2() %pm>%
vapply(FUN.VALUE = character(1), function(x) if (x %in% AMR::antibiotics$ab) ab_name(x, language = NULL, tolower = TRUE, fast_mode = TRUE) else x) %pm>%
vapply(FUN.VALUE = character(1), function(x) if (x %in% AMR::antimicrobials$ab) ab_name(x, language = NULL, tolower = TRUE, fast_mode = TRUE) else x) %pm>%
sort() %pm>%
paste(collapse = ", ")
x <- gsub("_", " ", x, fixed = TRUE)
@ -471,10 +471,10 @@ eucast_rules <- function(x,
))
cat("\n\n")
}
ab_enzyme <- subset(AMR::antibiotics, name %like% "/")[, c("ab", "name"), drop = FALSE]
ab_enzyme <- subset(AMR::antimicrobials, name %like% "/")[, c("ab", "name"), drop = FALSE]
colnames(ab_enzyme) <- c("enzyme_ab", "enzyme_name")
ab_enzyme$base_name <- gsub("^([a-zA-Z0-9]+).*", "\\1", ab_enzyme$enzyme_name)
ab_enzyme$base_ab <- AMR::antibiotics[match(ab_enzyme$base_name, AMR::antibiotics$name), "ab", drop = TRUE]
ab_enzyme$base_ab <- AMR::antimicrobials[match(ab_enzyme$base_name, AMR::antimicrobials$name), "ab", drop = TRUE]
ab_enzyme <- subset(ab_enzyme, !is.na(base_ab))
# make ampicillin and amoxicillin interchangable
ampi <- subset(ab_enzyme, base_ab == "AMX")
@ -825,7 +825,7 @@ eucast_rules <- function(x,
# error = function(e) integer(0))
# nolint end
} else {
stop_("only 2 antibiotics supported for source_antibiotics")
stop_("only 2 antimicrobials supported for source_antibiotics")
}
}

View File

@ -364,7 +364,7 @@ first_isolate <- function(x = NULL,
specimen_group <- NULL
}
# filter on specimen group and keyantibiotics when they are filled in
# filter on specimen group and keyantimicrobials when they are filled in
if (!is.null(specimen_group)) {
check_columns_existance(col_specimen, x)
if (isTRUE(info) && message_not_thrown_before("first_isolate", "excludingspecimen")) {

View File

@ -49,9 +49,9 @@
#' @param x.title text to show as x axis description
#' @param y.title text to show as y axis description
#' @param ... other arguments passed on to [geom_sir()] or, in case of [scale_sir_colours()], named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See *Examples*.
#' @details At default, the names of antibiotics will be shown on the plots using [ab_name()]. This can be set with the `translate_ab` argument. See [count_df()].
#' @details At default, the names of antimicrobials will be shown on the plots using [ab_name()]. This can be set with the `translate_ab` argument. See [count_df()].
#'
#' [geom_sir()] will take any variable from the data that has an [`sir`] class (created with [as.sir()]) using [sir_df()] and will plot bars with the percentage S, I, and R. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis.
#' [geom_sir()] will take any variable from the data that has an [`sir`] class (created with [as.sir()]) using [sir_df()] and will plot bars with the percentage S, I, and R. The default behaviour is to have the bars stacked and to have the different antimicrobials on the x axis.
#'
#' Additional functions include:
#'
@ -320,7 +320,7 @@ geom_sir <- function(position = NULL,
x <- substr(x, 2, nchar(x) - 1)
}
if (tolower(x) %in% tolower(c("ab", "abx", "antibiotics"))) {
if (tolower(x) %in% tolower(c("ab", "abx", "antimicrobials"))) {
x <- "antibiotic"
} else if (tolower(x) %in% tolower(c("SIR", "sir", "interpretations", "result"))) {
x <- "interpretation"

View File

@ -29,12 +29,12 @@
#' Guess Antibiotic Column
#'
#' This tries to find a column name in a data set based on information from the [antibiotics] data set. Also supports WHONET abbreviations.
#' This tries to find a column name in a data set based on information from the [antimicrobials] data set. Also supports WHONET abbreviations.
#' @param x a [data.frame]
#' @param search_string a text to search `x` for, will be checked with [as.ab()] if this value is not a column in `x`
#' @param verbose a [logical] to indicate whether additional info should be printed
#' @param only_sir_columns a [logical] to indicate whether only antibiotic columns must be detected that were transformed to class `sir` (see [as.sir()]) on beforehand (default is `FALSE`)
#' @details You can look for an antibiotic (trade) name or abbreviation and it will search `x` and the [antibiotics] data set for any column containing a name or code of that antibiotic.
#' @details You can look for an antibiotic (trade) name or abbreviation and it will search `x` and the [antimicrobials] data set for any column containing a name or code of that antibiotic.
#' @return A column name of `x`, or `NULL` when no result is found.
#' @export
#' @examples

View File

@ -30,7 +30,7 @@
#' (Key) Antimicrobials for First Weighted Isolates
#'
#' These functions can be used to determine first weighted isolates by considering the phenotype for isolate selection (see [first_isolate()]). Using a phenotype-based method to determine first isolates is more reliable than methods that disregard phenotypes.
#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank to determine automatically
#' @param x a [data.frame] with antimicrobials columns, like `AMX` or `amox`. Can be left blank to determine automatically.
#' @param y,z [character] vectors to compare
#' @inheritParams first_isolate
#' @param universal names of **broad-spectrum** antimicrobial drugs, case-insensitive. Set to `NULL` to ignore. See *Details* for the default antimicrobial drugs
@ -73,7 +73,6 @@
#' - Tetracycline
#' - Vancomycin
#'
#'
#' The default antimicrobial drugs used for **fungi** (set in `antifungal`) are:
#'
#' - Anidulafungin
@ -102,7 +101,7 @@
#'
#' \donttest{
#' if (require("dplyr")) {
#' # set key antibiotics to a new variable
#' # set key antimicrobials to a new variable
#' my_patients <- example_isolates %>%
#' mutate(keyab = key_antimicrobials(antifungal = NULL)) %>% # no need to define `x`
#' mutate(
@ -192,7 +191,7 @@ key_antimicrobials <- function(x = NULL,
)
}
generate_antimcrobials_string(x[which(filter), c(universal, values), drop = FALSE])
generate_antimicrobials_string(x[which(filter), c(universal, values), drop = FALSE])
}
if (is.null(universal)) {
@ -264,10 +263,10 @@ all_antimicrobials <- function(x = NULL,
sort = FALSE, fn = "all_antimicrobials"
)
generate_antimcrobials_string(x[, cols, drop = FALSE])
generate_antimicrobials_string(x[, cols, drop = FALSE])
}
generate_antimcrobials_string <- function(df) {
generate_antimicrobials_string <- function(df) {
if (NCOL(df) == 0) {
return(rep("", NROW(df)))
}

View File

@ -30,7 +30,7 @@
#' Determine Multidrug-Resistant Organisms (MDRO)
#'
#' Determine which isolates are multidrug-resistant organisms (MDRO) according to international, national, or custom guidelines.
#' @param x a [data.frame] with antibiotics columns, like `AMX` or `amox`. Can be left blank for automatic determination.
#' @param x a [data.frame] with antimicrobials columns, like `AMX` or `amox`. Can be left blank for automatic determination.
#' @param guideline a specific guideline to follow, see sections *Supported international / national guidelines* and *Using Custom Guidelines* below. When left empty, the publication by Magiorakos *et al.* (see below) will be followed.
#' @param esbl [logical] values, or a column name containing logical values, indicating the presence of an ESBL gene (or production of its proteins)
#' @param carbapenemase [logical] values, or a column name containing logical values, indicating the presence of a carbapenemase gene (or production of its proteins)
@ -38,13 +38,13 @@
#' @param mecC [logical] values, or a column name containing logical values, indicating the presence of a *mecC* gene (or production of its proteins)
#' @param vanA [logical] values, or a column name containing logical values, indicating the presence of a *vanA* gene (or production of its proteins)
#' @param vanB [logical] values, or a column name containing logical values, indicating the presence of a *vanB* gene (or production of its proteins)
#' @param ... in case of [custom_mdro_guideline()]: a set of rules, see section *Using Custom Guidelines* below. Otherwise: column name of an antibiotic, see section *Antibiotics* below.
#' @param ... in case of [custom_mdro_guideline()]: a set of rules, see section *Using Custom Guidelines* below. Otherwise: column name of an antibiotic, see section *Antimicrobials* below.
#' @param as_factor a [logical] to indicate whether the returned value should be an ordered [factor] (`TRUE`, default), or otherwise a [character] vector
#' @inheritParams eucast_rules
#' @param pct_required_classes minimal required percentage of antimicrobial classes that must be available per isolate, rounded down. For example, with the default guideline, 17 antimicrobial classes must be available for *S. aureus*. Setting this `pct_required_classes` argument to `0.5` (default) means that for every *S. aureus* isolate at least 8 different classes must be available. Any lower number of available classes will return `NA` for that isolate.
#' @param combine_SI a [logical] to indicate whether all values of S and I must be merged into one, so resistance is only considered when isolates are R, not I. As this is the default behaviour of the [mdro()] function, it follows the redefinition by EUCAST about the interpretation of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. When using `combine_SI = FALSE`, resistance is considered when isolates are R or I.
#' @param verbose a [logical] to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.
#' @inheritSection eucast_rules Antibiotics
#' @inheritSection eucast_rules Antimicrobials
#' @details
#' These functions are context-aware. This means that the `x` argument can be left blank if used inside a [data.frame] call, see *Examples*.
#'
@ -801,7 +801,7 @@ mdro <- function(x = NULL,
if (is.null(reason)) {
reason <- paste0(
any_all,
" of the required antibiotics ",
" of the required antimicrobials ",
ifelse(any_all == "any", "is", "are"),
" R",
ifelse(!isTRUE(combine_SI), " or I", "")
@ -1126,7 +1126,7 @@ mdro <- function(x = NULL,
x[which(x$classes_affected == 999 & x$classes_in_guideline == x$classes_available), "MDRO"] <- 4
if (isTRUE(verbose)) {
x[which(x$MDRO == 4), "reason"] <- paste(
"all antibiotics in all",
"all antimicrobials in all",
x$classes_in_guideline[which(x$MDRO == 4)],
"classes were tested R",
ifelse(!isTRUE(combine_SI), " or I", "")
@ -1850,7 +1850,7 @@ mdro <- function(x = NULL,
" (3 required for MDR)"
)
} else {
# x[which(x$MDRO == 1), "reason"] <- "too few antibiotics are R"
# x[which(x$MDRO == 1), "reason"] <- "too few antimicrobials are R"
}
}

View File

@ -52,7 +52,7 @@
#'
#' Determination of yeasts ([mo_is_yeast()]) will be based on the taxonomic kingdom and class. *Budding yeasts* are yeasts that reproduce asexually through a process called budding, where a new cell develops from a small protrusion on the parent cell. Taxonomically, these are members of the phylum Ascomycota, class Saccharomycetes (also called Hemiascomycetes) or Pichiomycetes. *True yeasts* quite specifically refers to yeasts in the underlying order Saccharomycetales (such as *Saccharomyces cerevisiae*). Thus, for all microorganisms that are member of the taxonomic class Saccharomycetes or Pichiomycetes, the function will return `TRUE`. It returns `FALSE` otherwise (or `NA` when the input is `NA` or the MO code is `UNKNOWN`).
#'
#' Determination of intrinsic resistance ([mo_is_intrinsic_resistant()]) will be based on the [intrinsic_resistant] data set, which is based on `r format_eucast_version_nr(3.3)`. The [mo_is_intrinsic_resistant()] function can be vectorised over both argument `x` (input for microorganisms) and `ab` (input for antibiotics).
#' Determination of intrinsic resistance ([mo_is_intrinsic_resistant()]) will be based on the [intrinsic_resistant] data set, which is based on `r format_eucast_version_nr(3.3)`. The [mo_is_intrinsic_resistant()] function can be vectorised over both argument `x` (input for microorganisms) and `ab` (input for antimicrobials).
#'
#' Determination of bacterial oxygen tolerance ([mo_oxygen_tolerance()]) will be based on BacDive, see *Source*. The function [mo_is_anaerobic()] only returns `TRUE` if the oxygen tolerance is `"anaerobe"`, indicting an obligate anaerobic species or genus. It always returns `FALSE` for species outside the taxonomic kingdom of Bacteria.
#'

View File

@ -1230,7 +1230,7 @@ facet_sir <- function(facet = c("interpretation", "antibiotic"), nrow = NULL) {
if (tolower(facet) %in% tolower(c("SIR", "sir", "interpretations", "result"))) {
facet <- "interpretation"
} else if (tolower(facet) %in% tolower(c("ab", "abx", "antibiotics"))) {
} else if (tolower(facet) %in% tolower(c("ab", "abx", "antimicrobials"))) {
facet <- "antibiotic"
}

View File

@ -35,9 +35,9 @@
#' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with [as.sir()] if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See *Examples*.
#' @param minimum the minimum allowed number of available (tested) isolates. Any isolate count lower than `minimum` will return `NA` with a warning. The default number of `30` isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see *Source*.
#' @param as_percent a [logical] to indicate whether the output must be returned as a hundred fold with % sign (a character). A value of `0.123456` will then be returned as `"12.3%"`.
#' @param only_all_tested (for combination therapies, i.e. using more than one variable for `...`): a [logical] to indicate that isolates must be tested for all antibiotics, see section *Combination Therapy* below
#' @param only_all_tested (for combination therapies, i.e. using more than one variable for `...`): a [logical] to indicate that isolates must be tested for all antimicrobials, see section *Combination Therapy* below
#' @param data a [data.frame] containing columns with class [`sir`] (see [as.sir()])
#' @param translate_ab a column name of the [antibiotics] data set to translate the antibiotic abbreviations to, using [ab_property()]
#' @param translate_ab a column name of the [antimicrobials] data set to translate the antibiotic abbreviations to, using [ab_property()]
#' @inheritParams ab_property
#' @param combine_SI a [logical] to indicate whether all values of S, SDD, and I must be merged into one, so the output only consists of S+SDD+I vs. R (susceptible vs. resistant) - the default is `TRUE`
#' @param ab_result antibiotic results to test against, must be one or more values of "S", "SDD", "I", or "R"
@ -58,7 +58,7 @@
#'
#' The function [proportion_df()] takes any variable from `data` that has an [`sir`] class (created with [as.sir()]) and calculates the proportions S, I, and R. It also supports grouped variables. The function [sir_df()] works exactly like [proportion_df()], but adds the number of isolates.
#' @section Combination Therapy:
#' When using more than one variable for `...` (= combination therapy), use `only_all_tested` to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Drug A and Drug B, about how [susceptibility()] works to calculate the %SI:
#' When using more than one variable for `...` (= combination therapy), use `only_all_tested` to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antimicrobials, Drug A and Drug B, about how [susceptibility()] works to calculate the %SI:
#'
#'
#' ```

1
R/temp_file Normal file
View File

@ -0,0 +1 @@
test_that("key_antimicrobials works", {

View File

@ -29,12 +29,16 @@
#' Deprecated Functions
#'
#' These functions are so-called '[Deprecated]'. **They will be removed in a future version of this package.** Using these functions will give a warning with the name of the function it has been replaced by (if there is one).
#' These objects are so-called '[Deprecated]'. **They will be removed in a future version of this package.** Using these will give a warning with the name of the alternative object it has been replaced by (if there is one).
#' @keywords internal
#' @name AMR-deprecated
#' @rdname AMR-deprecated
NULL
#' @rdname AMR-deprecated
#' @export
"antibiotics"
#' @rdname AMR-deprecated
#' @export
ab_class <- function(...) {
@ -50,7 +54,7 @@ ab_selector <- function(...) {
}
deprecation_warning <- function(old = NULL, new = NULL, extra_msg = NULL, is_function = TRUE) {
deprecation_warning <- function(old = NULL, new = NULL, extra_msg = NULL, is_function = TRUE, is_dataset = FALSE) {
if (is.null(old)) {
warning_(extra_msg)
} else {
@ -61,17 +65,25 @@ deprecation_warning <- function(old = NULL, new = NULL, extra_msg = NULL, is_fun
old <- paste0(old, "()")
new <- paste0(new, "()")
type <- "function"
} else if (isTRUE(is_dataset)) {
type <- "dataset"
} else {
type <- "argument"
}
warning_(
ifelse(is.null(new),
paste0("The `", old, "` ", type, " is no longer in use"),
paste0("The `", old, "` ", type, " has been replaced with `", new, "` and will be removed in a future version")
ifelse(type == "dataset",
paste0("The `", old, "` ", type, " has been renamed to `", new, "`"),
paste0("The `", old, "` ", type, " has been replaced with `", new, "` and will be removed in a future version")
)
),
ifelse(type == "argument",
". While the old argument still works, it will be removed in a future version, so please update your code.",
", see `?AMR-deprecated`."
ifelse(type == "dataset",
". The old name will be removed in future version, so please update your code.",
ifelse(type == "argument",
". While the old argument still works, it will be removed in a future version, so please update your code.",
", see `?AMR-deprecated`."
)
),
ifelse(!is.null(extra_msg),
paste0(" ", extra_msg),

17
R/zzz.R
View File

@ -91,7 +91,7 @@ AMR_env$cli_abort <- import_fn("cli_abort", "cli", error_on_fail = FALSE)
AMR_env$cross_icon <- if (isTRUE(base::l10n_info()$`UTF-8`)) "\u00d7" else "x"
.onLoad <- function(lib, pkg) {
.onLoad <- function(libname, pkgname) {
# Support for tibble headers (type_sum) and tibble columns content (pillar_shaft)
# without the need to depend on other packages. This was suggested by the
# developers of the vctrs package:
@ -203,15 +203,22 @@ AMR_env$cross_icon <- if (isTRUE(base::l10n_info()$`UTF-8`)) "\u00d7" else "x"
# reference data - they have additional data to improve algorithm speed
# they cannot be part of R/sysdata.rda since CRAN thinks it would make the package too large (+3 MB)
if (NROW(AB_LOOKUP) != NROW(AMR::antibiotics)) {
if (NROW(AB_LOOKUP) != NROW(AMR::antimicrobials)) {
# antibiotics data set was updated - run create_AB_AV_lookup() again
AB_LOOKUP <- create_AB_AV_lookup(AMR::antibiotics)
AB_LOOKUP <- create_AB_AV_lookup(AMR::antimicrobials)
}
AMR_env$AB_lookup <- cbind(AMR::antibiotics, AB_LOOKUP)
# deprecated antibiotics data set
makeActiveBinding("antibiotics", function() {
deprecation_warning(old = "antibiotics", new = "antimicrobials", is_function = FALSE, is_dataset = TRUE)
AMR::antimicrobials
}, env = asNamespace(pkgname))
AMR_env$AB_lookup <- cbind(AMR::antimicrobials, AB_LOOKUP)
AMR_env$AV_lookup <- cbind(AMR::antivirals, AV_LOOKUP)
}
.onAttach <- function(lib, pkg) {
.onAttach <- function(libname, pkgname) {
# if custom ab option is available, load it
if (!is.null(getOption("AMR_custom_ab")) && file.exists(getOption("AMR_custom_ab", default = ""))) {
if (getOption("AMR_custom_ab") %unlike% "[.]rds$") {

View File

@ -151,9 +151,9 @@ reference:
- "`add_custom_microorganisms`"
- "`mo_source`"
- title: "Preparing data: antibiotics"
- title: "Preparing data: antimicrobials"
desc: >
Use these functions to get valid properties of antibiotics from any input or to clean your input.
Use these functions to get valid properties of antimicrobials from any input or to clean your input.
You can even retrieve drug names and doses from clinical text records, using `ab_from_text()`.
contents:
- "`as.ab`"
@ -236,7 +236,7 @@ reference:
for more information about how to work with functions in this package.
contents:
- "`microorganisms`"
- "`antibiotics`"
- "`antimicrobials`"
- "`clinical_breakpoints`"
- "`example_isolates`"
- "`microorganisms.codes`"

View File

@ -115,7 +115,7 @@ example_isolates['date'] = pd.to_datetime(example_isolates['date'])
# microorganisms
microorganisms = pandas2ri.rpy2py(robjects.r('AMR::microorganisms[, !sapply(AMR::microorganisms, is.list)]'))
antibiotics = pandas2ri.rpy2py(robjects.r('AMR::antibiotics[, !sapply(AMR::antibiotics, is.list)]'))
antimicrobials = pandas2ri.rpy2py(robjects.r('AMR::antimicrobials[, !sapply(AMR::antimicrobials, is.list)]'))
clinical_breakpoints = pandas2ri.rpy2py(robjects.r('AMR::clinical_breakpoints[, !sapply(AMR::clinical_breakpoints, is.list)]'))
base.options(warn = 0)
@ -125,7 +125,7 @@ EOL
echo "from .datasets import example_isolates" >> $init_file
echo "from .datasets import microorganisms" >> $init_file
echo "from .datasets import antibiotics" >> $init_file
echo "from .datasets import antimicrobials" >> $init_file
echo "from .datasets import clinical_breakpoints" >> $init_file
@ -239,7 +239,7 @@ for rd_file in "$rd_dir"/*.Rd; do
}
# Skip functions matching the regex pattern
if (func_name_py ~ /^(x |facet|scale|set|get|NA_|microorganisms|antibiotics|clinical_breakpoints|example_isolates)/) {
if (func_name_py ~ /^(x |facet|scale|set|get|NA_|microorganisms|antimicrobials|clinical_breakpoints|example_isolates)/) {
next
}

View File

@ -364,98 +364,98 @@ pre_commit_lst$MO_RELEVANT_GENERA <- c(
# antibiotic groups
# (these will also be used for eucast_rules() and understanding data-raw/eucast_rules.tsv)
pre_commit_lst$AB_AMINOGLYCOSIDES <- antibiotics %>%
pre_commit_lst$AB_AMINOGLYCOSIDES <- antimicrobials %>%
filter(group %like% "aminoglycoside") %>%
pull(ab)
pre_commit_lst$AB_AMINOPENICILLINS <- as.ab(c("AMP", "AMX"))
pre_commit_lst$AB_ANTIFUNGALS <- antibiotics %>%
pre_commit_lst$AB_ANTIFUNGALS <- antimicrobials %>%
filter(group %like% "antifungal") %>%
pull(ab)
pre_commit_lst$AB_ANTIMYCOBACTERIALS <- antibiotics %>%
pre_commit_lst$AB_ANTIMYCOBACTERIALS <- antimicrobials %>%
filter(group %like% "antimycobacterial") %>%
pull(ab)
pre_commit_lst$AB_CARBAPENEMS <- antibiotics %>%
pre_commit_lst$AB_CARBAPENEMS <- antimicrobials %>%
filter(group %like% "carbapenem") %>%
pull(ab)
pre_commit_lst$AB_CEPHALOSPORINS <- antibiotics %>%
pre_commit_lst$AB_CEPHALOSPORINS <- antimicrobials %>%
filter(group %like% "cephalosporin") %>%
pull(ab)
pre_commit_lst$AB_CEPHALOSPORINS_1ST <- antibiotics %>%
pre_commit_lst$AB_CEPHALOSPORINS_1ST <- antimicrobials %>%
filter(group %like% "cephalosporin.*1") %>%
pull(ab)
pre_commit_lst$AB_CEPHALOSPORINS_2ND <- antibiotics %>%
pre_commit_lst$AB_CEPHALOSPORINS_2ND <- antimicrobials %>%
filter(group %like% "cephalosporin.*2") %>%
pull(ab)
pre_commit_lst$AB_CEPHALOSPORINS_3RD <- antibiotics %>%
pre_commit_lst$AB_CEPHALOSPORINS_3RD <- antimicrobials %>%
filter(group %like% "cephalosporin.*3") %>%
pull(ab)
pre_commit_lst$AB_CEPHALOSPORINS_4TH <- antibiotics %>%
pre_commit_lst$AB_CEPHALOSPORINS_4TH <- antimicrobials %>%
filter(group %like% "cephalosporin.*4") %>%
pull(ab)
pre_commit_lst$AB_CEPHALOSPORINS_5TH <- antibiotics %>%
pre_commit_lst$AB_CEPHALOSPORINS_5TH <- antimicrobials %>%
filter(group %like% "cephalosporin.*5") %>%
pull(ab)
pre_commit_lst$AB_CEPHALOSPORINS_EXCEPT_CAZ <- pre_commit_lst$AB_CEPHALOSPORINS[pre_commit_lst$AB_CEPHALOSPORINS != "CAZ"]
pre_commit_lst$AB_FLUOROQUINOLONES <- antibiotics %>%
pre_commit_lst$AB_FLUOROQUINOLONES <- antimicrobials %>%
filter(atc_group2 %like% "fluoroquinolone" | (group %like% "quinolone" & is.na(atc_group2))) %>%
pull(ab)
pre_commit_lst$AB_GLYCOPEPTIDES <- antibiotics %>%
pre_commit_lst$AB_GLYCOPEPTIDES <- antimicrobials %>%
filter(group %like% "glycopeptide") %>%
pull(ab)
pre_commit_lst$AB_ISOXAZOLYLPENICILLINS <- antibiotics %>%
pre_commit_lst$AB_ISOXAZOLYLPENICILLINS <- antimicrobials %>%
filter(name %like% "oxacillin|cloxacillin|dicloxacillin|flucloxacillin|meth?icillin") %>%
pull(ab)
pre_commit_lst$AB_LIPOGLYCOPEPTIDES <- as.ab(c("DAL", "ORI", "TLV")) # dalba/orita/tela
pre_commit_lst$AB_GLYCOPEPTIDES_EXCEPT_LIPO <- pre_commit_lst$AB_GLYCOPEPTIDES[!pre_commit_lst$AB_GLYCOPEPTIDES %in% pre_commit_lst$AB_LIPOGLYCOPEPTIDES]
pre_commit_lst$AB_LINCOSAMIDES <- antibiotics %>%
pre_commit_lst$AB_LINCOSAMIDES <- antimicrobials %>%
filter(atc_group2 %like% "lincosamide" | (group %like% "lincosamide" & is.na(atc_group2) & name %like% "^(pirlimycin)" & name %unlike% "screening|inducible")) %>%
pull(ab)
pre_commit_lst$AB_MACROLIDES <- antibiotics %>%
pre_commit_lst$AB_MACROLIDES <- antimicrobials %>%
filter(atc_group2 %like% "macrolide" | (group %like% "macrolide" & is.na(atc_group2) & name %like% "^(acetylmidecamycin|acetylspiramycin|gamith?romycin|kitasamycin|meleumycin|nafith?romycin|solith?romycin|tildipirosin|tilmicosin|tulath?romycin|tylosin|tylvalosin)" & name %unlike% "screening|inducible")) %>%
pull(ab)
pre_commit_lst$AB_MONOBACTAMS <- antibiotics %>%
pre_commit_lst$AB_MONOBACTAMS <- antimicrobials %>%
filter(group %like% "monobactam") %>%
pull(ab)
pre_commit_lst$AB_NITROFURANS <- antibiotics %>%
pre_commit_lst$AB_NITROFURANS <- antimicrobials %>%
filter(name %like% "^furaz|nitrofura" | atc_group2 %like% "nitrofuran") %>%
pull(ab)
pre_commit_lst$AB_OXAZOLIDINONES <- antibiotics %>%
pre_commit_lst$AB_OXAZOLIDINONES <- antimicrobials %>%
filter(group %like% "oxazolidinone") %>%
pull(ab)
pre_commit_lst$AB_PENICILLINS <- antibiotics %>%
pre_commit_lst$AB_PENICILLINS <- antimicrobials %>%
filter(group %like% "penicillin" & !(name %unlike% "/" & name %like% ".*bactam$")) %>%
pull(ab)
pre_commit_lst$AB_PHENICOLS <- antibiotics %>%
pre_commit_lst$AB_PHENICOLS <- antimicrobials %>%
filter(group %like% "phenicol" | atc_group1 %like% "phenicol" | atc_group2 %like% "phenicol") %>%
pull(ab)
pre_commit_lst$AB_POLYMYXINS <- antibiotics %>%
pre_commit_lst$AB_POLYMYXINS <- antimicrobials %>%
filter(group %like% "polymyxin") %>%
pull(ab)
pre_commit_lst$AB_QUINOLONES <- antibiotics %>%
pre_commit_lst$AB_QUINOLONES <- antimicrobials %>%
filter(group %like% "quinolone") %>%
pull(ab)
pre_commit_lst$AB_RIFAMYCINS <- antibiotics %>%
pre_commit_lst$AB_RIFAMYCINS <- antimicrobials %>%
filter(name %like% "Rifampi|Rifabutin|Rifapentine|rifamy") %>%
pull(ab)
pre_commit_lst$AB_STREPTOGRAMINS <- antibiotics %>%
pre_commit_lst$AB_STREPTOGRAMINS <- antimicrobials %>%
filter(atc_group2 %like% "streptogramin") %>%
pull(ab)
pre_commit_lst$AB_TETRACYCLINES <- antibiotics %>%
pre_commit_lst$AB_TETRACYCLINES <- antimicrobials %>%
filter(group %like% "tetracycline") %>%
pull(ab)
pre_commit_lst$AB_TETRACYCLINES_EXCEPT_TGC <- pre_commit_lst$AB_TETRACYCLINES[pre_commit_lst$AB_TETRACYCLINES != "TGC"]
pre_commit_lst$AB_TRIMETHOPRIMS <- antibiotics %>%
pre_commit_lst$AB_TRIMETHOPRIMS <- antimicrobials %>%
filter(group %like% "trimethoprim") %>%
pull(ab)
pre_commit_lst$AB_UREIDOPENICILLINS <- as.ab(c("PIP", "TZP", "AZL", "MEZ"))
pre_commit_lst$AB_BETALACTAMS <- sort(c(pre_commit_lst$AB_PENICILLINS, pre_commit_lst$AB_CEPHALOSPORINS, pre_commit_lst$AB_CARBAPENEMS, pre_commit_lst$AB_MONOBACTAMS))
pre_commit_lst$AB_BETALACTAMS_WITH_INHIBITOR <- antibiotics %>%
pre_commit_lst$AB_BETALACTAMS_WITH_INHIBITOR <- antimicrobials %>%
filter(name %like% "/" & name %unlike% "EDTA" & ab %in% pre_commit_lst$AB_BETALACTAMS) %>%
pull(ab)
# this will be used for documentation:
pre_commit_lst$DEFINED_AB_GROUPS <- sort(names(pre_commit_lst)[names(pre_commit_lst) %like% "^AB_" & names(pre_commit_lst) != "AB_LOOKUP"])
pre_commit_lst$AB_LOOKUP <- create_AB_AV_lookup(antibiotics)
pre_commit_lst$AB_LOOKUP <- create_AB_AV_lookup(antimicrobials)
pre_commit_lst$AV_LOOKUP <- create_AB_AV_lookup(antivirals)
# Export to package as internal data ----
@ -506,7 +506,7 @@ changed_md5 <- function(object) {
# give official names to ABs and MOs
clin_break <- clinical_breakpoints %>%
mutate(mo_name = microorganisms$fullname[match(mo, microorganisms$mo)], .after = mo) %>%
mutate(ab_name = antibiotics$name[match(ab, antibiotics$ab)], .after = ab)
mutate(ab_name = antimicrobials$name[match(ab, antimicrobials$ab)], .after = ab)
if (changed_md5(clin_break)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('clinical_breakpoints')} to {usethis::ui_value('data-raw/')}"))
write_md5(clin_break)
@ -560,18 +560,18 @@ if (changed_md5(microorganisms.groups)) {
try(arrow::write_parquet(microorganisms.groups, "data-raw/microorganisms.groups.parquet"), silent = TRUE)
}
ab <- dplyr::mutate_if(antibiotics, ~ !is.numeric(.), as.character)
ab <- dplyr::mutate_if(antimicrobials, ~ !is.numeric(.), as.character)
if (changed_md5(ab)) {
usethis::ui_info(paste0("Saving {usethis::ui_value('antibiotics')} to {usethis::ui_value('data-raw/')}"))
usethis::ui_info(paste0("Saving {usethis::ui_value('antimicrobials')} to {usethis::ui_value('data-raw/')}"))
write_md5(ab)
try(saveRDS(antibiotics, "data-raw/antibiotics.rds", version = 2, compress = "xz"), silent = TRUE)
try(haven::write_sav(ab, "data-raw/antibiotics.sav"), silent = TRUE)
try(haven::write_dta(ab, "data-raw/antibiotics.dta"), silent = TRUE)
ab_lists <- antibiotics %>% mutate_if(is.list, function(x) sapply(x, paste, collapse = ","))
try(write.table(ab_lists, "data-raw/antibiotics.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
try(openxlsx2::write_xlsx(ab_lists, "data-raw/antibiotics.xlsx"), silent = TRUE)
try(arrow::write_feather(antibiotics, "data-raw/antibiotics.feather"), silent = TRUE)
try(arrow::write_parquet(antibiotics, "data-raw/antibiotics.parquet"), silent = TRUE)
try(saveRDS(antimicrobials, "data-raw/antimicrobials.rds", version = 2, compress = "xz"), silent = TRUE)
try(haven::write_sav(ab, "data-raw/antimicrobials.sav"), silent = TRUE)
try(haven::write_dta(ab, "data-raw/antimicrobials.dta"), silent = TRUE)
ab_lists <- antimicrobials %>% mutate_if(is.list, function(x) sapply(x, paste, collapse = ","))
try(write.table(ab_lists, "data-raw/antimicrobials.txt", sep = "\t", na = "", row.names = FALSE), silent = TRUE)
try(openxlsx2::write_xlsx(ab_lists, "data-raw/antimicrobials.xlsx"), silent = TRUE)
try(arrow::write_feather(antimicrobials, "data-raw/antimicrobials.feather"), silent = TRUE)
try(arrow::write_parquet(antimicrobials, "data-raw/antimicrobials.parquet"), silent = TRUE)
}
av <- dplyr::mutate_if(antivirals, ~ !is.numeric(.), as.character)

File diff suppressed because one or more lines are too long

View File

@ -50,15 +50,15 @@ loinc_df <- loinc_df %>%
filter(CLASS %in% c("DRUG/TOX", "ABXBACT")) %>%
mutate(name = generalise_antibiotic_name(COMPONENT), .before = 1)
# antibiotics
antibiotics$loinc <- as.list(rep(NA_character_, nrow(antibiotics)))
for (i in seq_len(nrow(antibiotics))) {
# antimicrobials
antimicrobials$loinc <- as.list(rep(NA_character_, nrow(antimicrobials)))
for (i in seq_len(nrow(antimicrobials))) {
message(i)
loinc_ab <- loinc_df %>%
filter(name %like% paste0("^", generalise_antibiotic_name(antibiotics$name[i]))) %>%
filter(name %like% paste0("^", generalise_antibiotic_name(antimicrobials$name[i]))) %>%
pull(LOINC_NUM)
if (length(loinc_ab) > 0) {
antibiotics$loinc[i] <- list(loinc_ab)
antimicrobials$loinc[i] <- list(loinc_ab)
}
}
@ -75,10 +75,10 @@ for (i in seq_len(nrow(antivirals))) {
}
# sort and fix for empty values
for (i in 1:nrow(antibiotics)) {
loinc <- as.character(sort(unique(tolower(antibiotics[i, "loinc", drop = TRUE][[1]]))))
for (i in 1:nrow(antimicrobials)) {
loinc <- as.character(sort(unique(tolower(antimicrobials[i, "loinc", drop = TRUE][[1]]))))
loinc <- loinc[loinc != ""]
antibiotics[i, "loinc"][[1]] <- ifelse(length(loinc) == 0, list(""), list(loinc))
antimicrobials[i, "loinc"][[1]] <- ifelse(length(loinc) == 0, list(""), list(loinc))
}
for (i in 1:nrow(antivirals)) {
loinc <- as.character(sort(unique(tolower(antivirals[i, "loinc", drop = TRUE][[1]]))))
@ -86,17 +86,17 @@ for (i in 1:nrow(antivirals)) {
antivirals[i, "loinc"][[1]] <- ifelse(length(loinc) == 0, list(""), list(loinc))
}
antibiotics <- dataset_UTF8_to_ASCII(as.data.frame(antibiotics, stringsAsFactors = FALSE))
antibiotics <- dplyr::arrange(antibiotics, name)
antimicrobials <- dataset_UTF8_to_ASCII(as.data.frame(antimicrobials, stringsAsFactors = FALSE))
antimicrobials <- dplyr::arrange(antimicrobials, name)
antivirals <- dataset_UTF8_to_ASCII(as.data.frame(antivirals, stringsAsFactors = FALSE))
antivirals <- dplyr::arrange(antivirals, name)
# remember to update R/aa_globals.R for the documentation
dim(antibiotics) # for R/data.R
usethis::use_data(antibiotics, internal = FALSE, overwrite = TRUE, compress = "xz", version = 2)
rm(antibiotics)
dim(antimicrobials) # for R/data.R
usethis::use_data(antimicrobials, internal = FALSE, overwrite = TRUE, compress = "xz", version = 2)
rm(antimicrobials)
dim(antivirals) # for R/data.R
usethis::use_data(antivirals, internal = FALSE, overwrite = TRUE, compress = "xz", version = 2)

View File

@ -1,948 +0,0 @@
# ==================================================================== #
# TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data #
# #
# SOURCE CODE: #
# https://github.com/msberends/AMR #
# #
# PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
# Journal of Statistical Software, 104(3), 1-31. #
# https://doi.org/10.18637/jss.v104.i03 #
# #
# Developed at the University of Groningen and the University Medical #
# Center Groningen in The Netherlands, in collaboration with many #
# colleagues from around the world, see our website. #
# #
# 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 the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
library(dplyr)
# got EARS-Net codes (= ECDC/WHO codes) from here:
# Installed WHONET 2019 software on Windows (http://www.whonet.org/software.html),
# opened C:\WHONET\Codes\WHONETCodes.mdb in MS Access
# and exported table 'DRGLST' to MS Excel
library(readxl)
DRGLST <- read_excel("DRGLST.xlsx")
abx <- DRGLST %>%
select(
ab = WHON5_CODE,
name = ANTIBIOTIC
) %>%
# remove the ones without WHONET code
filter(!is.na(ab)) %>%
distinct(name, .keep_all = TRUE) %>%
# add the ones without WHONET code
bind_rows(
DRGLST %>%
select(
ab = WHON5_CODE,
name = ANTIBIOTIC
) %>%
filter(is.na(ab)) %>%
distinct(name, .keep_all = TRUE)
# add new ab code later
) %>%
arrange(name)
# add old ATC codes
ab_old <- AMR::antibiotics %>%
mutate(
official = gsub("( and |, )", "/", official),
abbr = tolower(paste(ifelse(is.na(abbr), "", abbr),
ifelse(is.na(certe), "", certe),
ifelse(is.na(umcg), "", umcg),
sep = "|"
))
)
for (i in 1:nrow(ab_old)) {
abbr <- ab_old[i, "abbr"]
abbr <- strsplit(abbr, "|", fixed = TRUE) %>%
unlist() %>%
unique()
abbr <- abbr[abbr != ""]
# print(abbr)
if (length(abbr) == 0) {
ab_old[i, "abbr"] <- NA_character_
} else {
ab_old[i, "abbr"] <- paste(abbr, collapse = "|")
}
}
# create reference data set: to be able to map ab to atc
abx_atc1 <- abx %>%
mutate(name_lower = tolower(name)) %>%
left_join(ab_old %>%
select(ears_net, atc), by = c(ab = "ears_net")) %>%
rename(atc1 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc2 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
mutate(official = gsub("f", "ph", official)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc3 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
mutate(official = gsub("t", "th", official)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc4 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
mutate(official = gsub("f", "ph", official)) %>%
mutate(official = gsub("t", "th", official)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc5 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
mutate(official = gsub("f", "ph", official)) %>%
mutate(official = gsub("t", "th", official)) %>%
mutate(official = gsub("ine$", "in", official)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc6 = atc) %>%
mutate(atc = case_when(
!is.na(atc1) ~ atc1,
!is.na(atc2) ~ atc2,
!is.na(atc3) ~ atc3,
!is.na(atc4) ~ atc4,
!is.na(atc4) ~ atc5,
TRUE ~ atc6
)) %>%
distinct(ab, name, .keep_all = TRUE) %>%
select(ab, atc, name)
abx_atc2 <- ab_old %>%
filter(
!atc %in% abx_atc1$atc,
is.na(ears_net),
!is.na(atc_group1),
atc_group1 %unlike% ("virus|vaccin|viral|immun"),
official %unlike% "(combinations| with )"
) %>%
mutate(ab = NA_character_) %>%
as.data.frame(stringsAsFactors = FALSE) %>%
select(ab, atc, name = official)
abx2 <- bind_rows(abx_atc1, abx_atc2)
rm(abx_atc1)
rm(abx_atc2)
abx2$ab[is.na(abx2$ab)] <- toupper(abbreviate(
gsub(
"[/0-9-]",
" ",
abx2$name[is.na(abx2$ab)]
),
minlength = 3,
method = "left.kept",
strict = TRUE
))
n_distinct(abx2$ab)
abx2 <- abx2 %>% arrange(ab)
seqnr <- 0
# add follow up nrs
for (i in 2:nrow(abx2)) {
if (abx2[i, "ab", drop = TRUE] == abx2[i - 1, "ab", drop = TRUE]) {
seqnr <- seqnr + 1
abx2[i, "seqnr"] <- seqnr
} else {
seqnr <- 0
}
}
for (i in 2:nrow(abx2)) {
if (!is.na(abx2[i, "seqnr"])) {
abx2[i, "ab"] <- paste0(abx2[i, "ab", drop = TRUE], abx2[i, "seqnr", drop = TRUE])
}
}
abx2 <- abx2 %>%
select(-seqnr) %>%
arrange(name)
# everything unique??
nrow(abx2) == n_distinct(abx2$ab)
# get ATC properties
abx2 <- abx2 %>%
left_join(ab_old %>%
select(
atc, abbr, atc_group1, atc_group2,
oral_ddd, oral_units, iv_ddd, iv_units
))
abx2$abbr <- lapply(as.list(abx2$abbr), function(x) unlist(strsplit(x, "|", fixed = TRUE)))
# Update Compound IDs and Synonyms ----
# vector with official names, returns vector with CIDs
get_CID <- function(ab) {
CID <- rep(NA_integer_, length(ab))
p <- AMR:::progress_ticker(n = length(ab), min_time = 0)
for (i in 1:length(ab)) {
p$tick()
CID[i] <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/",
URLencode(ab[i], reserved = TRUE),
"/cids/TXT?name_type=complete"
),
showProgress = FALSE
)[[1]][1],
error = function(e) NA_integer_
)
if (is.na(CID[i])) {
# try with removing the text in brackets
CID[i] <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/",
URLencode(trimws(gsub("[(].*[)]", "", ab[i])), reserved = TRUE),
"/cids/TXT?name_type=complete"
),
showProgress = FALSE
)[[1]][1],
error = function(e) NA_integer_
)
}
if (is.na(CID[i])) {
# try match on word and take the lowest CID value (sorted)
ab[i] <- gsub("[^a-z0-9]+", " ", ab[i], ignore.case = TRUE)
CID[i] <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/",
URLencode(ab[i], reserved = TRUE),
"/cids/TXT?name_type=word"
),
showProgress = FALSE
)[[1]][1],
error = function(e) NA_integer_
)
}
Sys.sleep(0.1)
}
CID
}
# get CIDs (4-5 min)
CIDs <- get_CID(antibiotics$name)
# take missing from previously found CIDs
CIDs[is.na(CIDs) & !is.na(antibiotics$cid)] <- antibiotics$cid[is.na(CIDs) & !is.na(antibiotics$cid)]
# These could not be found:
antibiotics[is.na(CIDs), ] %>% View()
# returns list with synonyms (brand names), with CIDs as names
get_synonyms <- function(CID, clean = TRUE) {
synonyms <- rep(NA_character_, length(CID))
p <- AMR:::progress_ticker(n = length(CID), min_time = 0)
for (i in 1:length(CID)) {
p$tick()
synonyms_txt <- ""
if (is.na(CID[i])) {
next
}
# we will now get the closest compounds with a 96% threshold
similar_cids <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/fastsimilarity_2d/cid/",
CID[i],
"/cids/TXT?Threshold=96&MaxRecords=5"
),
sep = "\n",
showProgress = FALSE
)[[1]],
error = function(e) NA_character_
)
# include the current CID of course
all_cids <- unique(c(CID[i], similar_cids))
# but leave out all CIDs that we have in our antibiotics dataset to prevent duplication
all_cids <- all_cids[!all_cids %in% antibiotics$cid[!is.na(antibiotics$cid)]]
# for each one, we are getting the synonyms
current_syns <- character(0)
for (j in seq_len(length(all_cids))) {
synonyms_txt <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/fastidentity/cid/",
all_cids[j],
"/synonyms/TXT"
),
sep = "\n",
showProgress = FALSE
)[[1]],
error = function(e) NA_character_
)
Sys.sleep(0.05)
if (clean == TRUE) {
# remove text between brackets
synonyms_txt <- trimws(gsub(
"[(].*[)]", "",
gsub(
"[[].*[]]", "",
gsub(
"[(].*[]]", "",
gsub("[[].*[)]", "", synonyms_txt)
)
)
))
synonyms_txt <- gsub("Co-", "Co", synonyms_txt, fixed = TRUE)
synonyms_txt <- gsub(" ?(mono)?sodium ?", "", ignore.case = TRUE, synonyms_txt)
synonyms_txt <- gsub(" ?(injection|pediatric) ?", "", ignore.case = TRUE, synonyms_txt)
# only length 6 to 20 and no txt with reading marks or numbers and must start with capital letter (= brand)
synonyms_txt <- synonyms_txt[nchar(synonyms_txt) %in% c(5:20) &
!grepl("[-&{},_0-9/:]", synonyms_txt) &
grepl("^[A-Z]", synonyms_txt, ignore.case = FALSE)]
synonyms_txt <- unlist(strsplit(synonyms_txt, ";", fixed = TRUE))
}
current_syns <- c(current_syns, synonyms_txt)
}
current_syns <- unique(trimws(current_syns[tolower(current_syns) %in% unique(tolower(current_syns))]))
synonyms[i] <- list(sort(current_syns))
}
names(synonyms) <- CID
synonyms
}
# get brand names from PubChem (3-4 min)
synonyms <- get_synonyms(CIDs)
synonyms.bak <- synonyms
synonyms <- synonyms.bak
# add existing ones (will be cleaned later)
for (i in seq_len(length(synonyms))) {
old <- unname(unlist(AMR::antibiotics[i, "synonyms", drop = TRUE]))
synonyms[[i]] <- c(unname(synonyms[[i]]), old)
}
antibiotics$synonyms <- synonyms
stop("remember to remove co-trimoxazole as synonyms from SMX (Sulfamethoxazole), so it only exists in SXT!")
sulfa <- antibiotics[which(antibiotics$ab == "SMX"), "synonyms", drop = TRUE][[1]]
cotrim <- antibiotics[which(antibiotics$ab == "SXT"), "synonyms", drop = TRUE][[1]]
# 2024-10-06 not the case anymore, no overlapping names: sulfa[sulfa %in% cotrim]
sulfa <- sulfa[!sulfa %in% cotrim]
antibiotics[which(antibiotics$ab == "SMX"), "synonyms"][[1]][[1]] <- sulfa
# now go to end of this file
# -----
# add them to data set
antibiotics <- abx2 %>%
left_join(DRGLST %>%
select(ab = WHON5_CODE, CLASS, SUBCLASS) %>%
distinct(ab, .keep_all = TRUE), by = "ab") %>%
transmute(ab,
atc,
cid = CIDs,
# no capital after a slash: Ampicillin/Sulbactam -> Ampicillin/sulbactam
name = name %>%
gsub("([/-])([A-Z])", "\\1\\L\\2", ., perl = TRUE) %>%
gsub("edta", "EDTA", ., ignore.case = TRUE),
group = case_when(
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "am(ph|f)enicol" ~ "Amphenicols",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "aminoglycoside" ~ "Aminoglycosides",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "carbapenem" | name %like% "(imipenem|meropenem)" ~ "Carbapenems",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "First-generation cephalosporin" ~ "Cephalosporins (1st gen.)",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "Second-generation cephalosporin" ~ "Cephalosporins (2nd gen.)",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "Third-generation cephalosporin" ~ "Cephalosporins (3rd gen.)",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "Fourth-generation cephalosporin" ~ "Cephalosporins (4th gen.)",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "(tuberculosis|mycobacter)" ~ "Antimycobacterials",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "cephalosporin" ~ "Cephalosporins",
name %like% "^Ce" & is.na(atc_group1) & paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "beta-?lactam" ~ "Cephalosporins",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "(beta-?lactam|penicillin)" ~ "Beta-lactams/penicillins",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "quinolone" ~ "Quinolones",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "glycopeptide" ~ "Glycopeptides",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "macrolide" ~ "Macrolides/lincosamides",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "tetracycline" ~ "Tetracyclines",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "trimethoprim" ~ "Trimethoprims",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "polymyxin" ~ "Polymyxins",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "(fungal|mycot)" ~ "Antifungals/antimycotics",
TRUE ~ "Other antibacterials"
),
atc_group1, atc_group2,
abbreviations = unname(abbr),
synonyms = unname(synonyms),
oral_ddd, oral_units,
iv_ddd, iv_units
) %>%
as.data.frame(stringsAsFactors = FALSE)
# some exceptions
antibiotics[which(antibiotics$ab == "DOX"), "abbreviations"][[1]] <- list(c("dox", "doxy"))
antibiotics[which(antibiotics$ab == "FLC"), "abbreviations"][[1]] <- list(c("clox"))
antibiotics[which(antibiotics$ab == "CEC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CEC"), "abbreviations"][[1]], "CFC")) # cefaclor old WHONET4 code
antibiotics[which(antibiotics$ab == "AMX"), "synonyms"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "AMX"), "synonyms"][[1]], "Amoxy")))
# 'Polymixin B' (POL) and 'Polymyxin B' (PLB) both exist, so:
antibiotics[which(antibiotics$ab == "PLB"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PLB"), "abbreviations"][[1]], "POL", "Polymixin", "Polymixin B", "Poly B"))
antibiotics <- filter(antibiotics, ab != "POL")
# 'Latamoxef' (LTM) and 'Moxalactam (Latamoxef)' (MOX) both exist, so:
antibiotics[which(antibiotics$ab == "LTM"), "abbreviations"][[1]] <- list(c("MOX", "moxa"))
antibiotics <- filter(antibiotics, ab != "MOX")
# RFP and RFP1 (the J0 one) both mean 'rifapentine', although 'rifp' is not recognised, so:
antibiotics <- filter(antibiotics, ab != "RFP")
antibiotics[which(antibiotics$ab == "RFP1"), "ab"] <- "RFP"
antibiotics[which(antibiotics$ab == "RFP"), "abbreviations"][[1]] <- list(c("rifp"))
# Rifampicin is better known as a drug than Rifampin (Rifampin is still listed as a brand name), so:
antibiotics[which(antibiotics$ab == "RIF"), "name"] <- "Rifampicin"
# PME and PVM1 (the J0 one) both mean 'Pivmecillinam', so:
antibiotics <- filter(antibiotics, ab != "PME")
antibiotics[which(antibiotics$ab == "PVM1"), "ab"] <- "PME"
# Remove Sinecatechins
antibiotics <- filter(antibiotics, ab != "SNC")
# GLIMS codes
antibiotics[which(antibiotics$ab == as.ab("cefuroxim")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("cefuroxim")), "abbreviations"][[1]], "cfrx"))
antibiotics[which(antibiotics$ab == as.ab("cefotaxim")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("cefotaxim")), "abbreviations"][[1]], "cftx"))
antibiotics[which(antibiotics$ab == as.ab("ceftazidime")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("ceftazidime")), "abbreviations"][[1]], "cftz"))
antibiotics[which(antibiotics$ab == as.ab("cefepime")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("cefepime")), "abbreviations"][[1]], "cfpi"))
antibiotics[which(antibiotics$ab == as.ab("cefoxitin")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("cefoxitin")), "abbreviations"][[1]], "cfxt"))
# Add cefoxitin screening
class(antibiotics$ab) <- "character"
antibiotics <- rbind(antibiotics, data.frame(
ab = "FOX1", atc = NA, cid = NA,
name = "Cefoxitin screening",
group = "Cephalosporins (2nd gen.)", atc_group1 = NA, atc_group2 = NA,
abbreviations = "cfsc", synonyms = NA,
oral_ddd = NA, oral_units = NA, iv_ddd = NA, iv_units = NA,
loinc = NA,
stringsAsFactors = FALSE
))
# More GLIMS codes
antibiotics[which(antibiotics$ab == "AMB"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AMB"), "abbreviations"][[1]], "amf"))
antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]], "cftz"))
antibiotics[which(antibiotics$ab == "COL"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "COL"), "abbreviations"][[1]], "cst"))
antibiotics[which(antibiotics$ab == "CRO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CRO"), "abbreviations"][[1]], "cftr"))
antibiotics[which(antibiotics$ab == "CTX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CTX"), "abbreviations"][[1]], "cftx"))
antibiotics[which(antibiotics$ab == "CXM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CXM"), "abbreviations"][[1]], "cfrx"))
antibiotics[which(antibiotics$ab == "CZO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CZO"), "abbreviations"][[1]], "cfzl"))
antibiotics[which(antibiotics$ab == "FCT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FCT"), "abbreviations"][[1]], "fcu"))
antibiotics[which(antibiotics$ab == "FCT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FCT"), "abbreviations"][[1]], "fluy"))
antibiotics[which(antibiotics$ab == "FLU"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FLU"), "abbreviations"][[1]], "flz"))
antibiotics[which(antibiotics$ab == "FOS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FOS"), "abbreviations"][[1]], "fof"))
antibiotics[which(antibiotics$ab == "FOX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FOX"), "abbreviations"][[1]], "cfxt"))
antibiotics[which(antibiotics$ab == "FUS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FUS"), "abbreviations"][[1]], "fa"))
antibiotics[which(antibiotics$ab == "GEH"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "GEH"), "abbreviations"][[1]], "g_h"))
antibiotics[which(antibiotics$ab == "KAH"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "KAH"), "abbreviations"][[1]], "k_h"))
antibiotics[which(antibiotics$ab == "KET"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "KET"), "abbreviations"][[1]], "ktc"))
antibiotics[which(antibiotics$ab == "PIP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PIP"), "abbreviations"][[1]], "pipc"))
antibiotics[which(antibiotics$ab == "PIP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PIP"), "abbreviations"][[1]], "PIPC"))
antibiotics[which(antibiotics$ab == "SPX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SPX"), "abbreviations"][[1]], "spa"))
antibiotics[which(antibiotics$ab == "STH"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "STH"), "abbreviations"][[1]], "s_h"))
antibiotics[which(antibiotics$ab == "STR1"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "STR1"), "abbreviations"][[1]], "stm"))
antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]], "COTRIM"))
antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]], "trsx"))
antibiotics[which(antibiotics$ab == "TGC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TGC"), "abbreviations"][[1]], "tig"))
antibiotics[which(antibiotics$ab == "TMP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TMP"), "abbreviations"][[1]], "tri"))
antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]], "PIPTAZ"))
antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]], "pit"))
antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]], "pita"))
antibiotics[which(antibiotics$ab == "VOR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "VOR"), "abbreviations"][[1]], "vrc"))
# official RIVM codes (Dutch National Health Institute)
# https://www.rivm.nl/sites/default/files/2019-09/Bijlage_4_Lijst_antibiotica%202020%201.0.pdf
antibiotics[which(antibiotics$ab == "FCT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FCT"), "abbreviations"][[1]], "5flc"))
antibiotics[which(antibiotics$ab == "AMC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AMC"), "abbreviations"][[1]], "amcl"))
antibiotics[which(antibiotics$ab == "AMB"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AMB"), "abbreviations"][[1]], "amfb"))
antibiotics[which(antibiotics$ab == "AMH"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AMH"), "abbreviations"][[1]], "amhl"))
antibiotics[which(antibiotics$ab == "AMK"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AMK"), "abbreviations"][[1]], "amik"))
antibiotics[which(antibiotics$ab == "AMX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AMX"), "abbreviations"][[1]], "amox"))
antibiotics[which(antibiotics$ab == "AMP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AMP"), "abbreviations"][[1]], "ampi"))
antibiotics[which(antibiotics$ab == "SAM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SAM"), "abbreviations"][[1]], "amsu"))
antibiotics[which(antibiotics$ab == "ANI"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "ANI"), "abbreviations"][[1]], "anid"))
antibiotics[which(antibiotics$ab == "SAM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SAM"), "abbreviations"][[1]], "apsu"))
antibiotics[which(antibiotics$ab == "AZM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AZM"), "abbreviations"][[1]], "azit"))
antibiotics[which(antibiotics$ab == "AZL"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "AZL"), "abbreviations"][[1]], "azlo"))
antibiotics[which(antibiotics$ab == "ATM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "ATM"), "abbreviations"][[1]], "aztr"))
antibiotics[which(antibiotics$ab == "PNV"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PNV"), "abbreviations"][[1]], "bepe"))
antibiotics[which(antibiotics$ab == "CAP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CAP"), "abbreviations"][[1]], "capr"))
antibiotics[which(antibiotics$ab == "CRB"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CRB"), "abbreviations"][[1]], "carb"))
antibiotics[which(antibiotics$ab == "CAS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CAS"), "abbreviations"][[1]], "casp"))
antibiotics[which(antibiotics$ab == "CDC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CDC"), "abbreviations"][[1]], "cecl"))
antibiotics[which(antibiotics$ab == "CXA"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CXA"), "abbreviations"][[1]], "cfax"))
antibiotics[which(antibiotics$ab == "CTB"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CTB"), "abbreviations"][[1]], "cfbu"))
antibiotics[which(antibiotics$ab == "CEC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CEC"), "abbreviations"][[1]], "cfcl"))
antibiotics[which(antibiotics$ab == "CFR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CFR"), "abbreviations"][[1]], "cfdx"))
antibiotics[which(antibiotics$ab == "CEP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CEP"), "abbreviations"][[1]], "cflt"))
antibiotics[which(antibiotics$ab == "LEX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "LEX"), "abbreviations"][[1]], "cflx"))
antibiotics[which(antibiotics$ab == "MAN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MAN"), "abbreviations"][[1]], "cfmn"))
antibiotics[which(antibiotics$ab == "CPD"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CPD"), "abbreviations"][[1]], "cfpd"))
antibiotics[which(antibiotics$ab == "FEP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FEP"), "abbreviations"][[1]], "cfpi"))
antibiotics[which(antibiotics$ab == "CPO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CPO"), "abbreviations"][[1]], "cfpr"))
antibiotics[which(antibiotics$ab == "CFP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CFP"), "abbreviations"][[1]], "cfpz"))
antibiotics[which(antibiotics$ab == "CED"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CED"), "abbreviations"][[1]], "cfrd"))
antibiotics[which(antibiotics$ab == "CPT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CPT"), "abbreviations"][[1]], "cfro"))
antibiotics[which(antibiotics$ab == "CXM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CXM"), "abbreviations"][[1]], "cfrx"))
antibiotics[which(antibiotics$ab == "CFS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CFS"), "abbreviations"][[1]], "cfsl"))
antibiotics[which(antibiotics$ab == "CRO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CRO"), "abbreviations"][[1]], "cftr"))
antibiotics[which(antibiotics$ab == "CTT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CTT"), "abbreviations"][[1]], "cftt"))
antibiotics[which(antibiotics$ab == "CTX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CTX"), "abbreviations"][[1]], "cftx"))
antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]], "cftz"))
antibiotics[which(antibiotics$ab == "CFM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CFM"), "abbreviations"][[1]], "cfxm"))
antibiotics[which(antibiotics$ab == "FOX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FOX"), "abbreviations"][[1]], "cfxt"))
antibiotics[which(antibiotics$ab == "CZA"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CZA"), "abbreviations"][[1]], "cfav"))
antibiotics[which(antibiotics$ab == "CZO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CZO"), "abbreviations"][[1]], "cfzl"))
antibiotics[which(antibiotics$ab == "CZX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CZX"), "abbreviations"][[1]], "cfzx"))
antibiotics[which(antibiotics$ab == "CHL"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CHL"), "abbreviations"][[1]], "chlo"))
antibiotics[which(antibiotics$ab == "CPC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CPC"), "abbreviations"][[1]], "cicl"))
antibiotics[which(antibiotics$ab == "CIN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CIN"), "abbreviations"][[1]], "cino"))
antibiotics[which(antibiotics$ab == "CIP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CIP"), "abbreviations"][[1]], "cipr"))
antibiotics[which(antibiotics$ab == "CIX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CIX"), "abbreviations"][[1]], "cipx"))
antibiotics[which(antibiotics$ab == "CLR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CLR"), "abbreviations"][[1]], "clar"))
antibiotics[which(antibiotics$ab == "CLI"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CLI"), "abbreviations"][[1]], "clin"))
antibiotics[which(antibiotics$ab == "CTR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CTR"), "abbreviations"][[1]], "clot"))
antibiotics[which(antibiotics$ab == "CLO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CLO"), "abbreviations"][[1]], "clox"))
antibiotics[which(antibiotics$ab == "COL"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "COL"), "abbreviations"][[1]], "coli"))
antibiotics[which(antibiotics$ab == "CTC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CTC"), "abbreviations"][[1]], "cxcl"))
antibiotics[which(antibiotics$ab == "CYC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CYC"), "abbreviations"][[1]], "cycl"))
antibiotics[which(antibiotics$ab == "CCV"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CCV"), "abbreviations"][[1]], "czcl"))
antibiotics[which(antibiotics$ab == "DAP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "DAP"), "abbreviations"][[1]], "dapt"))
antibiotics[which(antibiotics$ab == "DIC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "DIC"), "abbreviations"][[1]], "dicl"))
antibiotics[which(antibiotics$ab == "DOR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "DOR"), "abbreviations"][[1]], "dori"))
antibiotics[which(antibiotics$ab == "DOX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "DOX"), "abbreviations"][[1]], "doxy"))
antibiotics[which(antibiotics$ab == "ENX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "ENX"), "abbreviations"][[1]], "enox"))
antibiotics[which(antibiotics$ab == "ETP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "ETP"), "abbreviations"][[1]], "erta"))
antibiotics[which(antibiotics$ab == "ERY"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "ERY"), "abbreviations"][[1]], "eryt"))
antibiotics[which(antibiotics$ab == "PHE"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PHE"), "abbreviations"][[1]], "fene"))
antibiotics[which(antibiotics$ab == "PHN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PHN"), "abbreviations"][[1]], "fepe"))
antibiotics[which(antibiotics$ab == "FLE"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FLE"), "abbreviations"][[1]], "fler"))
antibiotics[which(antibiotics$ab == "FLU"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FLU"), "abbreviations"][[1]], "fluc"))
antibiotics[which(antibiotics$ab == "FLC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FLC"), "abbreviations"][[1]], "flux"))
antibiotics[which(antibiotics$ab == "FOS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FOS"), "abbreviations"][[1]], "fosf"))
antibiotics[which(antibiotics$ab == "FRM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FRM"), "abbreviations"][[1]], "fram"))
antibiotics[which(antibiotics$ab == "FUS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FUS"), "abbreviations"][[1]], "fusi"))
antibiotics[which(antibiotics$ab == "GAT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "GAT"), "abbreviations"][[1]], "gati"))
antibiotics[which(antibiotics$ab == "GEH"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "GEH"), "abbreviations"][[1]], "gehl"))
antibiotics[which(antibiotics$ab == "GEN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "GEN"), "abbreviations"][[1]], "gent"))
antibiotics[which(antibiotics$ab == "GRX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "GRX"), "abbreviations"][[1]], "grep"))
antibiotics[which(antibiotics$ab == "IPM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "IPM"), "abbreviations"][[1]], "imci"))
antibiotics[which(antibiotics$ab == "IPM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "IPM"), "abbreviations"][[1]], "imip"))
antibiotics[which(antibiotics$ab == "ISV"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "ISV"), "abbreviations"][[1]], "isav"))
antibiotics[which(antibiotics$ab == "ITR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "ITR"), "abbreviations"][[1]], "itra"))
antibiotics[which(antibiotics$ab == "KAH"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "KAH"), "abbreviations"][[1]], "kahl"))
antibiotics[which(antibiotics$ab == "KAN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "KAN"), "abbreviations"][[1]], "kana"))
antibiotics[which(antibiotics$ab == "KET"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "KET"), "abbreviations"][[1]], "keto"))
antibiotics[which(antibiotics$ab == "LVX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "LVX"), "abbreviations"][[1]], "levo"))
antibiotics[which(antibiotics$ab == "LIN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "LIN"), "abbreviations"][[1]], "linc"))
antibiotics[which(antibiotics$ab == "LNZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "LNZ"), "abbreviations"][[1]], "line"))
antibiotics[which(antibiotics$ab == "LOR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "LOR"), "abbreviations"][[1]], "lora"))
antibiotics[which(antibiotics$ab == "MEM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MEM"), "abbreviations"][[1]], "mero"))
antibiotics[which(antibiotics$ab == "MET"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MET"), "abbreviations"][[1]], "meti"))
antibiotics[which(antibiotics$ab == "MTR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MTR"), "abbreviations"][[1]], "metr"))
antibiotics[which(antibiotics$ab == "MEZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MEZ"), "abbreviations"][[1]], "mezl"))
antibiotics[which(antibiotics$ab == "MIF"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MIF"), "abbreviations"][[1]], "mica"))
antibiotics[which(antibiotics$ab == "MCZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MCZ"), "abbreviations"][[1]], "mico"))
antibiotics[which(antibiotics$ab == "MNO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MNO"), "abbreviations"][[1]], "mino"))
antibiotics[which(antibiotics$ab == "LTM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "LTM"), "abbreviations"][[1]], "moxa", "moxalactam"))
antibiotics[which(antibiotics$ab == "MFX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "MFX"), "abbreviations"][[1]], "moxi"))
antibiotics[which(antibiotics$ab == "NAL"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "NAL"), "abbreviations"][[1]], "nali"))
antibiotics[which(antibiotics$ab == "NEO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "NEO"), "abbreviations"][[1]], "neom"))
antibiotics[which(antibiotics$ab == "NET"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "NET"), "abbreviations"][[1]], "neti"))
antibiotics[which(antibiotics$ab == "NIT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "NIT"), "abbreviations"][[1]], "nitr"))
antibiotics[which(antibiotics$ab == "NOR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "NOR"), "abbreviations"][[1]], "norf"))
antibiotics[which(antibiotics$ab == "NYS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "NYS"), "abbreviations"][[1]], "nyst"))
antibiotics[which(antibiotics$ab == "OFX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "OFX"), "abbreviations"][[1]], "oflo"))
antibiotics[which(antibiotics$ab == "OXA"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "OXA"), "abbreviations"][[1]], "oxal"))
antibiotics[which(antibiotics$ab == "PEF"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PEF"), "abbreviations"][[1]], "pefl"))
antibiotics[which(antibiotics$ab == "PEN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PEN"), "abbreviations"][[1]], "peni"))
antibiotics[which(antibiotics$ab == "PIP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PIP"), "abbreviations"][[1]], "pipc"))
antibiotics[which(antibiotics$ab == "PPA"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PPA"), "abbreviations"][[1]], "pipz"))
antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]], "pita"))
antibiotics[which(antibiotics$ab == "PLB"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PLB"), "abbreviations"][[1]], "polb"))
antibiotics[which(antibiotics$ab == "POS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "POS"), "abbreviations"][[1]], "posa"))
antibiotics[which(antibiotics$ab == "PRI"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "PRI"), "abbreviations"][[1]], "pris"))
antibiotics[which(antibiotics$ab == "QDA"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "QDA"), "abbreviations"][[1]], "quda"))
antibiotics[which(antibiotics$ab == "RIF"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "RIF"), "abbreviations"][[1]], "rifa"))
antibiotics[which(antibiotics$ab == "RXT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "RXT"), "abbreviations"][[1]], "roxi"))
antibiotics[which(antibiotics$ab == "SMX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SMX"), "abbreviations"][[1]], "sfmx"))
antibiotics[which(antibiotics$ab == "SLF4"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SLF4"), "abbreviations"][[1]], "sfmz"))
antibiotics[which(antibiotics$ab == "SSS"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SSS"), "abbreviations"][[1]], "sfna"))
antibiotics[which(antibiotics$ab == "SLF"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SLF"), "abbreviations"][[1]], "sfsz"))
antibiotics[which(antibiotics$ab == "SPX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SPX"), "abbreviations"][[1]], "spar"))
antibiotics[which(antibiotics$ab == "SPT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SPT"), "abbreviations"][[1]], "spec"))
antibiotics[which(antibiotics$ab == "SPI"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SPI"), "abbreviations"][[1]], "spir"))
antibiotics[which(antibiotics$ab == "STH"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "STH"), "abbreviations"][[1]], "sthl"))
antibiotics[which(antibiotics$ab == "STR1"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "STR1"), "abbreviations"][[1]], "stre"))
antibiotics[which(antibiotics$ab == "TAZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TAZ"), "abbreviations"][[1]], "tazo"))
antibiotics[which(antibiotics$ab == "TEC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TEC"), "abbreviations"][[1]], "teic"))
antibiotics[which(antibiotics$ab == "TLT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TLT"), "abbreviations"][[1]], "teli"))
antibiotics[which(antibiotics$ab == "TMX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TMX"), "abbreviations"][[1]], "tema"))
antibiotics[which(antibiotics$ab == "TEM"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TEM"), "abbreviations"][[1]], "temo"))
antibiotics[which(antibiotics$ab == "TRB"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TRB"), "abbreviations"][[1]], "terb"))
antibiotics[which(antibiotics$ab == "TCY"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TCY"), "abbreviations"][[1]], "tetr"))
antibiotics[which(antibiotics$ab == "TIC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TIC"), "abbreviations"][[1]], "tica"))
antibiotics[which(antibiotics$ab == "TCC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TCC"), "abbreviations"][[1]], "ticl"))
antibiotics[which(antibiotics$ab == "TGC"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TGC"), "abbreviations"][[1]], "tige"))
antibiotics[which(antibiotics$ab == "TIN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TIN"), "abbreviations"][[1]], "tini"))
antibiotics[which(antibiotics$ab == "TOB"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TOB"), "abbreviations"][[1]], "tobr"))
antibiotics[which(antibiotics$ab == "TOH"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TOH"), "abbreviations"][[1]], "tohl"))
antibiotics[which(antibiotics$ab == "TMP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TMP"), "abbreviations"][[1]], "trim"))
antibiotics[which(antibiotics$ab == "TVA"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "TVA"), "abbreviations"][[1]], "trov"))
antibiotics[which(antibiotics$ab == "SLT4"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SLT4"), "abbreviations"][[1]], "trsm"))
antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "SXT"), "abbreviations"][[1]], "trsx"))
antibiotics[which(antibiotics$ab == "VAN"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "VAN"), "abbreviations"][[1]], "vanc"))
antibiotics[which(antibiotics$ab == "VOR"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "VOR"), "abbreviations"][[1]], "vori"))
antibiotics[which(antibiotics$ab == "FOS"), "synonyms"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "FOS"), "synonyms"][[1]], "Monuril")))
antibiotics[which(antibiotics$ab == "FOS"), "synonyms"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "FOS"), "synonyms"][[1]], "Monurol")))
antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "TZP"), "abbreviations"][[1]], "piptazo")))
antibiotics[which(antibiotics$ab == "RFP"), "abbreviations"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "RFP"), "abbreviations"][[1]], "RPT")))
antibiotics[which(antibiotics$ab == "RTP"), "abbreviations"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "RTP"), "abbreviations"][[1]], "RET")))
antibiotics[which(antibiotics$ab == "TYL1"), "abbreviations"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "TYL1"), "abbreviations"][[1]], "TVN")))
antibiotics <- antibiotics %>%
mutate(ab = as.character(ab)) %>%
rbind(antibiotics %>%
filter(ab == "GEH") %>%
mutate(
ab = "AMH",
name = "Amphotericin B-high",
abbreviations = list(c("amhl", "amfo b high", "ampho b high", "amphotericin high"))
)) %>%
rbind(antibiotics %>%
filter(ab == "GEH") %>%
mutate(
ab = "TOH",
name = "Tobramycin-high",
abbreviations = list(c("tohl", "tobra high", "tobramycin high"))
)) %>%
rbind(antibiotics %>%
filter(ab == "BUT") %>%
mutate(
ab = "CIX",
atc = "D01AE14",
name = "Ciclopirox",
group = "Antifungals/antimycotics",
atc_group1 = "Antifungals for topical use",
atc_group2 = "Other antifungals for topical use",
abbreviations = list(c("cipx"))
))
antibiotics[which(antibiotics$ab == "SSS"), "name"] <- "Sulfonamide"
# ESBL E-test codes:
antibiotics[which(antibiotics$ab == "CCV"), "abbreviations"][[1]] <- list(c("xtzl"))
antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]], "xtz", "cefta"))
antibiotics[which(antibiotics$ab == "CPC"), "abbreviations"][[1]] <- list(c("xpml"))
antibiotics[which(antibiotics$ab == "FEP"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "FEP"), "abbreviations"][[1]], "xpm"))
antibiotics[which(antibiotics$ab == "CTC"), "abbreviations"][[1]] <- list(c("xctl"))
antibiotics[which(antibiotics$ab == "CTX"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CTX"), "abbreviations"][[1]], "xct"))
# High level Gentamcin and Streptomycin
antibiotics[which(antibiotics$ab == "GEH"), "abbreviations"][[1]] <- list(c("gehl", "gentamicin high", "genta high", "gehi"))
antibiotics[which(antibiotics$ab == "STH"), "abbreviations"][[1]] <- list(c("sthl", "streptomycin high", "strepto high", "sthi"))
# add imi and "imipenem/cilastatine" to imipenem
antibiotics[which(antibiotics$ab == "IPM"), "abbreviations"][[1]] <- list(c("imip", "imi", "imp"))
antibiotics[which(antibiotics$ab == "IPM"), "synonyms"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "IPM"), "synonyms"][[1]], "imipenem/cilastatin")))
# add synonyms of ones not found
antibiotics[which(antibiotics$ab == "TZP"), "synonyms"][[1]] <- list(sort(c(antibiotics[which(antibiotics$ab == "TZP"), "synonyms"][[1]], "Tazocel", "tazocillin", "Tazocin", "Zosyn")))
antibiotics[which(antibiotics$ab == "COL"), "synonyms"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "COL"), "synonyms"][[1]], "Colisticin", "Polymyxin E", "Colimycin", "Coly-Mycin", "Totazina", "Colistimethate", "Promixin", "Colistimethate Sodium"))))
# remove incorrect synonyms from rifampicin (RIF) and add them to the combination rifampicin/isoniazid (RFI)
old_sym <- antibiotics[which(antibiotics$ab == "RIF"), "synonyms"][[1]]
old_sym <- old_sym[!old_sym %in% c("Rifinah", "Rimactazid")]
antibiotics[which(antibiotics$ab == "RIF"), "synonyms"][[1]] <- list(old_sym)
antibiotics[which(antibiotics$ab == "RFI"), "synonyms"][[1]] <- list(sort(c("Rifinah", "Rimactazid")))
# remove incorrect synonyms from sulfamethoxazole (SMX) and add them to the combination trimethoprim/sulfamethoxazole (SXT)
old_sym <- antibiotics[which(antibiotics$ab == "SMX"), "synonyms"][[1]]
old_sym <- old_sym[!old_sym %in% c("Cotrimoxazole", "Bactrimel")]
antibiotics[which(antibiotics$ab == "SMX"), "synonyms"][[1]] <- list(old_sym)
antibiotics[which(antibiotics$ab == "SXT"), "synonyms"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "COL"), "synonyms"][[1]], "Cotrimoxazole", "Bactrimel", "Septra", "Bactrim", "Cotrimazole"))))
# Fix penicillins
antibiotics[which(antibiotics$ab == "PEN"), "abbreviations"][[1]] <- list(c("bepe", "pg", "pen", "peni", "peni g", "penicillin", "penicillin g"))
antibiotics[which(antibiotics$ab == "PEN"), "name"] <- "Benzylpenicillin"
antibiotics[which(antibiotics$ab == "PHN"), "abbreviations"][[1]] <- list(c("fepe", "peni v", "pv", "penicillin v", "PNV"))
antibiotics <- subset(antibiotics, antibiotics$ab != "PNV")
# New DDDs
antibiotics[which(antibiotics$ab == "PEN"), "iv_ddd"] <- 3.6
antibiotics[which(antibiotics$ab == "PEN"), "iv_units"] <- "g"
## new ATC codes
# ceftaroline
antibiotics[which(antibiotics$ab == "CPT"), "atc"] <- "J01DI02"
# faropenem
antibiotics[which(antibiotics$ab == "FAR"), "atc"] <- "J01DI03"
# ceftobiprole
antibiotics[which(antibiotics$ab == "BPR"), "atc"] <- "J01DI01"
# ceftazidime / avibactam
antibiotics[which(antibiotics$ab == "CZA"), "atc"] <- "J01DD52"
antibiotics[which(antibiotics$ab == "CZA"), "cid"] <- 90643431
antibiotics[which(antibiotics$ab == "CZA"), "atc_group1"] <- "Other beta-lactam antibacterials"
antibiotics[which(antibiotics$ab == "CZA"), "atc_group2"] <- "Third-generation cephalosporins"
antibiotics[which(antibiotics$ab == "CZA"), "iv_ddd"] <- 6
antibiotics[which(antibiotics$ab == "CZA"), "iv_units"] <- "g"
antibiotics[which(antibiotics$ab == "CZA"), "synonyms"] <- list(c("Avycaz", "Zavicefta"))
# typo
antibiotics[which(antibiotics$ab == "RXT"), "name"] <- "Roxithromycin"
antibiotics[which(antibiotics$ab == "PEN"), "atc"] <- "J01CE01"
# WHONET cleanup
antibiotics[which(antibiotics$ab == "BCZ"), "name"] <- "Bicyclomycin"
antibiotics[which(antibiotics$ab == "CCL"), "name"] <- "Cefetecol"
antibiotics[which(antibiotics$ab == "ENV"), "name"] <- "Enviomycin"
antibiotics[which(antibiotics$ab == "KIT"), "name"] <- "Kitasamycin"
antibiotics[which(antibiotics$ab == "LSP"), "name"] <- "Linco-spectin"
antibiotics[which(antibiotics$ab == "MEC"), "name"] <- "Mecillinam"
antibiotics[which(antibiotics$ab == "PMR"), "name"] <- "Pimaricin"
antibiotics[which(antibiotics$ab == "BCZ"), "abbreviations"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "BCZ"), "abbreviations"][[1]], "Bicozamycin"))))
antibiotics[which(antibiotics$ab == "CCL"), "abbreviations"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "CCL"), "abbreviations"][[1]], "Cefcatacol"))))
antibiotics[which(antibiotics$ab == "ENV"), "abbreviations"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "ENV"), "abbreviations"][[1]], "Tuberactinomycin"))))
antibiotics[which(antibiotics$ab == "KIT"), "abbreviations"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "KIT"), "abbreviations"][[1]], "Leucomycin"))))
antibiotics[which(antibiotics$ab == "LSP"), "abbreviations"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "LSP"), "abbreviations"][[1]], "lincomycin/spectinomycin"))))
antibiotics[which(antibiotics$ab == "MEC"), "abbreviations"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "MEC"), "abbreviations"][[1]], "Amdinocillin"))))
antibiotics[which(antibiotics$ab == "PMR"), "abbreviations"][[1]] <- list(sort(unique(c(antibiotics[which(antibiotics$ab == "PMR"), "abbreviations"][[1]], "Natamycin"))))
# set cephalosporins groups for the ones that could not be determined automatically:
antibiotics <- antibiotics %>%
mutate(group = case_when(
name == "Cefcapene" ~ "Cephalosporins (3rd gen.)",
name == "Cefcapene pivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Cefditoren pivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Cefepime/clavulanic acid" ~ "Cephalosporins (4th gen.)",
name == "Cefepime/tazobactam" ~ "Cephalosporins (4th gen.)",
name == "Cefetamet pivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Cefetecol (Cefcatacol)" ~ "Cephalosporins (4th gen.)",
name == "Cefetrizole" ~ "Cephalosporins (unclassified gen.)",
name == "Cefoselis" ~ "Cephalosporins (4th gen.)",
name == "Cefotaxime/clavulanic acid" ~ "Cephalosporins (3rd gen.)",
name == "Cefotaxime/sulbactam" ~ "Cephalosporins (3rd gen.)",
name == "Cefotiam hexetil" ~ "Cephalosporins (3rd gen.)",
name == "Cefovecin" ~ "Cephalosporins (3rd gen.)",
name == "Cefozopran" ~ "Cephalosporins (4th gen.)",
name == "Cefpimizole" ~ "Cephalosporins (3rd gen.)",
name == "Cefpodoxime proxetil" ~ "Cephalosporins (3rd gen.)",
name == "Cefpodoxime/clavulanic acid" ~ "Cephalosporins (3rd gen.)",
name == "Cefquinome" ~ "Cephalosporins (4th gen.)",
name == "Cefsumide" ~ "Cephalosporins (unclassified gen.)",
name == "Ceftaroline" ~ "Cephalosporins (5th gen.)",
name == "Ceftaroline/avibactam" ~ "Cephalosporins (5th gen.)",
name == "Ceftazidime/avibactam" ~ "Cephalosporins (3rd gen.)",
name == "Cefteram" ~ "Cephalosporins (3rd gen.)",
name == "Cefteram pivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Ceftiofur" ~ "Cephalosporins (3rd gen.)",
name == "Ceftizoxime alapivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Ceftobiprole" ~ "Cephalosporins (5th gen.)",
name == "Ceftobiprole medocaril" ~ "Cephalosporins (5th gen.)",
name == "Ceftolozane/enzyme inhibitor" ~ "Cephalosporins (5th gen.)",
name == "Ceftolozane/tazobactam" ~ "Cephalosporins (5th gen.)",
name == "Cefuroxime axetil" ~ "Cephalosporins (2nd gen.)",
TRUE ~ group
))
antibiotics[which(antibiotics$ab %in% c("CYC", "LNZ", "THA", "TZD")), "group"] <- "Oxazolidinones"
# add efflux
effl <- antibiotics |>
filter(ab == "ACM") |>
mutate(ab = as.character("EFF"),
cid = NA_real_,
name = "Efflux",
group = "Other")
antibiotics <- antibiotics |>
mutate(ab = as.character(ab)) |>
bind_rows(effl)
class(antibiotics$ab) <- c("ab", "character")
antibiotics[which(antibiotics$ab == "EFF"), "abbreviations"][[1]] <- list(c("effflux pump"))
# add clindamycin inducible screening
clin <- antibiotics |>
filter(ab == "FOX1") |>
mutate(ab = as.character("CLI1"),
name = "Clindamycin inducible screening",
group = "Macrolides/lincosamides")
antibiotics <- antibiotics |>
mutate(ab = as.character(ab)) |>
bind_rows(clin)
class(antibiotics$ab) <- c("ab", "character")
antibiotics[which(antibiotics$ab == "CLI1"), "abbreviations"][[1]] <- list(c("clindamycin inducible", "clinda inducible", "clin inducible"))
# add pretomanid
antibiotics <- antibiotics %>%
mutate(ab = as.character(ab)) %>%
bind_rows(antibiotics %>%
mutate(ab = as.character(ab)) %>%
filter(ab == "SMF") %>%
mutate(
ab = "PMD",
atc = "J04AK08",
cid = 456199,
name = "Pretomanid",
abbreviations = list(""),
oral_ddd = NA_real_
))
# update ATC codes from WHOCC website -------------------------------------
# last time checked: 2024-02-22
library(rvest)
updated_atc <- as.list(antibiotics$atc)
get_atcs <- function(ab_name, type = "human") {
if (type == "human") {
url <- "https://atcddd.fhi.no/atc_ddd_index/"
} else if (type == "veterinary") {
url <- "https://atcddd.fhi.no/atcvet/atcvet_index/"
} else {
stop("invalid type")
}
ab_name <- gsub("/", " and ", tolower(ab_name), fixed = TRUE)
# we will do a search on their website, which means:
# go to the url
atc_tbl <- read_html(url) %>%
# get all forms
html_form() %>%
# get the second form (the first form is a global website form)
.[[2]] %>%
# set the name input box to our search parameter
html_form_set(name = ab_name) %>%
# hit Submit
html_form_submit() %>%
# read the resulting page
read_html() %>%
# retrieve the table on it
html_node("table") %>%
# transform it to an R data set
html_table(header = FALSE)
# and get the ATCs (first column) of only exact hits
unique(as.character(atc_tbl[which(tolower(atc_tbl[, 2, drop = TRUE]) == ab_name), 1, drop = TRUE]))
}
# this takes around 4 minutes (some are skipped and go faster)
for (i in seq_len(nrow(antibiotics))) {
message(percentage(i / nrow(antibiotics), digits = 1),
" - Downloading ", antibiotics$name[i],
appendLF = FALSE
)
atcs <- get_atcs(antibiotics$name[i], type = "human")
if (all(is.na(atcs))) {
atcs <- get_atcs(antibiotics$name[i], type = "veterinary")
}
if (length(atcs) > 0) {
updated_atc[[i]] <- atcs
message(" (", length(atcs), " results)")
# let the WHO server rest for a second - they might have a limitation on the queries per second
Sys.sleep(1)
} else {
message(" (skipping)")
}
}
antibiotics$atc <- updated_atc
# update DDDs from WHOCC website ------------------------------------------
# last time checked: 2024-02-22
ddd_oral <- rep(NA_real_, nrow(antibiotics))
ddd_oral_units <- rep(NA_character_, nrow(antibiotics))
ddd_iv <- rep(NA_real_, nrow(antibiotics))
ddd_iv_units <- rep(NA_character_, nrow(antibiotics))
progress <- progress_ticker(nrow(antibiotics))
for (i in seq_len(nrow(antibiotics))) {
on.exit(close(progress))
progress$tick()
atcs <- antibiotics$atc[[i]]
if (!all(is.na(atcs))) {
for (j in seq_len(length(atcs))) {
# oral
if (is.na(ddd_oral[i])) {
ddd_oral[i] <- atc_online_ddd(atcs[j], administration = "O")
if (!is.na(ddd_oral[i])) {
ddd_oral_units[i] <- atc_online_ddd_units(atcs[j], administration = "O")
}
}
# parenteral
if (is.na(ddd_iv[i])) {
ddd_iv[i] <- atc_online_ddd(atcs[j], administration = "P")
if (!is.na(ddd_iv[i])) {
ddd_iv_units[i] <- atc_online_ddd_units(atcs[j], administration = "P")
}
}
}
}
if (!is.na(ddd_oral[i]) | !is.na(ddd_iv[i])) {
# let the WHO server rest for 0.25 second - they might have a limitation on the queries per second
Sys.sleep(0.25)
}
}
antibiotics$oral_ddd <- ddd_oral
antibiotics$oral_units <- ddd_oral_units
antibiotics$iv_ddd <- ddd_iv
antibiotics$iv_units <- ddd_iv_units
# Wrap up -----------------------------------------------------------------
# set as data.frame again
antibiotics <- dataset_UTF8_to_ASCII(as.data.frame(antibiotics, stringsAsFactors = FALSE))
class(antibiotics$ab) <- c("ab", "character")
antibiotics <- dplyr::arrange(antibiotics, name)
# REFER TO data-raw/loinc.R FOR ADDING LOINC CODES
# make all abbreviations and synonyms lower case, unique and alphabetically sorted ----
for (i in 1:nrow(antibiotics)) {
abb <- as.character(sort(unique(tolower(antibiotics[i, "abbreviations", drop = TRUE][[1]]))))
abb <- abb[abb != "" & abb %unlike% ":"]
syn <- as.character(sort(unique(tolower(unname(unlist(antibiotics[i, "synonyms", drop = TRUE]))))))
syn <- gsub("[^a-z]", "", syn)
syn <- gsub(" +", " ", syn)
pharm_terms <- "(pa?ediatric|injection|oral|inhale|otic|sulfate|sulphate|sodium|base|anhydrous|anhydrate|stearate|syrup|natrium|hydrate|x?hcl|gsalt|vet[.]?)"
syn <- gsub(paste0(" ", pharm_terms, "$"), "", syn)
syn <- gsub(paste0("^", pharm_terms, " "), "", syn)
syn <- trimws(syn)
syn <- gsub(" [a-z]{1,3}$", "", syn, perl = TRUE)
syn <- trimws(syn)
syn <- syn[syn != "" & syn %unlike% ":" & !syn %in% tolower(antibiotics$name)]
syn <- unique(syn)
# special cases
if (antibiotics$ab[i] == "VAN") syn <- syn[syn %unlike% "^tei?ch?o"]
if (antibiotics$ab[i] == "CLR") syn <- syn[syn %unlike% "^ery"]
antibiotics[i, "abbreviations"][[1]] <- ifelse(length(abb) == 0, list(""), list(abb))
antibiotics[i, "synonyms"][[1]] <- ifelse(length(syn) == 0, list(""), list(syn))
if ("loinc" %in% colnames(antibiotics)) {
loinc <- as.character(sort(unique(tolower(antibiotics[i, "loinc", drop = TRUE][[1]]))))
loinc <- loinc[loinc != ""]
antibiotics[i, "loinc"][[1]] <- ifelse(length(loinc) == 0, list(""), list(loinc))
}
}
usethis::use_data(antibiotics, overwrite = TRUE, version = 2, compress = "xz")
rm(antibiotics)

View File

@ -0,0 +1,948 @@
# ==================================================================== #
# TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data #
# #
# SOURCE CODE: #
# https://github.com/msberends/AMR #
# #
# PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
# Journal of Statistical Software, 104(3), 1-31. #
# https://doi.org/10.18637/jss.v104.i03 #
# #
# Developed at the University of Groningen and the University Medical #
# Center Groningen in The Netherlands, in collaboration with many #
# colleagues from around the world, see our website. #
# #
# 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 the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
library(dplyr)
# got EARS-Net codes (= ECDC/WHO codes) from here:
# Installed WHONET 2019 software on Windows (http://www.whonet.org/software.html),
# opened C:\WHONET\Codes\WHONETCodes.mdb in MS Access
# and exported table 'DRGLST' to MS Excel
library(readxl)
DRGLST <- read_excel("DRGLST.xlsx")
abx <- DRGLST %>%
select(
ab = WHON5_CODE,
name = ANTIBIOTIC
) %>%
# remove the ones without WHONET code
filter(!is.na(ab)) %>%
distinct(name, .keep_all = TRUE) %>%
# add the ones without WHONET code
bind_rows(
DRGLST %>%
select(
ab = WHON5_CODE,
name = ANTIBIOTIC
) %>%
filter(is.na(ab)) %>%
distinct(name, .keep_all = TRUE)
# add new ab code later
) %>%
arrange(name)
# add old ATC codes
ab_old <- AMR::antimicrobials %>%
mutate(
official = gsub("( and |, )", "/", official),
abbr = tolower(paste(ifelse(is.na(abbr), "", abbr),
ifelse(is.na(certe), "", certe),
ifelse(is.na(umcg), "", umcg),
sep = "|"
))
)
for (i in 1:nrow(ab_old)) {
abbr <- ab_old[i, "abbr"]
abbr <- strsplit(abbr, "|", fixed = TRUE) %>%
unlist() %>%
unique()
abbr <- abbr[abbr != ""]
# print(abbr)
if (length(abbr) == 0) {
ab_old[i, "abbr"] <- NA_character_
} else {
ab_old[i, "abbr"] <- paste(abbr, collapse = "|")
}
}
# create reference data set: to be able to map ab to atc
abx_atc1 <- abx %>%
mutate(name_lower = tolower(name)) %>%
left_join(ab_old %>%
select(ears_net, atc), by = c(ab = "ears_net")) %>%
rename(atc1 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc2 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
mutate(official = gsub("f", "ph", official)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc3 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
mutate(official = gsub("t", "th", official)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc4 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
mutate(official = gsub("f", "ph", official)) %>%
mutate(official = gsub("t", "th", official)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc5 = atc) %>%
left_join(ab_old %>%
mutate(official = gsub(", combinations", "", official, fixed = TRUE)) %>%
mutate(official = gsub("f", "ph", official)) %>%
mutate(official = gsub("t", "th", official)) %>%
mutate(official = gsub("ine$", "in", official)) %>%
transmute(official = tolower(official), atc), by = c(name_lower = "official")) %>%
rename(atc6 = atc) %>%
mutate(atc = case_when(
!is.na(atc1) ~ atc1,
!is.na(atc2) ~ atc2,
!is.na(atc3) ~ atc3,
!is.na(atc4) ~ atc4,
!is.na(atc4) ~ atc5,
TRUE ~ atc6
)) %>%
distinct(ab, name, .keep_all = TRUE) %>%
select(ab, atc, name)
abx_atc2 <- ab_old %>%
filter(
!atc %in% abx_atc1$atc,
is.na(ears_net),
!is.na(atc_group1),
atc_group1 %unlike% ("virus|vaccin|viral|immun"),
official %unlike% "(combinations| with )"
) %>%
mutate(ab = NA_character_) %>%
as.data.frame(stringsAsFactors = FALSE) %>%
select(ab, atc, name = official)
abx2 <- bind_rows(abx_atc1, abx_atc2)
rm(abx_atc1)
rm(abx_atc2)
abx2$ab[is.na(abx2$ab)] <- toupper(abbreviate(
gsub(
"[/0-9-]",
" ",
abx2$name[is.na(abx2$ab)]
),
minlength = 3,
method = "left.kept",
strict = TRUE
))
n_distinct(abx2$ab)
abx2 <- abx2 %>% arrange(ab)
seqnr <- 0
# add follow up nrs
for (i in 2:nrow(abx2)) {
if (abx2[i, "ab", drop = TRUE] == abx2[i - 1, "ab", drop = TRUE]) {
seqnr <- seqnr + 1
abx2[i, "seqnr"] <- seqnr
} else {
seqnr <- 0
}
}
for (i in 2:nrow(abx2)) {
if (!is.na(abx2[i, "seqnr"])) {
abx2[i, "ab"] <- paste0(abx2[i, "ab", drop = TRUE], abx2[i, "seqnr", drop = TRUE])
}
}
abx2 <- abx2 %>%
select(-seqnr) %>%
arrange(name)
# everything unique??
nrow(abx2) == n_distinct(abx2$ab)
# get ATC properties
abx2 <- abx2 %>%
left_join(ab_old %>%
select(
atc, abbr, atc_group1, atc_group2,
oral_ddd, oral_units, iv_ddd, iv_units
))
abx2$abbr <- lapply(as.list(abx2$abbr), function(x) unlist(strsplit(x, "|", fixed = TRUE)))
# Update Compound IDs and Synonyms ----
# vector with official names, returns vector with CIDs
get_CID <- function(ab) {
CID <- rep(NA_integer_, length(ab))
p <- AMR:::progress_ticker(n = length(ab), min_time = 0)
for (i in 1:length(ab)) {
p$tick()
CID[i] <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/",
URLencode(ab[i], reserved = TRUE),
"/cids/TXT?name_type=complete"
),
showProgress = FALSE
)[[1]][1],
error = function(e) NA_integer_
)
if (is.na(CID[i])) {
# try with removing the text in brackets
CID[i] <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/",
URLencode(trimws(gsub("[(].*[)]", "", ab[i])), reserved = TRUE),
"/cids/TXT?name_type=complete"
),
showProgress = FALSE
)[[1]][1],
error = function(e) NA_integer_
)
}
if (is.na(CID[i])) {
# try match on word and take the lowest CID value (sorted)
ab[i] <- gsub("[^a-z0-9]+", " ", ab[i], ignore.case = TRUE)
CID[i] <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/",
URLencode(ab[i], reserved = TRUE),
"/cids/TXT?name_type=word"
),
showProgress = FALSE
)[[1]][1],
error = function(e) NA_integer_
)
}
Sys.sleep(0.1)
}
CID
}
# get CIDs (4-5 min)
CIDs <- get_CID(antimicrobials$name)
# take missing from previously found CIDs
CIDs[is.na(CIDs) & !is.na(antimicrobials$cid)] <- antimicrobials$cid[is.na(CIDs) & !is.na(antimicrobials$cid)]
# These could not be found:
antimicrobials[is.na(CIDs), ] %>% View()
# returns list with synonyms (brand names), with CIDs as names
get_synonyms <- function(CID, clean = TRUE) {
synonyms <- rep(NA_character_, length(CID))
p <- AMR:::progress_ticker(n = length(CID), min_time = 0)
for (i in 1:length(CID)) {
p$tick()
synonyms_txt <- ""
if (is.na(CID[i])) {
next
}
# we will now get the closest compounds with a 96% threshold
similar_cids <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/fastsimilarity_2d/cid/",
CID[i],
"/cids/TXT?Threshold=96&MaxRecords=5"
),
sep = "\n",
showProgress = FALSE
)[[1]],
error = function(e) NA_character_
)
# include the current CID of course
all_cids <- unique(c(CID[i], similar_cids))
# but leave out all CIDs that we have in our antimicrobials dataset to prevent duplication
all_cids <- all_cids[!all_cids %in% antimicrobials$cid[!is.na(antimicrobials$cid)]]
# for each one, we are getting the synonyms
current_syns <- character(0)
for (j in seq_len(length(all_cids))) {
synonyms_txt <- tryCatch(
data.table::fread(
paste0(
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/fastidentity/cid/",
all_cids[j],
"/synonyms/TXT"
),
sep = "\n",
showProgress = FALSE
)[[1]],
error = function(e) NA_character_
)
Sys.sleep(0.05)
if (clean == TRUE) {
# remove text between brackets
synonyms_txt <- trimws(gsub(
"[(].*[)]", "",
gsub(
"[[].*[]]", "",
gsub(
"[(].*[]]", "",
gsub("[[].*[)]", "", synonyms_txt)
)
)
))
synonyms_txt <- gsub("Co-", "Co", synonyms_txt, fixed = TRUE)
synonyms_txt <- gsub(" ?(mono)?sodium ?", "", ignore.case = TRUE, synonyms_txt)
synonyms_txt <- gsub(" ?(injection|pediatric) ?", "", ignore.case = TRUE, synonyms_txt)
# only length 6 to 20 and no txt with reading marks or numbers and must start with capital letter (= brand)
synonyms_txt <- synonyms_txt[nchar(synonyms_txt) %in% c(5:20) &
!grepl("[-&{},_0-9/:]", synonyms_txt) &
grepl("^[A-Z]", synonyms_txt, ignore.case = FALSE)]
synonyms_txt <- unlist(strsplit(synonyms_txt, ";", fixed = TRUE))
}
current_syns <- c(current_syns, synonyms_txt)
}
current_syns <- unique(trimws(current_syns[tolower(current_syns) %in% unique(tolower(current_syns))]))
synonyms[i] <- list(sort(current_syns))
}
names(synonyms) <- CID
synonyms
}
# get brand names from PubChem (3-4 min)
synonyms <- get_synonyms(CIDs)
synonyms.bak <- synonyms
synonyms <- synonyms.bak
# add existing ones (will be cleaned later)
for (i in seq_len(length(synonyms))) {
old <- unname(unlist(AMR::antimicrobials[i, "synonyms", drop = TRUE]))
synonyms[[i]] <- c(unname(synonyms[[i]]), old)
}
antimicrobials$synonyms <- synonyms
stop("remember to remove co-trimoxazole as synonyms from SMX (Sulfamethoxazole), so it only exists in SXT!")
sulfa <- antimicrobials[which(antimicrobials$ab == "SMX"), "synonyms", drop = TRUE][[1]]
cotrim <- antimicrobials[which(antimicrobials$ab == "SXT"), "synonyms", drop = TRUE][[1]]
# 2024-10-06 not the case anymore, no overlapping names: sulfa[sulfa %in% cotrim]
sulfa <- sulfa[!sulfa %in% cotrim]
antimicrobials[which(antimicrobials$ab == "SMX"), "synonyms"][[1]][[1]] <- sulfa
# now go to end of this file
# -----
# add them to data set
antimicrobials <- abx2 %>%
left_join(DRGLST %>%
select(ab = WHON5_CODE, CLASS, SUBCLASS) %>%
distinct(ab, .keep_all = TRUE), by = "ab") %>%
transmute(ab,
atc,
cid = CIDs,
# no capital after a slash: Ampicillin/Sulbactam -> Ampicillin/sulbactam
name = name %>%
gsub("([/-])([A-Z])", "\\1\\L\\2", ., perl = TRUE) %>%
gsub("edta", "EDTA", ., ignore.case = TRUE),
group = case_when(
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "am(ph|f)enicol" ~ "Amphenicols",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "aminoglycoside" ~ "Aminoglycosides",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "carbapenem" | name %like% "(imipenem|meropenem)" ~ "Carbapenems",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "First-generation cephalosporin" ~ "Cephalosporins (1st gen.)",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "Second-generation cephalosporin" ~ "Cephalosporins (2nd gen.)",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "Third-generation cephalosporin" ~ "Cephalosporins (3rd gen.)",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "Fourth-generation cephalosporin" ~ "Cephalosporins (4th gen.)",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "(tuberculosis|mycobacter)" ~ "Antimycobacterials",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "cephalosporin" ~ "Cephalosporins",
name %like% "^Ce" & is.na(atc_group1) & paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "beta-?lactam" ~ "Cephalosporins",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "(beta-?lactam|penicillin)" ~ "Beta-lactams/penicillins",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "quinolone" ~ "Quinolones",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "glycopeptide" ~ "Glycopeptides",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "macrolide" ~ "Macrolides/lincosamides",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "tetracycline" ~ "Tetracyclines",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "trimethoprim" ~ "Trimethoprims",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "polymyxin" ~ "Polymyxins",
paste(atc_group1, atc_group2, CLASS, SUBCLASS) %like% "(fungal|mycot)" ~ "Antifungals/antimycotics",
TRUE ~ "Other antibacterials"
),
atc_group1, atc_group2,
abbreviations = unname(abbr),
synonyms = unname(synonyms),
oral_ddd, oral_units,
iv_ddd, iv_units
) %>%
as.data.frame(stringsAsFactors = FALSE)
# some exceptions
antimicrobials[which(antimicrobials$ab == "DOX"), "abbreviations"][[1]] <- list(c("dox", "doxy"))
antimicrobials[which(antimicrobials$ab == "FLC"), "abbreviations"][[1]] <- list(c("clox"))
antimicrobials[which(antimicrobials$ab == "CEC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CEC"), "abbreviations"][[1]], "CFC")) # cefaclor old WHONET4 code
antimicrobials[which(antimicrobials$ab == "AMX"), "synonyms"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "AMX"), "synonyms"][[1]], "Amoxy")))
# 'Polymixin B' (POL) and 'Polymyxin B' (PLB) both exist, so:
antimicrobials[which(antimicrobials$ab == "PLB"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PLB"), "abbreviations"][[1]], "POL", "Polymixin", "Polymixin B", "Poly B"))
antimicrobials <- filter(antimicrobials, ab != "POL")
# 'Latamoxef' (LTM) and 'Moxalactam (Latamoxef)' (MOX) both exist, so:
antimicrobials[which(antimicrobials$ab == "LTM"), "abbreviations"][[1]] <- list(c("MOX", "moxa"))
antimicrobials <- filter(antimicrobials, ab != "MOX")
# RFP and RFP1 (the J0 one) both mean 'rifapentine', although 'rifp' is not recognised, so:
antimicrobials <- filter(antimicrobials, ab != "RFP")
antimicrobials[which(antimicrobials$ab == "RFP1"), "ab"] <- "RFP"
antimicrobials[which(antimicrobials$ab == "RFP"), "abbreviations"][[1]] <- list(c("rifp"))
# Rifampicin is better known as a drug than Rifampin (Rifampin is still listed as a brand name), so:
antimicrobials[which(antimicrobials$ab == "RIF"), "name"] <- "Rifampicin"
# PME and PVM1 (the J0 one) both mean 'Pivmecillinam', so:
antimicrobials <- filter(antimicrobials, ab != "PME")
antimicrobials[which(antimicrobials$ab == "PVM1"), "ab"] <- "PME"
# Remove Sinecatechins
antimicrobials <- filter(antimicrobials, ab != "SNC")
# GLIMS codes
antimicrobials[which(antimicrobials$ab == as.ab("cefuroxim")), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == as.ab("cefuroxim")), "abbreviations"][[1]], "cfrx"))
antimicrobials[which(antimicrobials$ab == as.ab("cefotaxim")), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == as.ab("cefotaxim")), "abbreviations"][[1]], "cftx"))
antimicrobials[which(antimicrobials$ab == as.ab("ceftazidime")), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == as.ab("ceftazidime")), "abbreviations"][[1]], "cftz"))
antimicrobials[which(antimicrobials$ab == as.ab("cefepime")), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == as.ab("cefepime")), "abbreviations"][[1]], "cfpi"))
antimicrobials[which(antimicrobials$ab == as.ab("cefoxitin")), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == as.ab("cefoxitin")), "abbreviations"][[1]], "cfxt"))
# Add cefoxitin screening
class(antimicrobials$ab) <- "character"
antimicrobials <- rbind(antimicrobials, data.frame(
ab = "FOX1", atc = NA, cid = NA,
name = "Cefoxitin screening",
group = "Cephalosporins (2nd gen.)", atc_group1 = NA, atc_group2 = NA,
abbreviations = "cfsc", synonyms = NA,
oral_ddd = NA, oral_units = NA, iv_ddd = NA, iv_units = NA,
loinc = NA,
stringsAsFactors = FALSE
))
# More GLIMS codes
antimicrobials[which(antimicrobials$ab == "AMB"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AMB"), "abbreviations"][[1]], "amf"))
antimicrobials[which(antimicrobials$ab == "CAZ"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CAZ"), "abbreviations"][[1]], "cftz"))
antimicrobials[which(antimicrobials$ab == "COL"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "COL"), "abbreviations"][[1]], "cst"))
antimicrobials[which(antimicrobials$ab == "CRO"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CRO"), "abbreviations"][[1]], "cftr"))
antimicrobials[which(antimicrobials$ab == "CTX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CTX"), "abbreviations"][[1]], "cftx"))
antimicrobials[which(antimicrobials$ab == "CXM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CXM"), "abbreviations"][[1]], "cfrx"))
antimicrobials[which(antimicrobials$ab == "CZO"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CZO"), "abbreviations"][[1]], "cfzl"))
antimicrobials[which(antimicrobials$ab == "FCT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FCT"), "abbreviations"][[1]], "fcu"))
antimicrobials[which(antimicrobials$ab == "FCT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FCT"), "abbreviations"][[1]], "fluy"))
antimicrobials[which(antimicrobials$ab == "FLU"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FLU"), "abbreviations"][[1]], "flz"))
antimicrobials[which(antimicrobials$ab == "FOS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FOS"), "abbreviations"][[1]], "fof"))
antimicrobials[which(antimicrobials$ab == "FOX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FOX"), "abbreviations"][[1]], "cfxt"))
antimicrobials[which(antimicrobials$ab == "FUS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FUS"), "abbreviations"][[1]], "fa"))
antimicrobials[which(antimicrobials$ab == "GEH"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "GEH"), "abbreviations"][[1]], "g_h"))
antimicrobials[which(antimicrobials$ab == "KAH"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "KAH"), "abbreviations"][[1]], "k_h"))
antimicrobials[which(antimicrobials$ab == "KET"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "KET"), "abbreviations"][[1]], "ktc"))
antimicrobials[which(antimicrobials$ab == "PIP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PIP"), "abbreviations"][[1]], "pipc"))
antimicrobials[which(antimicrobials$ab == "PIP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PIP"), "abbreviations"][[1]], "PIPC"))
antimicrobials[which(antimicrobials$ab == "SPX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SPX"), "abbreviations"][[1]], "spa"))
antimicrobials[which(antimicrobials$ab == "STH"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "STH"), "abbreviations"][[1]], "s_h"))
antimicrobials[which(antimicrobials$ab == "STR1"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "STR1"), "abbreviations"][[1]], "stm"))
antimicrobials[which(antimicrobials$ab == "SXT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SXT"), "abbreviations"][[1]], "COTRIM"))
antimicrobials[which(antimicrobials$ab == "SXT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SXT"), "abbreviations"][[1]], "trsx"))
antimicrobials[which(antimicrobials$ab == "TGC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TGC"), "abbreviations"][[1]], "tig"))
antimicrobials[which(antimicrobials$ab == "TMP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TMP"), "abbreviations"][[1]], "tri"))
antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]], "PIPTAZ"))
antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]], "pit"))
antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]], "pita"))
antimicrobials[which(antimicrobials$ab == "VOR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "VOR"), "abbreviations"][[1]], "vrc"))
# official RIVM codes (Dutch National Health Institute)
# https://www.rivm.nl/sites/default/files/2019-09/Bijlage_4_Lijst_antibiotica%202020%201.0.pdf
antimicrobials[which(antimicrobials$ab == "FCT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FCT"), "abbreviations"][[1]], "5flc"))
antimicrobials[which(antimicrobials$ab == "AMC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AMC"), "abbreviations"][[1]], "amcl"))
antimicrobials[which(antimicrobials$ab == "AMB"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AMB"), "abbreviations"][[1]], "amfb"))
antimicrobials[which(antimicrobials$ab == "AMH"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AMH"), "abbreviations"][[1]], "amhl"))
antimicrobials[which(antimicrobials$ab == "AMK"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AMK"), "abbreviations"][[1]], "amik"))
antimicrobials[which(antimicrobials$ab == "AMX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AMX"), "abbreviations"][[1]], "amox"))
antimicrobials[which(antimicrobials$ab == "AMP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AMP"), "abbreviations"][[1]], "ampi"))
antimicrobials[which(antimicrobials$ab == "SAM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SAM"), "abbreviations"][[1]], "amsu"))
antimicrobials[which(antimicrobials$ab == "ANI"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "ANI"), "abbreviations"][[1]], "anid"))
antimicrobials[which(antimicrobials$ab == "SAM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SAM"), "abbreviations"][[1]], "apsu"))
antimicrobials[which(antimicrobials$ab == "AZM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AZM"), "abbreviations"][[1]], "azit"))
antimicrobials[which(antimicrobials$ab == "AZL"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "AZL"), "abbreviations"][[1]], "azlo"))
antimicrobials[which(antimicrobials$ab == "ATM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "ATM"), "abbreviations"][[1]], "aztr"))
antimicrobials[which(antimicrobials$ab == "PNV"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PNV"), "abbreviations"][[1]], "bepe"))
antimicrobials[which(antimicrobials$ab == "CAP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CAP"), "abbreviations"][[1]], "capr"))
antimicrobials[which(antimicrobials$ab == "CRB"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CRB"), "abbreviations"][[1]], "carb"))
antimicrobials[which(antimicrobials$ab == "CAS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CAS"), "abbreviations"][[1]], "casp"))
antimicrobials[which(antimicrobials$ab == "CDC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CDC"), "abbreviations"][[1]], "cecl"))
antimicrobials[which(antimicrobials$ab == "CXA"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CXA"), "abbreviations"][[1]], "cfax"))
antimicrobials[which(antimicrobials$ab == "CTB"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CTB"), "abbreviations"][[1]], "cfbu"))
antimicrobials[which(antimicrobials$ab == "CEC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CEC"), "abbreviations"][[1]], "cfcl"))
antimicrobials[which(antimicrobials$ab == "CFR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CFR"), "abbreviations"][[1]], "cfdx"))
antimicrobials[which(antimicrobials$ab == "CEP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CEP"), "abbreviations"][[1]], "cflt"))
antimicrobials[which(antimicrobials$ab == "LEX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "LEX"), "abbreviations"][[1]], "cflx"))
antimicrobials[which(antimicrobials$ab == "MAN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MAN"), "abbreviations"][[1]], "cfmn"))
antimicrobials[which(antimicrobials$ab == "CPD"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CPD"), "abbreviations"][[1]], "cfpd"))
antimicrobials[which(antimicrobials$ab == "FEP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FEP"), "abbreviations"][[1]], "cfpi"))
antimicrobials[which(antimicrobials$ab == "CPO"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CPO"), "abbreviations"][[1]], "cfpr"))
antimicrobials[which(antimicrobials$ab == "CFP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CFP"), "abbreviations"][[1]], "cfpz"))
antimicrobials[which(antimicrobials$ab == "CED"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CED"), "abbreviations"][[1]], "cfrd"))
antimicrobials[which(antimicrobials$ab == "CPT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CPT"), "abbreviations"][[1]], "cfro"))
antimicrobials[which(antimicrobials$ab == "CXM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CXM"), "abbreviations"][[1]], "cfrx"))
antimicrobials[which(antimicrobials$ab == "CFS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CFS"), "abbreviations"][[1]], "cfsl"))
antimicrobials[which(antimicrobials$ab == "CRO"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CRO"), "abbreviations"][[1]], "cftr"))
antimicrobials[which(antimicrobials$ab == "CTT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CTT"), "abbreviations"][[1]], "cftt"))
antimicrobials[which(antimicrobials$ab == "CTX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CTX"), "abbreviations"][[1]], "cftx"))
antimicrobials[which(antimicrobials$ab == "CAZ"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CAZ"), "abbreviations"][[1]], "cftz"))
antimicrobials[which(antimicrobials$ab == "CFM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CFM"), "abbreviations"][[1]], "cfxm"))
antimicrobials[which(antimicrobials$ab == "FOX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FOX"), "abbreviations"][[1]], "cfxt"))
antimicrobials[which(antimicrobials$ab == "CZA"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CZA"), "abbreviations"][[1]], "cfav"))
antimicrobials[which(antimicrobials$ab == "CZO"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CZO"), "abbreviations"][[1]], "cfzl"))
antimicrobials[which(antimicrobials$ab == "CZX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CZX"), "abbreviations"][[1]], "cfzx"))
antimicrobials[which(antimicrobials$ab == "CHL"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CHL"), "abbreviations"][[1]], "chlo"))
antimicrobials[which(antimicrobials$ab == "CPC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CPC"), "abbreviations"][[1]], "cicl"))
antimicrobials[which(antimicrobials$ab == "CIN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CIN"), "abbreviations"][[1]], "cino"))
antimicrobials[which(antimicrobials$ab == "CIP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CIP"), "abbreviations"][[1]], "cipr"))
antimicrobials[which(antimicrobials$ab == "CIX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CIX"), "abbreviations"][[1]], "cipx"))
antimicrobials[which(antimicrobials$ab == "CLR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CLR"), "abbreviations"][[1]], "clar"))
antimicrobials[which(antimicrobials$ab == "CLI"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CLI"), "abbreviations"][[1]], "clin"))
antimicrobials[which(antimicrobials$ab == "CTR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CTR"), "abbreviations"][[1]], "clot"))
antimicrobials[which(antimicrobials$ab == "CLO"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CLO"), "abbreviations"][[1]], "clox"))
antimicrobials[which(antimicrobials$ab == "COL"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "COL"), "abbreviations"][[1]], "coli"))
antimicrobials[which(antimicrobials$ab == "CTC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CTC"), "abbreviations"][[1]], "cxcl"))
antimicrobials[which(antimicrobials$ab == "CYC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CYC"), "abbreviations"][[1]], "cycl"))
antimicrobials[which(antimicrobials$ab == "CCV"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CCV"), "abbreviations"][[1]], "czcl"))
antimicrobials[which(antimicrobials$ab == "DAP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "DAP"), "abbreviations"][[1]], "dapt"))
antimicrobials[which(antimicrobials$ab == "DIC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "DIC"), "abbreviations"][[1]], "dicl"))
antimicrobials[which(antimicrobials$ab == "DOR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "DOR"), "abbreviations"][[1]], "dori"))
antimicrobials[which(antimicrobials$ab == "DOX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "DOX"), "abbreviations"][[1]], "doxy"))
antimicrobials[which(antimicrobials$ab == "ENX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "ENX"), "abbreviations"][[1]], "enox"))
antimicrobials[which(antimicrobials$ab == "ETP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "ETP"), "abbreviations"][[1]], "erta"))
antimicrobials[which(antimicrobials$ab == "ERY"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "ERY"), "abbreviations"][[1]], "eryt"))
antimicrobials[which(antimicrobials$ab == "PHE"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PHE"), "abbreviations"][[1]], "fene"))
antimicrobials[which(antimicrobials$ab == "PHN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PHN"), "abbreviations"][[1]], "fepe"))
antimicrobials[which(antimicrobials$ab == "FLE"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FLE"), "abbreviations"][[1]], "fler"))
antimicrobials[which(antimicrobials$ab == "FLU"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FLU"), "abbreviations"][[1]], "fluc"))
antimicrobials[which(antimicrobials$ab == "FLC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FLC"), "abbreviations"][[1]], "flux"))
antimicrobials[which(antimicrobials$ab == "FOS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FOS"), "abbreviations"][[1]], "fosf"))
antimicrobials[which(antimicrobials$ab == "FRM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FRM"), "abbreviations"][[1]], "fram"))
antimicrobials[which(antimicrobials$ab == "FUS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FUS"), "abbreviations"][[1]], "fusi"))
antimicrobials[which(antimicrobials$ab == "GAT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "GAT"), "abbreviations"][[1]], "gati"))
antimicrobials[which(antimicrobials$ab == "GEH"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "GEH"), "abbreviations"][[1]], "gehl"))
antimicrobials[which(antimicrobials$ab == "GEN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "GEN"), "abbreviations"][[1]], "gent"))
antimicrobials[which(antimicrobials$ab == "GRX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "GRX"), "abbreviations"][[1]], "grep"))
antimicrobials[which(antimicrobials$ab == "IPM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "IPM"), "abbreviations"][[1]], "imci"))
antimicrobials[which(antimicrobials$ab == "IPM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "IPM"), "abbreviations"][[1]], "imip"))
antimicrobials[which(antimicrobials$ab == "ISV"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "ISV"), "abbreviations"][[1]], "isav"))
antimicrobials[which(antimicrobials$ab == "ITR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "ITR"), "abbreviations"][[1]], "itra"))
antimicrobials[which(antimicrobials$ab == "KAH"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "KAH"), "abbreviations"][[1]], "kahl"))
antimicrobials[which(antimicrobials$ab == "KAN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "KAN"), "abbreviations"][[1]], "kana"))
antimicrobials[which(antimicrobials$ab == "KET"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "KET"), "abbreviations"][[1]], "keto"))
antimicrobials[which(antimicrobials$ab == "LVX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "LVX"), "abbreviations"][[1]], "levo"))
antimicrobials[which(antimicrobials$ab == "LIN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "LIN"), "abbreviations"][[1]], "linc"))
antimicrobials[which(antimicrobials$ab == "LNZ"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "LNZ"), "abbreviations"][[1]], "line"))
antimicrobials[which(antimicrobials$ab == "LOR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "LOR"), "abbreviations"][[1]], "lora"))
antimicrobials[which(antimicrobials$ab == "MEM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MEM"), "abbreviations"][[1]], "mero"))
antimicrobials[which(antimicrobials$ab == "MET"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MET"), "abbreviations"][[1]], "meti"))
antimicrobials[which(antimicrobials$ab == "MTR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MTR"), "abbreviations"][[1]], "metr"))
antimicrobials[which(antimicrobials$ab == "MEZ"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MEZ"), "abbreviations"][[1]], "mezl"))
antimicrobials[which(antimicrobials$ab == "MIF"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MIF"), "abbreviations"][[1]], "mica"))
antimicrobials[which(antimicrobials$ab == "MCZ"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MCZ"), "abbreviations"][[1]], "mico"))
antimicrobials[which(antimicrobials$ab == "MNO"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MNO"), "abbreviations"][[1]], "mino"))
antimicrobials[which(antimicrobials$ab == "LTM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "LTM"), "abbreviations"][[1]], "moxa", "moxalactam"))
antimicrobials[which(antimicrobials$ab == "MFX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "MFX"), "abbreviations"][[1]], "moxi"))
antimicrobials[which(antimicrobials$ab == "NAL"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "NAL"), "abbreviations"][[1]], "nali"))
antimicrobials[which(antimicrobials$ab == "NEO"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "NEO"), "abbreviations"][[1]], "neom"))
antimicrobials[which(antimicrobials$ab == "NET"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "NET"), "abbreviations"][[1]], "neti"))
antimicrobials[which(antimicrobials$ab == "NIT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "NIT"), "abbreviations"][[1]], "nitr"))
antimicrobials[which(antimicrobials$ab == "NOR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "NOR"), "abbreviations"][[1]], "norf"))
antimicrobials[which(antimicrobials$ab == "NYS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "NYS"), "abbreviations"][[1]], "nyst"))
antimicrobials[which(antimicrobials$ab == "OFX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "OFX"), "abbreviations"][[1]], "oflo"))
antimicrobials[which(antimicrobials$ab == "OXA"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "OXA"), "abbreviations"][[1]], "oxal"))
antimicrobials[which(antimicrobials$ab == "PEF"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PEF"), "abbreviations"][[1]], "pefl"))
antimicrobials[which(antimicrobials$ab == "PEN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PEN"), "abbreviations"][[1]], "peni"))
antimicrobials[which(antimicrobials$ab == "PIP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PIP"), "abbreviations"][[1]], "pipc"))
antimicrobials[which(antimicrobials$ab == "PPA"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PPA"), "abbreviations"][[1]], "pipz"))
antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]], "pita"))
antimicrobials[which(antimicrobials$ab == "PLB"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PLB"), "abbreviations"][[1]], "polb"))
antimicrobials[which(antimicrobials$ab == "POS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "POS"), "abbreviations"][[1]], "posa"))
antimicrobials[which(antimicrobials$ab == "PRI"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "PRI"), "abbreviations"][[1]], "pris"))
antimicrobials[which(antimicrobials$ab == "QDA"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "QDA"), "abbreviations"][[1]], "quda"))
antimicrobials[which(antimicrobials$ab == "RIF"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "RIF"), "abbreviations"][[1]], "rifa"))
antimicrobials[which(antimicrobials$ab == "RXT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "RXT"), "abbreviations"][[1]], "roxi"))
antimicrobials[which(antimicrobials$ab == "SMX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SMX"), "abbreviations"][[1]], "sfmx"))
antimicrobials[which(antimicrobials$ab == "SLF4"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SLF4"), "abbreviations"][[1]], "sfmz"))
antimicrobials[which(antimicrobials$ab == "SSS"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SSS"), "abbreviations"][[1]], "sfna"))
antimicrobials[which(antimicrobials$ab == "SLF"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SLF"), "abbreviations"][[1]], "sfsz"))
antimicrobials[which(antimicrobials$ab == "SPX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SPX"), "abbreviations"][[1]], "spar"))
antimicrobials[which(antimicrobials$ab == "SPT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SPT"), "abbreviations"][[1]], "spec"))
antimicrobials[which(antimicrobials$ab == "SPI"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SPI"), "abbreviations"][[1]], "spir"))
antimicrobials[which(antimicrobials$ab == "STH"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "STH"), "abbreviations"][[1]], "sthl"))
antimicrobials[which(antimicrobials$ab == "STR1"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "STR1"), "abbreviations"][[1]], "stre"))
antimicrobials[which(antimicrobials$ab == "TAZ"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TAZ"), "abbreviations"][[1]], "tazo"))
antimicrobials[which(antimicrobials$ab == "TEC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TEC"), "abbreviations"][[1]], "teic"))
antimicrobials[which(antimicrobials$ab == "TLT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TLT"), "abbreviations"][[1]], "teli"))
antimicrobials[which(antimicrobials$ab == "TMX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TMX"), "abbreviations"][[1]], "tema"))
antimicrobials[which(antimicrobials$ab == "TEM"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TEM"), "abbreviations"][[1]], "temo"))
antimicrobials[which(antimicrobials$ab == "TRB"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TRB"), "abbreviations"][[1]], "terb"))
antimicrobials[which(antimicrobials$ab == "TCY"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TCY"), "abbreviations"][[1]], "tetr"))
antimicrobials[which(antimicrobials$ab == "TIC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TIC"), "abbreviations"][[1]], "tica"))
antimicrobials[which(antimicrobials$ab == "TCC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TCC"), "abbreviations"][[1]], "ticl"))
antimicrobials[which(antimicrobials$ab == "TGC"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TGC"), "abbreviations"][[1]], "tige"))
antimicrobials[which(antimicrobials$ab == "TIN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TIN"), "abbreviations"][[1]], "tini"))
antimicrobials[which(antimicrobials$ab == "TOB"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TOB"), "abbreviations"][[1]], "tobr"))
antimicrobials[which(antimicrobials$ab == "TOH"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TOH"), "abbreviations"][[1]], "tohl"))
antimicrobials[which(antimicrobials$ab == "TMP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TMP"), "abbreviations"][[1]], "trim"))
antimicrobials[which(antimicrobials$ab == "TVA"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "TVA"), "abbreviations"][[1]], "trov"))
antimicrobials[which(antimicrobials$ab == "SLT4"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SLT4"), "abbreviations"][[1]], "trsm"))
antimicrobials[which(antimicrobials$ab == "SXT"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "SXT"), "abbreviations"][[1]], "trsx"))
antimicrobials[which(antimicrobials$ab == "VAN"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "VAN"), "abbreviations"][[1]], "vanc"))
antimicrobials[which(antimicrobials$ab == "VOR"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "VOR"), "abbreviations"][[1]], "vori"))
antimicrobials[which(antimicrobials$ab == "FOS"), "synonyms"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "FOS"), "synonyms"][[1]], "Monuril")))
antimicrobials[which(antimicrobials$ab == "FOS"), "synonyms"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "FOS"), "synonyms"][[1]], "Monurol")))
antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "TZP"), "abbreviations"][[1]], "piptazo")))
antimicrobials[which(antimicrobials$ab == "RFP"), "abbreviations"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "RFP"), "abbreviations"][[1]], "RPT")))
antimicrobials[which(antimicrobials$ab == "RTP"), "abbreviations"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "RTP"), "abbreviations"][[1]], "RET")))
antimicrobials[which(antimicrobials$ab == "TYL1"), "abbreviations"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "TYL1"), "abbreviations"][[1]], "TVN")))
antimicrobials <- antimicrobials %>%
mutate(ab = as.character(ab)) %>%
rbind(antimicrobials %>%
filter(ab == "GEH") %>%
mutate(
ab = "AMH",
name = "Amphotericin B-high",
abbreviations = list(c("amhl", "amfo b high", "ampho b high", "amphotericin high"))
)) %>%
rbind(antimicrobials %>%
filter(ab == "GEH") %>%
mutate(
ab = "TOH",
name = "Tobramycin-high",
abbreviations = list(c("tohl", "tobra high", "tobramycin high"))
)) %>%
rbind(antimicrobials %>%
filter(ab == "BUT") %>%
mutate(
ab = "CIX",
atc = "D01AE14",
name = "Ciclopirox",
group = "Antifungals/antimycotics",
atc_group1 = "Antifungals for topical use",
atc_group2 = "Other antifungals for topical use",
abbreviations = list(c("cipx"))
))
antimicrobials[which(antimicrobials$ab == "SSS"), "name"] <- "Sulfonamide"
# ESBL E-test codes:
antimicrobials[which(antimicrobials$ab == "CCV"), "abbreviations"][[1]] <- list(c("xtzl"))
antimicrobials[which(antimicrobials$ab == "CAZ"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CAZ"), "abbreviations"][[1]], "xtz", "cefta"))
antimicrobials[which(antimicrobials$ab == "CPC"), "abbreviations"][[1]] <- list(c("xpml"))
antimicrobials[which(antimicrobials$ab == "FEP"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "FEP"), "abbreviations"][[1]], "xpm"))
antimicrobials[which(antimicrobials$ab == "CTC"), "abbreviations"][[1]] <- list(c("xctl"))
antimicrobials[which(antimicrobials$ab == "CTX"), "abbreviations"][[1]] <- list(c(antimicrobials[which(antimicrobials$ab == "CTX"), "abbreviations"][[1]], "xct"))
# High level Gentamcin and Streptomycin
antimicrobials[which(antimicrobials$ab == "GEH"), "abbreviations"][[1]] <- list(c("gehl", "gentamicin high", "genta high", "gehi"))
antimicrobials[which(antimicrobials$ab == "STH"), "abbreviations"][[1]] <- list(c("sthl", "streptomycin high", "strepto high", "sthi"))
# add imi and "imipenem/cilastatine" to imipenem
antimicrobials[which(antimicrobials$ab == "IPM"), "abbreviations"][[1]] <- list(c("imip", "imi", "imp"))
antimicrobials[which(antimicrobials$ab == "IPM"), "synonyms"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "IPM"), "synonyms"][[1]], "imipenem/cilastatin")))
# add synonyms of ones not found
antimicrobials[which(antimicrobials$ab == "TZP"), "synonyms"][[1]] <- list(sort(c(antimicrobials[which(antimicrobials$ab == "TZP"), "synonyms"][[1]], "Tazocel", "tazocillin", "Tazocin", "Zosyn")))
antimicrobials[which(antimicrobials$ab == "COL"), "synonyms"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "COL"), "synonyms"][[1]], "Colisticin", "Polymyxin E", "Colimycin", "Coly-Mycin", "Totazina", "Colistimethate", "Promixin", "Colistimethate Sodium"))))
# remove incorrect synonyms from rifampicin (RIF) and add them to the combination rifampicin/isoniazid (RFI)
old_sym <- antimicrobials[which(antimicrobials$ab == "RIF"), "synonyms"][[1]]
old_sym <- old_sym[!old_sym %in% c("Rifinah", "Rimactazid")]
antimicrobials[which(antimicrobials$ab == "RIF"), "synonyms"][[1]] <- list(old_sym)
antimicrobials[which(antimicrobials$ab == "RFI"), "synonyms"][[1]] <- list(sort(c("Rifinah", "Rimactazid")))
# remove incorrect synonyms from sulfamethoxazole (SMX) and add them to the combination trimethoprim/sulfamethoxazole (SXT)
old_sym <- antimicrobials[which(antimicrobials$ab == "SMX"), "synonyms"][[1]]
old_sym <- old_sym[!old_sym %in% c("Cotrimoxazole", "Bactrimel")]
antimicrobials[which(antimicrobials$ab == "SMX"), "synonyms"][[1]] <- list(old_sym)
antimicrobials[which(antimicrobials$ab == "SXT"), "synonyms"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "COL"), "synonyms"][[1]], "Cotrimoxazole", "Bactrimel", "Septra", "Bactrim", "Cotrimazole"))))
# Fix penicillins
antimicrobials[which(antimicrobials$ab == "PEN"), "abbreviations"][[1]] <- list(c("bepe", "pg", "pen", "peni", "peni g", "penicillin", "penicillin g"))
antimicrobials[which(antimicrobials$ab == "PEN"), "name"] <- "Benzylpenicillin"
antimicrobials[which(antimicrobials$ab == "PHN"), "abbreviations"][[1]] <- list(c("fepe", "peni v", "pv", "penicillin v", "PNV"))
antimicrobials <- subset(antimicrobials, antimicrobials$ab != "PNV")
# New DDDs
antimicrobials[which(antimicrobials$ab == "PEN"), "iv_ddd"] <- 3.6
antimicrobials[which(antimicrobials$ab == "PEN"), "iv_units"] <- "g"
## new ATC codes
# ceftaroline
antimicrobials[which(antimicrobials$ab == "CPT"), "atc"] <- "J01DI02"
# faropenem
antimicrobials[which(antimicrobials$ab == "FAR"), "atc"] <- "J01DI03"
# ceftobiprole
antimicrobials[which(antimicrobials$ab == "BPR"), "atc"] <- "J01DI01"
# ceftazidime / avibactam
antimicrobials[which(antimicrobials$ab == "CZA"), "atc"] <- "J01DD52"
antimicrobials[which(antimicrobials$ab == "CZA"), "cid"] <- 90643431
antimicrobials[which(antimicrobials$ab == "CZA"), "atc_group1"] <- "Other beta-lactam antibacterials"
antimicrobials[which(antimicrobials$ab == "CZA"), "atc_group2"] <- "Third-generation cephalosporins"
antimicrobials[which(antimicrobials$ab == "CZA"), "iv_ddd"] <- 6
antimicrobials[which(antimicrobials$ab == "CZA"), "iv_units"] <- "g"
antimicrobials[which(antimicrobials$ab == "CZA"), "synonyms"] <- list(c("Avycaz", "Zavicefta"))
# typo
antimicrobials[which(antimicrobials$ab == "RXT"), "name"] <- "Roxithromycin"
antimicrobials[which(antimicrobials$ab == "PEN"), "atc"] <- "J01CE01"
# WHONET cleanup
antimicrobials[which(antimicrobials$ab == "BCZ"), "name"] <- "Bicyclomycin"
antimicrobials[which(antimicrobials$ab == "CCL"), "name"] <- "Cefetecol"
antimicrobials[which(antimicrobials$ab == "ENV"), "name"] <- "Enviomycin"
antimicrobials[which(antimicrobials$ab == "KIT"), "name"] <- "Kitasamycin"
antimicrobials[which(antimicrobials$ab == "LSP"), "name"] <- "Linco-spectin"
antimicrobials[which(antimicrobials$ab == "MEC"), "name"] <- "Mecillinam"
antimicrobials[which(antimicrobials$ab == "PMR"), "name"] <- "Pimaricin"
antimicrobials[which(antimicrobials$ab == "BCZ"), "abbreviations"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "BCZ"), "abbreviations"][[1]], "Bicozamycin"))))
antimicrobials[which(antimicrobials$ab == "CCL"), "abbreviations"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "CCL"), "abbreviations"][[1]], "Cefcatacol"))))
antimicrobials[which(antimicrobials$ab == "ENV"), "abbreviations"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "ENV"), "abbreviations"][[1]], "Tuberactinomycin"))))
antimicrobials[which(antimicrobials$ab == "KIT"), "abbreviations"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "KIT"), "abbreviations"][[1]], "Leucomycin"))))
antimicrobials[which(antimicrobials$ab == "LSP"), "abbreviations"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "LSP"), "abbreviations"][[1]], "lincomycin/spectinomycin"))))
antimicrobials[which(antimicrobials$ab == "MEC"), "abbreviations"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "MEC"), "abbreviations"][[1]], "Amdinocillin"))))
antimicrobials[which(antimicrobials$ab == "PMR"), "abbreviations"][[1]] <- list(sort(unique(c(antimicrobials[which(antimicrobials$ab == "PMR"), "abbreviations"][[1]], "Natamycin"))))
# set cephalosporins groups for the ones that could not be determined automatically:
antimicrobials <- antimicrobials %>%
mutate(group = case_when(
name == "Cefcapene" ~ "Cephalosporins (3rd gen.)",
name == "Cefcapene pivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Cefditoren pivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Cefepime/clavulanic acid" ~ "Cephalosporins (4th gen.)",
name == "Cefepime/tazobactam" ~ "Cephalosporins (4th gen.)",
name == "Cefetamet pivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Cefetecol (Cefcatacol)" ~ "Cephalosporins (4th gen.)",
name == "Cefetrizole" ~ "Cephalosporins (unclassified gen.)",
name == "Cefoselis" ~ "Cephalosporins (4th gen.)",
name == "Cefotaxime/clavulanic acid" ~ "Cephalosporins (3rd gen.)",
name == "Cefotaxime/sulbactam" ~ "Cephalosporins (3rd gen.)",
name == "Cefotiam hexetil" ~ "Cephalosporins (3rd gen.)",
name == "Cefovecin" ~ "Cephalosporins (3rd gen.)",
name == "Cefozopran" ~ "Cephalosporins (4th gen.)",
name == "Cefpimizole" ~ "Cephalosporins (3rd gen.)",
name == "Cefpodoxime proxetil" ~ "Cephalosporins (3rd gen.)",
name == "Cefpodoxime/clavulanic acid" ~ "Cephalosporins (3rd gen.)",
name == "Cefquinome" ~ "Cephalosporins (4th gen.)",
name == "Cefsumide" ~ "Cephalosporins (unclassified gen.)",
name == "Ceftaroline" ~ "Cephalosporins (5th gen.)",
name == "Ceftaroline/avibactam" ~ "Cephalosporins (5th gen.)",
name == "Ceftazidime/avibactam" ~ "Cephalosporins (3rd gen.)",
name == "Cefteram" ~ "Cephalosporins (3rd gen.)",
name == "Cefteram pivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Ceftiofur" ~ "Cephalosporins (3rd gen.)",
name == "Ceftizoxime alapivoxil" ~ "Cephalosporins (3rd gen.)",
name == "Ceftobiprole" ~ "Cephalosporins (5th gen.)",
name == "Ceftobiprole medocaril" ~ "Cephalosporins (5th gen.)",
name == "Ceftolozane/enzyme inhibitor" ~ "Cephalosporins (5th gen.)",
name == "Ceftolozane/tazobactam" ~ "Cephalosporins (5th gen.)",
name == "Cefuroxime axetil" ~ "Cephalosporins (2nd gen.)",
TRUE ~ group
))
antimicrobials[which(antimicrobials$ab %in% c("CYC", "LNZ", "THA", "TZD")), "group"] <- "Oxazolidinones"
# add efflux
effl <- antimicrobials |>
filter(ab == "ACM") |>
mutate(ab = as.character("EFF"),
cid = NA_real_,
name = "Efflux",
group = "Other")
antimicrobials <- antimicrobials |>
mutate(ab = as.character(ab)) |>
bind_rows(effl)
class(antimicrobials$ab) <- c("ab", "character")
antimicrobials[which(antimicrobials$ab == "EFF"), "abbreviations"][[1]] <- list(c("effflux pump"))
# add clindamycin inducible screening
clin <- antimicrobials |>
filter(ab == "FOX1") |>
mutate(ab = as.character("CLI1"),
name = "Clindamycin inducible screening",
group = "Macrolides/lincosamides")
antimicrobials <- antimicrobials |>
mutate(ab = as.character(ab)) |>
bind_rows(clin)
class(antimicrobials$ab) <- c("ab", "character")
antimicrobials[which(antimicrobials$ab == "CLI1"), "abbreviations"][[1]] <- list(c("clindamycin inducible", "clinda inducible", "clin inducible"))
# add pretomanid
antimicrobials <- antimicrobials %>%
mutate(ab = as.character(ab)) %>%
bind_rows(antimicrobials %>%
mutate(ab = as.character(ab)) %>%
filter(ab == "SMF") %>%
mutate(
ab = "PMD",
atc = "J04AK08",
cid = 456199,
name = "Pretomanid",
abbreviations = list(""),
oral_ddd = NA_real_
))
# update ATC codes from WHOCC website -------------------------------------
# last time checked: 2024-02-22
library(rvest)
updated_atc <- as.list(antimicrobials$atc)
get_atcs <- function(ab_name, type = "human") {
if (type == "human") {
url <- "https://atcddd.fhi.no/atc_ddd_index/"
} else if (type == "veterinary") {
url <- "https://atcddd.fhi.no/atcvet/atcvet_index/"
} else {
stop("invalid type")
}
ab_name <- gsub("/", " and ", tolower(ab_name), fixed = TRUE)
# we will do a search on their website, which means:
# go to the url
atc_tbl <- read_html(url) %>%
# get all forms
html_form() %>%
# get the second form (the first form is a global website form)
.[[2]] %>%
# set the name input box to our search parameter
html_form_set(name = ab_name) %>%
# hit Submit
html_form_submit() %>%
# read the resulting page
read_html() %>%
# retrieve the table on it
html_node("table") %>%
# transform it to an R data set
html_table(header = FALSE)
# and get the ATCs (first column) of only exact hits
unique(as.character(atc_tbl[which(tolower(atc_tbl[, 2, drop = TRUE]) == ab_name), 1, drop = TRUE]))
}
# this takes around 4 minutes (some are skipped and go faster)
for (i in seq_len(nrow(antimicrobials))) {
message(percentage(i / nrow(antimicrobials), digits = 1),
" - Downloading ", antimicrobials$name[i],
appendLF = FALSE
)
atcs <- get_atcs(antimicrobials$name[i], type = "human")
if (all(is.na(atcs))) {
atcs <- get_atcs(antimicrobials$name[i], type = "veterinary")
}
if (length(atcs) > 0) {
updated_atc[[i]] <- atcs
message(" (", length(atcs), " results)")
# let the WHO server rest for a second - they might have a limitation on the queries per second
Sys.sleep(1)
} else {
message(" (skipping)")
}
}
antimicrobials$atc <- updated_atc
# update DDDs from WHOCC website ------------------------------------------
# last time checked: 2024-02-22
ddd_oral <- rep(NA_real_, nrow(antimicrobials))
ddd_oral_units <- rep(NA_character_, nrow(antimicrobials))
ddd_iv <- rep(NA_real_, nrow(antimicrobials))
ddd_iv_units <- rep(NA_character_, nrow(antimicrobials))
progress <- progress_ticker(nrow(antimicrobials))
for (i in seq_len(nrow(antimicrobials))) {
on.exit(close(progress))
progress$tick()
atcs <- antimicrobials$atc[[i]]
if (!all(is.na(atcs))) {
for (j in seq_len(length(atcs))) {
# oral
if (is.na(ddd_oral[i])) {
ddd_oral[i] <- atc_online_ddd(atcs[j], administration = "O")
if (!is.na(ddd_oral[i])) {
ddd_oral_units[i] <- atc_online_ddd_units(atcs[j], administration = "O")
}
}
# parenteral
if (is.na(ddd_iv[i])) {
ddd_iv[i] <- atc_online_ddd(atcs[j], administration = "P")
if (!is.na(ddd_iv[i])) {
ddd_iv_units[i] <- atc_online_ddd_units(atcs[j], administration = "P")
}
}
}
}
if (!is.na(ddd_oral[i]) | !is.na(ddd_iv[i])) {
# let the WHO server rest for 0.25 second - they might have a limitation on the queries per second
Sys.sleep(0.25)
}
}
antimicrobials$oral_ddd <- ddd_oral
antimicrobials$oral_units <- ddd_oral_units
antimicrobials$iv_ddd <- ddd_iv
antimicrobials$iv_units <- ddd_iv_units
# Wrap up -----------------------------------------------------------------
# set as data.frame again
antimicrobials <- dataset_UTF8_to_ASCII(as.data.frame(antimicrobials, stringsAsFactors = FALSE))
class(antimicrobials$ab) <- c("ab", "character")
antimicrobials <- dplyr::arrange(antimicrobials, name)
# REFER TO data-raw/loinc.R FOR ADDING LOINC CODES
# make all abbreviations and synonyms lower case, unique and alphabetically sorted ----
for (i in 1:nrow(antimicrobials)) {
abb <- as.character(sort(unique(tolower(antimicrobials[i, "abbreviations", drop = TRUE][[1]]))))
abb <- abb[abb != "" & abb %unlike% ":"]
syn <- as.character(sort(unique(tolower(unname(unlist(antimicrobials[i, "synonyms", drop = TRUE]))))))
syn <- gsub("[^a-z]", "", syn)
syn <- gsub(" +", " ", syn)
pharm_terms <- "(pa?ediatric|injection|oral|inhale|otic|sulfate|sulphate|sodium|base|anhydrous|anhydrate|stearate|syrup|natrium|hydrate|x?hcl|gsalt|vet[.]?)"
syn <- gsub(paste0(" ", pharm_terms, "$"), "", syn)
syn <- gsub(paste0("^", pharm_terms, " "), "", syn)
syn <- trimws(syn)
syn <- gsub(" [a-z]{1,3}$", "", syn, perl = TRUE)
syn <- trimws(syn)
syn <- syn[syn != "" & syn %unlike% ":" & !syn %in% tolower(antimicrobials$name)]
syn <- unique(syn)
# special cases
if (antimicrobials$ab[i] == "VAN") syn <- syn[syn %unlike% "^tei?ch?o"]
if (antimicrobials$ab[i] == "CLR") syn <- syn[syn %unlike% "^ery"]
antimicrobials[i, "abbreviations"][[1]] <- ifelse(length(abb) == 0, list(""), list(abb))
antimicrobials[i, "synonyms"][[1]] <- ifelse(length(syn) == 0, list(""), list(syn))
if ("loinc" %in% colnames(antimicrobials)) {
loinc <- as.character(sort(unique(tolower(antimicrobials[i, "loinc", drop = TRUE][[1]]))))
loinc <- loinc[loinc != ""]
antimicrobials[i, "loinc"][[1]] <- ifelse(length(loinc) == 0, list(""), list(loinc))
}
}
usethis::use_data(antimicrobials, overwrite = TRUE, version = 2, compress = "xz")
rm(antimicrobials)

View File

@ -235,7 +235,7 @@ breakpoints %>%
filter(!WHONET_ABX_CODE %in% whonet_antibiotics$WHONET_ABX_CODE) %>%
pull(WHONET_ABX_CODE) %>%
unique()
# they are at the moment all old codes that have the right replacements in `antibiotics`, so we can use as.ab()
# they are at the moment all old codes that have the right replacements in `antimicrobials`, so we can use as.ab()
## Build new breakpoints table ----

View File

@ -30,9 +30,9 @@
library(AMR)
library(dplyr)
int_resis <- data.frame(mo = microorganisms$mo, stringsAsFactors = FALSE)
for (i in seq_len(nrow(antibiotics))) {
for (i in seq_len(nrow(antimicrobials))) {
int_resis$new <- as.sir("S")
colnames(int_resis)[ncol(int_resis)] <- antibiotics$ab[i]
colnames(int_resis)[ncol(int_resis)] <- antimicrobials$ab[i]
}
int_resis <- eucast_rules(int_resis,
@ -49,14 +49,14 @@ int_resis2 <- int_resis[, sapply(int_resis, function(x) any(!is.sir(x) | x == "R
select(mo, ab = name)
# remove lab drugs
untreatable <- antibiotics[which(antibiotics$name %like% "-high|EDTA|polysorbate|macromethod|screening|/nacubactam"), "ab", drop = TRUE]
untreatable <- antimicrobials[which(antimicrobials$name %like% "-high|EDTA|polysorbate|macromethod|screening|/nacubactam"), "ab", drop = TRUE]
# takes ages with filter()..., weird
int_resis3 <- int_resis2[which(!int_resis2$ab %in% untreatable), ]
class(int_resis3$ab) <- c("ab", "character")
int_resis3
all(int_resis3$mo %in% microorganisms$mo)
all(int_resis3$ab %in% antibiotics$ab)
all(int_resis3$ab %in% antimicrobials$ab)
intrinsic_resistant <- df_remove_nonASCII(int_resis3)
usethis::use_data(intrinsic_resistant, internal = FALSE, overwrite = TRUE, version = 2, compress = "xz")

Binary file not shown.

BIN
data/antimicrobials.rda Normal file

Binary file not shown.

View File

@ -26,7 +26,7 @@ The `AMR` package is a [free and open-source](#copyright) R package with [zero d
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 [**~52,000 distinct microbial species**](./reference/microorganisms.html) (updated December 2022) and all [**~600 antibiotic, antimycotic and antiviral drugs**](./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 clinical breakpoint guidelines from CLSI and EUCAST are included, even with epidemiological cut-off (ECOFF) values. 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 [**~52,000 distinct microbial species**](./reference/microorganisms.html) (updated December 2022) and all [**~600 antimicrobial and antiviral drugs**](./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 clinical breakpoint guidelines from CLSI and EUCAST are included, even with epidemiological cut-off (ECOFF) values. 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).
##### Used in over 175 countries, available in 20 languages
@ -58,7 +58,7 @@ example_isolates %>%
carbapenems())
```
With only having defined a row filter on Gram-negative bacteria with intrinsic resistance to cefotaxime (`mo_is_gram_negative()` and `mo_is_intrinsic_resistant()`) and a column selection on two antibiotic groups (`aminoglycosides()` and `carbapenems()`), the reference data about [all microorganisms](./reference/microorganisms.html) and [all antibiotics](./reference/antibiotics.html) in the `AMR` package make sure you get what you meant:
With only having defined a row filter on Gram-negative bacteria with intrinsic resistance to cefotaxime (`mo_is_gram_negative()` and `mo_is_intrinsic_resistant()`) and a column selection on two antibiotic groups (`aminoglycosides()` and `carbapenems()`), the reference data about [all microorganisms](./reference/microorganisms.html) and [all antimicrobials](./reference/antimicrobials.html) in the `AMR` package make sure you get what you meant:
|bacteria | GEN | TOB | AMK | KAN | IPM | MEM |
|:------------------------------|:---:|:---:|:---:|:---:|:---:|:---:|
@ -81,7 +81,8 @@ If used inside [R Markdown](https://rmarkdown.rstudio.com) or [Quarto](https://q
```r
antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems()))
antibiotics = c(aminoglycosides(), carbapenems()),
formatting_type = 14)
```
| Pathogen | Amikacin | Gentamicin | Imipenem | Kanamycin | Meropenem | Tobramycin |
@ -102,7 +103,8 @@ In combination antibiograms, it is clear that combined antibiotics yield higher
```r
antibiogram(example_isolates,
antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
mo_transform = "gramstain")
mo_transform = "gramstain",
formatting_type = 14)
```
|Pathogen | Piperacillin/tazobactam | Piperacillin/tazobactam + Gentamicin | Piperacillin/tazobactam + Tobramycin |
@ -117,6 +119,7 @@ antibiogram(example_isolates,
antibiotics = c("cipro", "tobra", "genta"), # any arbitrary name or code will work
mo_transform = "gramstain",
ab_transform = "name",
formatting_type = 14,
language = "uk") # Ukrainian
```

View File

@ -1,16 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zz_deprecated.R
\docType{data}
\name{AMR-deprecated}
\alias{AMR-deprecated}
\alias{antibiotics}
\alias{ab_class}
\alias{ab_selector}
\title{Deprecated Functions}
\format{
An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 487 rows and 14 columns.
}
\usage{
antibiotics
ab_class(...)
ab_selector(...)
}
\description{
These functions are so-called '\link{Deprecated}'. \strong{They will be removed in a future version of this package.} Using these functions will give a warning with the name of the function it has been replaced by (if there is one).
These objects are so-called '\link{Deprecated}'. \strong{They will be removed in a future version of this package.} Using these will give a warning with the name of the alternative object it has been replaced by (if there is one).
}
\keyword{datasets}
\keyword{internal}

View File

@ -9,7 +9,7 @@ This is an overview of all the package-specific \code{\link[=options]{options()}
\section{Options}{
\itemize{
\item \code{AMR_antibiogram_formatting_type} \cr A \link{numeric} (1-12) to use in \code{\link[=antibiogram]{antibiogram()}}, to indicate which formatting type to use.
\item \code{AMR_antibiogram_formatting_type} \cr A \link{numeric} (1-22) to use in \code{\link[=antibiogram]{antibiogram()}}, to indicate which formatting type to use.
\item \code{AMR_breakpoint_type} \cr A \link{character} to use in \code{\link[=as.sir]{as.sir()}}, to indicate which breakpoint type to use. This must be either "ECOFF", "animal", or "human".
\item \code{AMR_cleaning_regex} \cr A \link[base:regex]{regular expression} (case-insensitive) to use in \code{\link[=as.mo]{as.mo()}} and all \code{\link[=mo_property]{mo_*}} functions, to clean the user input. The default is the outcome of \code{\link[=mo_cleaning_regex]{mo_cleaning_regex()}}, which removes texts between brackets and texts such as "species" and "serovar".
\item \code{AMR_custom_ab} \cr A file location to an RDS file, to use custom antimicrobial drugs with this package. This is explained in \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}}.
@ -38,7 +38,7 @@ In this file, you can set options such as...
options(AMR_include_PKPD = TRUE)
}\if{html}{\out{</div>}}
...to add Portuguese language support of antibiotics, and allow PK/PD rules when interpreting MIC values with \code{\link[=as.sir]{as.sir()}}.
...to add Portuguese language support of antimicrobials, and allow PK/PD rules when interpreting MIC values with \code{\link[=as.sir]{as.sir()}}.
\subsection{Share Options Within Team}{
For a more global approach, e.g. within a (data) team, save an options file to a remote file location, such as a shared network drive, and have each user read in this file automatically at start-up. This would work in this way:

View File

@ -32,13 +32,13 @@ The \code{AMR} package is a \href{https://msberends.github.io/AMR/#copyright}{fr
This work was published in the Journal of Statistical Software (Volume 104(3); \doi{10.18637/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{~79 000 microorganisms}} (updated June 2024) and all \href{https://msberends.github.io/AMR/reference/antibiotics.html}{\strong{~610 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 clinical breakpoint guidelines from CLSI and EUCAST are included, even with epidemiological cut-off (ECOFF) values. 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 public \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{~79 000 microorganisms}} (updated June 2024) and all \href{https://msberends.github.io/AMR/reference/antimicrobials.html}{\strong{~610 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 clinical breakpoint guidelines from CLSI and EUCAST are included, even with epidemiological cut-off (ECOFF) values. 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 public \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, 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}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\seealso{

View File

@ -32,14 +32,14 @@ A \link[tibble:tibble]{tibble} with 500 observations and 53 variables:
\item \verb{Inducible clindamycin resistance}\cr Clindamycin can be induced?
\item \code{Comment}\cr Other comments
\item \verb{Date of data entry}\cr \link{Date} this data was entered in WHONET
\item \code{AMP_ND10:CIP_EE}\cr 28 different antibiotics. You can lookup the abbreviations in the \link{antibiotics} data set, or use e.g. \code{\link[=ab_name]{ab_name("AMP")}} to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using \code{\link[=as.sir]{as.sir()}}.
\item \code{AMP_ND10:CIP_EE}\cr 28 different antimicrobials. You can lookup the abbreviations in the \link{antimicrobials} data set, or use e.g. \code{\link[=ab_name]{ab_name("AMP")}} to get the official name immediately. Before analysis, you should transform this to a valid antimcrobial class, using \code{\link[=as.sir]{as.sir()}}.
}
}
\usage{
WHONET
}
\description{
This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antibiotic results are from our \link{example_isolates} data set. All patient names were created using online surname generators and are only in place for practice purposes.
This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The antimcrobial results are from our \link{example_isolates} data set. All patient names were created using online surname generators and are only in place for practice purposes.
}
\details{
Like all data sets in this package, this data set is publicly available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, and Stata. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.

View File

@ -15,7 +15,7 @@ ab_from_text(text, type = c("drug", "dose", "administration"),
\item{collapse}{a \link{character} to pass on to \code{paste(, collapse = ...)} to only return one \link{character} per element of \code{text}, see \emph{Examples}}
\item{translate_ab}{if \code{type = "drug"}: a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}. The default is \code{FALSE}. Using \code{TRUE} is equal to using "name".}
\item{translate_ab}{if \code{type = "drug"}: a column name of the \link{antimicrobials} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}. The default is \code{FALSE}. Using \code{TRUE} is equal to using "name".}
\item{thorough_search}{a \link{logical} to indicate whether the input must be extensively searched for misspelling and other faulty input values. Setting this to \code{TRUE} will take considerably more time than when using \code{FALSE}. At default, it will turn \code{TRUE} when all input elements contain a maximum of three words.}

View File

@ -65,7 +65,7 @@ set_ab_names(data, ..., property = "name", language = get_AMR_locale(),
\item{open}{browse the URL using \code{\link[utils:browseURL]{utils::browseURL()}}}
\item{property}{one of the column names of one of the \link{antibiotics} data set: \code{vector_or(colnames(antibiotics), sort = FALSE)}.}
\item{property}{one of the column names of one of the \link{antimicrobials} data set: \code{vector_or(colnames(antimicrobials), sort = FALSE)}.}
\item{data}{a \link{data.frame} of which the columns need to be renamed, or a \link{character} vector of column names}
@ -81,7 +81,7 @@ set_ab_names(data, ..., property = "name", language = get_AMR_locale(),
}
}
\description{
Use these functions to return a specific property of an antibiotic from the \link{antibiotics} data set. All input values will be evaluated internally with \code{\link[=as.ab]{as.ab()}}.
Use these functions to return a specific property of an antibiotic from the \link{antimicrobials} data set. All input values will be evaluated internally with \code{\link[=as.ab]{as.ab()}}.
}
\details{
All output \link[=translate]{will be translated} where possible.
@ -99,7 +99,7 @@ European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{htt
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{
@ -168,5 +168,5 @@ if (require("dplyr")) {
}
}
\seealso{
\link{antibiotics}
\link{antimicrobials}
}

View File

@ -10,7 +10,7 @@ add_custom_antimicrobials(x)
clear_custom_antimicrobials()
}
\arguments{
\item{x}{a \link{data.frame} resembling the \link{antibiotics} data set, at least containing columns "ab" and "name"}
\item{x}{a \link{data.frame} resembling the \link{antimicrobials} data set, at least containing columns "ab" and "name"}
}
\description{
With \code{\link[=add_custom_antimicrobials]{add_custom_antimicrobials()}} you can add your own custom antimicrobial drug names and codes.
@ -22,7 +22,7 @@ There are two ways to circumvent this and automate the process of adding antimic
\strong{Method 1:} Using the package option \code{\link[=AMR-options]{AMR_custom_ab}}, which is the preferred method. To use this method:
\enumerate{
\item Create a data set in the structure of the \link{antibiotics} data set (containing at the very least columns "ab" and "name") and save it with \code{\link[=saveRDS]{saveRDS()}} to a location of choice, e.g. \code{"~/my_custom_ab.rds"}, or any remote location.
\item Create a data set in the structure of the \link{antimicrobials} data set (containing at the very least columns "ab" and "name") and save it with \code{\link[=saveRDS]{saveRDS()}} to a location of choice, e.g. \code{"~/my_custom_ab.rds"}, or any remote location.
\item Set the file location to the package option \code{\link[=AMR-options]{AMR_custom_ab}}: \code{options(AMR_custom_ab = "~/my_custom_ab.rds")}. This can even be a remote file location, such as an https URL. Since options are not saved between \R sessions, it is best to save this option to the \code{.Rprofile} file so that it will be loaded on start-up of \R. To do this, open the \code{.Rprofile} file using e.g. \code{utils::file.edit("~/.Rprofile")}, add this text and save the file:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Add custom antimicrobial codes:
@ -60,7 +60,7 @@ add_custom_antimicrobials(
ab = "TESTAB",
name = "Test Antibiotic",
# you can add any property present in the
# 'antibiotics' data set, such as 'group':
# 'antimicrobials' data set, such as 'group':
group = "Test Group"
)
)

View File

@ -21,10 +21,10 @@
antibiogram(x, antibiotics = where(is.sir), mo_transform = "shortname",
ab_transform = "name", syndromic_group = NULL, add_total_n = FALSE,
only_all_tested = FALSE, digits = ifelse(wisca, 1, 0),
formatting_type = getOption("AMR_antibiogram_formatting_type", 14),
col_mo = NULL, language = get_AMR_locale(), minimum = 30,
combine_SI = TRUE, sep = " + ", wisca = FALSE, simulations = 1000,
conf_interval = 0.95, interval_side = "two-tailed",
formatting_type = getOption("AMR_antibiogram_formatting_type",
ifelse(wisca, 14, 18)), col_mo = NULL, language = get_AMR_locale(),
minimum = 30, combine_SI = TRUE, sep = " + ", wisca = FALSE,
simulations = 1000, conf_interval = 0.95, interval_side = "two-tailed",
info = interactive())
wisca(x, antibiotics = where(is.sir), ab_transform = "name",
@ -52,7 +52,7 @@ retrieve_wisca_parameters(wisca_model, ...)
\item{mo_transform}{a character to transform microorganism input - must be \code{"name"}, \code{"shortname"} (default), \code{"gramstain"}, or one of the column names of the \link{microorganisms} data set: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". Can also be \code{NULL} to not transform the input or \code{NA} to consider all microorganisms 'unknown'.}
\item{ab_transform}{a character to transform antimicrobial input - must be one of the column names of the \link{antibiotics} data set (defaults to \code{"name"}): "ab", "cid", "name", "group", "atc", "atc_group1", "atc_group2", "abbreviations", "synonyms", "oral_ddd", "oral_units", "iv_ddd", "iv_units", or "loinc". Can also be \code{NULL} to not transform the input.}
\item{ab_transform}{a character to transform antimicrobial input - must be one of the column names of the \link{antimicrobials} data set (defaults to \code{"name"}): "ab", "cid", "name", "group", "atc", "atc_group1", "atc_group2", "abbreviations", "synonyms", "oral_ddd", "oral_units", "iv_ddd", "iv_units", or "loinc". Can also be \code{NULL} to not transform the input.}
\item{syndromic_group}{a column name of \code{x}, or values calculated to split rows of \code{x}, e.g. by using \code{\link[=ifelse]{ifelse()}} or \code{\link[dplyr:case_when]{case_when()}}. See \emph{Examples}.}
@ -109,7 +109,7 @@ For estimating antimicrobial coverage, especially when creating a WISCA, the out
The numeric values of an antibiogram are stored in a long format as the \link[=attributes]{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting.
\subsection{Formatting Type}{
The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} is the antimicrobial coverage (\code{4-6} indicates the confidence level), \code{15} the number of susceptible isolates, and \code{300} the number of tested (i.e., available) isolates:
The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} indicates the antimicrobial coverage (\code{4-6} the confidence level), \code{15} the number of susceptible isolates, and \code{300} the number of tested (i.e., available) isolates:
\enumerate{
\item 5
\item 15
@ -124,18 +124,18 @@ The formatting of the 'cells' of the table can be set with the argument \code{fo
\item 5 (N=15/300)
\item 5\% (N=15/300)
\item 5 (4-6)
\item 5\% (4-6\%) - \strong{default}
\item 5\% (4-6\%) - \strong{default for WISCA}
\item 5 (4-6,300)
\item 5\% (4-6\%,300)
\item 5 (4-6,N=300)
\item 5\% (4-6\%,N=300)
\item 5\% (4-6\%,N=300) - \strong{default for non-WISCA}
\item 5 (4-6,15/300)
\item 5\% (4-6\%,15/300)
\item 5 (4-6,N=15/300)
\item 5\% (4-6\%,N=15/300)
}
The default is \code{14}, which can be set globally with the package option \code{\link[=AMR-options]{AMR_antibiogram_formatting_type}}, e.g. \code{options(AMR_antibiogram_formatting_type = 5)}. Do note that for WISCA, the total numbers of tested and susceptible isolates are less useful to report, since these are included in the Bayesian model and apparent from the susceptibility and its confidence level.
The default can be set globally with the package option \code{\link[=AMR-options]{AMR_antibiogram_formatting_type}}, e.g. \code{options(AMR_antibiogram_formatting_type = 5)}. Do note that for WISCA, the total numbers of tested and susceptible isolates are less useful to report, since these are included in the Bayesian model and apparent from the susceptibility and its confidence level.
Set \code{digits} (defaults to \code{0}) to alter the rounding of the susceptibility percentages.
}

View File

@ -130,9 +130,9 @@ not_intrinsic_resistant(only_sir_columns = FALSE, col_mo = NULL,
\item{...}{ignored, only in place to allow future extensions}
\item{amr_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.}
\item{amr_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antimicrobials} data set will be searched (case-insensitive) for this value.}
\item{filter}{an \link{expression} to be evaluated in the \link{antibiotics} data set, such as \code{name \%like\% "trim"}}
\item{filter}{an \link{expression} to be evaluated in the \link{antimicrobials} data set, such as \code{name \%like\% "trim"}}
\item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
@ -156,13 +156,13 @@ These functions can be used in data set calls for selecting columns and filterin
All selectors can also be used in \code{tidymodels} packages such as \code{recipe} and \code{parsnip}. See for more info \href{https://msberends.github.io/AMR/articles/AMR_with_tidymodels.html}{our tutorial} on using antimicrobial selectors for predictive modelling.
All columns in the data in which these functions are called will be searched for known antimicrobial names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the \link{antibiotics} data set. This means that a selector such as \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
All columns in the data in which these functions are called will be searched for known antimicrobial names, abbreviations, brand names, and codes (ATC, EARS-Net, WHO, etc.) according to the \link{antimicrobials} data set. This means that a selector such as \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.
The \code{\link[=amr_class]{amr_class()}} function can be used to filter/select on a manually defined antimicrobial class. It searches for results in the \link{antibiotics} data set within the columns \code{group}, \code{atc_group1} and \code{atc_group2}.
The \code{\link[=amr_class]{amr_class()}} function can be used to filter/select on a manually defined antimicrobial class. It searches for results in the \link{antimicrobials} data set within the columns \code{group}, \code{atc_group1} and \code{atc_group2}.
The \code{\link[=administrable_per_os]{administrable_per_os()}} and \code{\link[=administrable_iv]{administrable_iv()}} functions also rely on the \link{antibiotics} data set - antimicrobials will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the \link{antibiotics} data set.
The \code{\link[=administrable_per_os]{administrable_per_os()}} and \code{\link[=administrable_iv]{administrable_iv()}} functions also rely on the \link{antimicrobials} data set - antimicrobials will be matched where a DDD (defined daily dose) for resp. oral and IV treatment is available in the \link{antimicrobials} data set.
The \code{\link[=amr_selector]{amr_selector()}} function can be used to internally filter the \link{antibiotics} data set on any results, see \emph{Examples}. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
The \code{\link[=amr_selector]{amr_selector()}} function can be used to internally filter the \link{antimicrobials} data set on any results, see \emph{Examples}. It allows for filtering on a (part of) a certain name, and/or a group name or even a minimum of DDDs for oral treatment. This function yields the highest flexibility, but is also the least user-friendly, since it requires a hard-coded filter to set.
The \code{\link[=not_intrinsic_resistant]{not_intrinsic_resistant()}} function can be used to only select antimicrobials that pose no intrinsic resistance for the microorganisms in the data set. For example, if a data set contains only microorganism codes or names of \emph{E. coli} and \emph{K. pneumoniae} and contains a column "vancomycin", this column will be removed (or rather, unselected) using this function. It currently applies \href{https://www.eucast.org/expert_rules_and_expected_phenotypes}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021) to determine intrinsic resistance, using the \code{\link[=eucast_rules]{eucast_rules()}} function internally. Because of this determination, this function is quite slow in terms of performance.
}
@ -205,7 +205,7 @@ The \code{\link[=not_intrinsic_resistant]{not_intrinsic_resistant()}} function c
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{
@ -341,7 +341,7 @@ example_isolates[any(carbapenems() == "R"), penicillins()]
# and erythromycin is not a penicillin:
example_isolates[, penicillins() & administrable_per_os()]
# amr_selector() applies a filter in the `antibiotics` data set and is thus
# amr_selector() applies a filter in the `antimicrobials` data set and is thus
# very flexible. For instance, to select antimicrobials with an oral DDD
# of at least 1 gram:
example_isolates[, amr_selector(oral_ddd > 1 & oral_units == "g")]

View File

@ -1,21 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{antibiotics}
\name{antimicrobials}
\alias{antimicrobials}
\alias{antibiotics}
\alias{antivirals}
\title{Data Sets with 607 Antimicrobial Drugs}
\format{
\subsection{For the \link{antibiotics} data set: a \link[tibble:tibble]{tibble} with 487 observations and 14 variables:}{
\subsection{For the \link{antimicrobials} data set: a \link[tibble:tibble]{tibble} with 487 observations and 14 variables:}{
\itemize{
\item \code{ab}\cr Antibiotic ID as used in this package (such as \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available. \emph{\strong{This is a unique identifier.}}
\item \code{ab}\cr antimcrobial ID as used in this package (such as \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available. \emph{\strong{This is a unique identifier.}}
\item \code{cid}\cr Compound ID as found in PubChem. \emph{\strong{This is a unique identifier.}}
\item \code{name}\cr Official name as used by WHONET/EARS-Net or the WHO. \emph{\strong{This is a unique identifier.}}
\item \code{group}\cr A short and concise group name, based on WHONET and WHOCC definitions
\item \code{atc}\cr ATC codes (Anatomical Therapeutic Chemical) as defined by the WHOCC, like \code{J01CR02}
\item \code{atc_group1}\cr Official pharmacological subgroup (3rd level ATC code) as defined by the WHOCC, like \code{"Macrolides, lincosamides and streptogramins"}
\item \code{atc_group2}\cr Official chemical subgroup (4th level ATC code) as defined by the WHOCC, like \code{"Macrolides"}
\item \code{abbr}\cr List of abbreviations as used in many countries, also for antibiotic susceptibility testing (AST)
\item \code{abbr}\cr List of abbreviations as used in many countries, also for antimcrobial susceptibility testing (AST)
\item \code{synonyms}\cr Synonyms (often trade names) of a drug, as found in PubChem based on their compound ID
\item \code{oral_ddd}\cr Defined Daily Dose (DDD), oral treatment, currently available for 179 drugs
\item \code{oral_units}\cr Units of \code{oral_ddd}
@ -51,12 +52,12 @@ An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) w
}
}
\usage{
antibiotics
antimicrobials
antivirals
}
\description{
Two data sets containing all antibiotics/antimycotics and antivirals. Use \code{\link[=as.ab]{as.ab()}} or one of the \code{\link[=ab_property]{ab_*}} functions to retrieve values from the \link{antibiotics} data set. Three identifiers are included in this data set: an antibiotic ID (\code{ab}, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (\code{atc}) as defined by the WHO, and a Compound ID (\code{cid}) as found in PubChem. Other properties in this data set are derived from one or more of these codes. Note that some drugs have multiple ATC codes.
Two data sets containing all antimicrobials and antivirals. Use \code{\link[=as.ab]{as.ab()}} or one of the \code{\link[=ab_property]{ab_*}} functions to retrieve values from the \link{antimicrobials} data set. Three identifiers are included in this data set: an antimcrobial ID (\code{ab}, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (\code{atc}) as defined by the WHO, and a Compound ID (\code{cid}) as found in PubChem. Other properties in this data set are derived from one or more of these codes. Note that some drugs have multiple ATC codes.
}
\details{
Properties that are based on an ATC code are only available when an ATC is available. These properties are: \code{atc_group1}, \code{atc_group2}, \code{oral_ddd}, \code{oral_units}, \code{iv_ddd} and \code{iv_units}.
@ -79,7 +80,7 @@ The WHOCC is located in Oslo at the Norwegian Institute of Public Health and fun
}
\examples{
antibiotics
antimicrobials
antivirals
}
\seealso{

View File

@ -29,10 +29,10 @@ ab_reset_session()
A \link{character} \link{vector} with additional class \code{\link{ab}}
}
\description{
Use this function to determine the antibiotic drug code of one or more antibiotics. The data set \link{antibiotics} will be searched for abbreviations, official names and synonyms (brand names).
Use this function to determine the antimicrobial drug code of one or more antimicrobials. The data set \link{antimicrobials} will be searched for abbreviations, official names and synonyms (brand names).
}
\details{
All entries in the \link{antibiotics} data set have three different identifiers: a human readable EARS-Net code (column \code{ab}, used by ECDC and WHONET), an ATC code (column \code{atc}, used by WHO), and a CID code (column \code{cid}, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. Not that some drugs contain multiple ATC codes.
All entries in the \link{antimicrobials} data set have three different identifiers: a human readable EARS-Net code (column \code{ab}, used by ECDC and WHONET), an ATC code (column \code{atc}, used by WHO), and a CID code (column \code{cid}, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. Not that some drugs contain multiple ATC codes.
All these properties will be searched for the user input. The \code{\link[=as.ab]{as.ab()}} can correct for different forms of misspelling:
\itemize{
@ -68,7 +68,7 @@ The WHOCC is located in Oslo at the Norwegian Institute of Public Health and fun
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{
@ -104,7 +104,7 @@ if (require("dplyr")) {
}
\seealso{
\itemize{
\item \link{antibiotics} for the \link{data.frame} that is being used to determine ATCs
\item \link{antimicrobials} for the \link{data.frame} that is being used to determine ATCs
\item \code{\link[=ab_from_text]{ab_from_text()}} for a function to retrieve antimicrobial drugs from clinical text (from health care records)
}
}

View File

@ -60,7 +60,7 @@ The WHOCC is located in Oslo at the Norwegian Institute of Public Health and fun
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{

View File

@ -204,7 +204,7 @@ All matches are sorted descending on their matching score and for all user input
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{

View File

@ -224,7 +224,7 @@ This AMR package honours this insight. Use \code{\link[=susceptibility]{suscepti
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{

View File

@ -21,7 +21,7 @@ atc_online_ddd(atc_code, ...)
atc_online_ddd_units(atc_code, ...)
}
\arguments{
\item{atc_code}{a \link{character} (vector) with ATC code(s) of antibiotics, will be coerced with \code{\link[=as.ab]{as.ab()}} and \code{\link[=ab_atc]{ab_atc()}} internally if not a valid ATC code}
\item{atc_code}{a \link{character} (vector) with ATC code(s) of antimicrobials, will be coerced with \code{\link[=as.ab]{as.ab()}} and \code{\link[=ab_atc]{ab_atc()}} internally if not a valid ATC code}
\item{property}{property of an ATC code. Valid values are \code{"ATC"}, \code{"Name"}, \code{"DDD"}, \code{"U"} (\code{"unit"}), \code{"Adm.R"}, \code{"Note"} and \code{groups}. For this last option, all hierarchical groups of an ATC code will be returned, see \emph{Examples}.}
@ -34,7 +34,7 @@ atc_online_ddd_units(atc_code, ...)
\item{...}{arguments to pass on to \code{atc_property}}
}
\description{
Gets data from the WHOCC website to determine properties of an Anatomical Therapeutic Chemical (ATC) (e.g. an antibiotic), such as the name, defined daily dose (DDD) or standard unit.
Gets data from the WHOCC website to determine properties of an Anatomical Therapeutic Chemical (ATC) (e.g. an antimicrobial), such as the name, defined daily dose (DDD) or standard unit.
}
\details{
Options for argument \code{administration}:

View File

@ -79,7 +79,7 @@ European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{htt
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{

View File

@ -15,7 +15,7 @@ bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname,
",", ".", ","), ...)
}
\arguments{
\item{x}{a data set with antibiotic columns, such as \code{amox}, \code{AMX} and \code{AMC}}
\item{x}{a data set with antimicrobials columns, such as \code{amox}, \code{AMX} and \code{AMC}}
\item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
@ -25,7 +25,7 @@ bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname,
\item{...}{arguments passed on to \code{FUN}}
\item{translate_ab}{a \link{character} of length 1 containing column names of the \link{antibiotics} data set}
\item{translate_ab}{a \link{character} of length 1 containing column names of the \link{antimicrobials} data set}
\item{language}{language of the returned text - the default is the current system language (see \code{\link[=get_AMR_locale]{get_AMR_locale()}}) and can also be set with the package option \code{\link[=AMR-options]{AMR_locale}}. Use \code{language = NULL} or \code{language = ""} to prevent translation.}

View File

@ -14,7 +14,7 @@ A \link[tibble:tibble]{tibble} with 34 063 observations and 14 variables:
\item \code{site}\cr Body site for which the breakpoint must be applied, e.g. "Oral" or "Respiratory"
\item \code{mo}\cr Microbial ID, see \code{\link[=as.mo]{as.mo()}}
\item \code{rank_index}\cr Taxonomic rank index of \code{mo} from 1 (subspecies/infraspecies) to 5 (unknown microorganism)
\item \code{ab}\cr Antibiotic code as used by this package, EARS-Net and WHONET, see \code{\link[=as.ab]{as.ab()}}
\item \code{ab}\cr Antimcrobial code as used by this package, EARS-Net and WHONET, see \code{\link[=as.ab]{as.ab()}}
\item \code{ref_tbl}\cr Info about where the guideline rule can be found
\item \code{disk_dose}\cr Dose of the used disk diffusion method
\item \code{breakpoint_S}\cr Lowest MIC value or highest number of millimetres that leads to "S"

View File

@ -38,11 +38,11 @@ count_df(data, translate_ab = "name", language = get_AMR_locale(),
\arguments{
\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link[=as.sir]{as.sir()}} if needed.}
\item{only_all_tested}{(for combination therapies, i.e. using more than one variable for \code{...}): a \link{logical} to indicate that isolates must be tested for all antibiotics, see section \emph{Combination Therapy} below}
\item{only_all_tested}{(for combination therapies, i.e. using more than one variable for \code{...}): a \link{logical} to indicate that isolates must be tested for all antimicrobials, see section \emph{Combination Therapy} below}
\item{data}{a \link{data.frame} containing columns with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}})}
\item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}}
\item{translate_ab}{a column name of the \link{antimicrobials} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}}
\item{language}{language of the returned text - the default is the current system language (see \code{\link[=get_AMR_locale]{get_AMR_locale()}}) and can also be set with the package option \code{\link[=AMR-options]{AMR_locale}}. Use \code{language = NULL} or \code{language = ""} to prevent translation.}
@ -61,7 +61,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[=n_sir]{n_sir()}} 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[=n_sir]{n_sir()}} is an alias of \code{\link[=count_all]{count_all()}}. They can be used to count all available isolates, i.e. where all input antimicrobials 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{sir}} class (created with \code{\link[=as.sir]{as.sir()}}) and counts the number of S's, I's and R's. It also supports grouped variables. The function \code{\link[=sir_df]{sir_df()}} works exactly like \code{\link[=count_df]{count_df()}}, but adds the percentage of S, I and R.
}
@ -85,7 +85,7 @@ This AMR package honours this insight. Use \code{\link[=susceptibility]{suscepti
\section{Combination Therapy}{
When using more than one variable for \code{...} (= combination therapy), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Drug A and Drug B, about how \code{\link[=susceptibility]{susceptibility()}} works to calculate the \%SI:
When using more than one variable for \code{...} (= combination therapy), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antimicrobials, Drug A and Drug B, about how \code{\link[=susceptibility]{susceptibility()}} works to calculate the \%SI:
\if{html}{\out{<div class="sourceCode">}}\preformatted{--------------------------------------------------------------------
only_all_tested = FALSE only_all_tested = TRUE

View File

@ -72,11 +72,11 @@ eucast_rules(df, rules = "custom", custom_rules = y, info = FALSE)
}\if{html}{\out{</div>}}
}
\subsection{Usage of multiple antibiotics and antibiotic group names}{
\subsection{Usage of multiple antimicrobials and antimicrobial group names}{
You can define antibiotic groups instead of single antibiotics for the rule consequence, which is the part \emph{after} the tilde (~). In the examples above, the antibiotic group \code{aminopenicillins} includes both ampicillin and amoxicillin.
You can define antimicrobial groups instead of single antimicrobials for the rule consequence, which is the part \emph{after} the tilde (~). In the examples above, the antimicrobial group \code{aminopenicillins} includes both ampicillin and amoxicillin.
Rules can also be applied to multiple antibiotics and antibiotic groups simultaneously. Use the \code{c()} function to combine multiple antibiotics. For instance, the following example sets all aminopenicillins and ureidopenicillins to "R" if column TZP (piperacillin/tazobactam) is "R":
Rules can also be applied to multiple antimicrobials and antimicrobial groups simultaneously. Use the \code{c()} function to combine multiple antimicrobials. For instance, the following example sets all aminopenicillins and ureidopenicillins to "R" if column TZP (piperacillin/tazobactam) is "R":
\if{html}{\out{<div class="sourceCode r">}}\preformatted{x <- custom_eucast_rules(TZP == "R" ~ c(aminopenicillins, ureidopenicillins) == "R")
x
@ -86,7 +86,7 @@ x
#> amoxicillin (AMX), ampicillin (AMP), azlocillin (AZL), mezlocillin (MEZ), piperacillin (PIP), piperacillin/tazobactam (TZP)
}\if{html}{\out{</div>}}
These 34 antibiotic groups are allowed in the rules (case-insensitive) and can be used in any combination:
These 34 antimicrobial groups are allowed in the rules (case-insensitive) and can be used in any combination:
\itemize{
\item aminoglycosides\cr(amikacin, amikacin/fosfomycin, apramycin, arbekacin, astromicin, bekanamycin, dibekacin, framycetin, gentamicin, gentamicin-high, habekacin, hygromycin, isepamicin, kanamycin, kanamycin-high, kanamycin/cephalexin, micronomicin, neomycin, netilmicin, pentisomicin, plazomicin, propikacin, ribostamycin, sisomicin, streptoduocin, streptomycin, streptomycin-high, tobramycin, and tobramycin-high)
\item aminopenicillins\cr(amoxicillin and ampicillin)

View File

@ -7,7 +7,7 @@
\format{
A \link[tibble:tibble]{tibble} with 503 observations and 9 variables:
\itemize{
\item \code{ab}\cr Antibiotic ID as used in this package (such as \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available
\item \code{ab}\cr Antimcrobial ID as used in this package (such as \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available
\item \code{name}\cr Official name of the antimicrobial drug as used by WHONET/EARS-Net or the WHO
\item \code{type}\cr Type of the dosage, either "high_dosage", "standard_dosage", or "uncomplicated_uti"
\item \code{dose}\cr Dose, such as "2 g" or "25 mg/kg"

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@ A \link[tibble:tibble]{tibble} with 2 000 observations and 46 variables:
\item \code{gender}\cr Gender of the patient, either "F" or "M"
\item \code{ward}\cr Ward type where the patient was admitted, either "Clinical", "ICU", or "Outpatient"
\item \code{mo}\cr ID of microorganism created with \code{\link[=as.mo]{as.mo()}}, see also the \link{microorganisms} data set
\item \code{PEN:RIF}\cr 40 different antibiotics with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}}); these column names occur in the \link{antibiotics} data set and can be translated with \code{\link[=set_ab_names]{set_ab_names()}} or \code{\link[=ab_name]{ab_name()}}
\item \code{PEN:RIF}\cr 40 different antimicrobials with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}}); these column names occur in the \link{antimicrobials} data set and can be translated with \code{\link[=set_ab_names]{set_ab_names()}} or \code{\link[=ab_name]{ab_name()}}
}
}
\usage{

View File

@ -11,7 +11,7 @@ A \link[tibble:tibble]{tibble} with 3 000 observations and 8 variables:
\item \code{date}\cr date of receipt at the laboratory
\item \code{hospital}\cr ID of the hospital, from A to C
\item \code{bacteria}\cr info about microorganism that can be transformed with \code{\link[=as.mo]{as.mo()}}, see also \link{microorganisms}
\item \code{AMX:GEN}\cr 4 different antibiotics that have to be transformed with \code{\link[=as.sir]{as.sir()}}
\item \code{AMX:GEN}\cr 4 different antimicrobials that have to be transformed with \code{\link[=as.sir]{as.sir()}}
}
}
\usage{

View File

@ -33,7 +33,7 @@ geom_sir(position = NULL, x = c("antibiotic", "interpretation"),
\item{limits}{a \link{numeric} vector of length two providing limits of the scale, use \code{NA} to refer to the existing minimum or maximum}
\item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}}
\item{translate_ab}{a column name of the \link{antimicrobials} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}}
\item{combine_SI}{a \link{logical} to indicate whether all values of S, SDD, and I must be merged into one, so the output only consists of S+SDD+I vs. R (susceptible vs. resistant) - the default is \code{TRUE}}
@ -67,9 +67,9 @@ geom_sir(position = NULL, x = c("antibiotic", "interpretation"),
Use these functions to create bar plots for AMR data analysis. All functions rely on \link[ggplot2:ggplot]{ggplot2} functions.
}
\details{
At default, the names of antibiotics will be shown on the plots using \code{\link[=ab_name]{ab_name()}}. This can be set with the \code{translate_ab} argument. See \code{\link[=count_df]{count_df()}}.
At default, the names of antimicrobials will be shown on the plots using \code{\link[=ab_name]{ab_name()}}. This can be set with the \code{translate_ab} argument. See \code{\link[=count_df]{count_df()}}.
\code{\link[=geom_sir]{geom_sir()}} will take any variable from the data that has an \code{\link{sir}} class (created with \code{\link[=as.sir]{as.sir()}}) using \code{\link[=sir_df]{sir_df()}} and will plot bars with the percentage S, I, and R. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis.
\code{\link[=geom_sir]{geom_sir()}} will take any variable from the data that has an \code{\link{sir}} class (created with \code{\link[=as.sir]{as.sir()}}) using \code{\link[=sir_df]{sir_df()}} and will plot bars with the percentage S, I, and R. The default behaviour is to have the bars stacked and to have the different antimicrobials on the x axis.
Additional functions include:
\itemize{

View File

@ -20,10 +20,10 @@ guess_ab_col(x = NULL, search_string = NULL, verbose = FALSE,
A column name of \code{x}, or \code{NULL} when no result is found.
}
\description{
This tries to find a column name in a data set based on information from the \link{antibiotics} data set. Also supports WHONET abbreviations.
This tries to find a column name in a data set based on information from the \link{antimicrobials} data set. Also supports WHONET abbreviations.
}
\details{
You can look for an antibiotic (trade) name or abbreviation and it will search \code{x} and the \link{antibiotics} data set for any column containing a name or code of that antibiotic.
You can look for an antibiotic (trade) name or abbreviation and it will search \code{x} and the \link{antimicrobials} data set for any column containing a name or code of that antibiotic.
}
\examples{
df <- data.frame(

View File

@ -8,7 +8,7 @@
A \link[tibble:tibble]{tibble} with 301 583 observations and 2 variables:
\itemize{
\item \code{mo}\cr Microorganism ID
\item \code{ab}\cr Antibiotic ID
\item \code{ab}\cr Antimcrobial ID
}
}
\usage{

View File

@ -21,7 +21,7 @@ antimicrobials_equal(y, z, type = c("points", "keyantimicrobials"),
ignore_I = TRUE, points_threshold = 2, ...)
}
\arguments{
\item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank to determine automatically}
\item{x}{a \link{data.frame} with antimicrobials columns, like \code{AMX} or \code{amox}. Can be left blank to determine automatically.}
\item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
@ -112,7 +112,7 @@ antimicrobials_equal(strainA, strainB, type = "keyantimicrobials", ignore_I = FA
\donttest{
if (require("dplyr")) {
# set key antibiotics to a new variable
# set key antimicrobials to a new variable
my_patients <- example_isolates \%>\%
mutate(keyab = key_antimicrobials(antifungal = NULL)) \%>\% # no need to define `x`
mutate(

File diff suppressed because one or more lines are too long

View File

@ -58,7 +58,7 @@ All matches are sorted descending on their matching score and for all user input
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{

View File

@ -197,7 +197,7 @@ Determination of the Gram stain (\code{\link[=mo_gramstain]{mo_gramstain()}}) wi
Determination of yeasts (\code{\link[=mo_is_yeast]{mo_is_yeast()}}) will be based on the taxonomic kingdom and class. \emph{Budding yeasts} are yeasts that reproduce asexually through a process called budding, where a new cell develops from a small protrusion on the parent cell. Taxonomically, these are members of the phylum Ascomycota, class Saccharomycetes (also called Hemiascomycetes) or Pichiomycetes. \emph{True yeasts} quite specifically refers to yeasts in the underlying order Saccharomycetales (such as \emph{Saccharomyces cerevisiae}). Thus, for all microorganisms that are member of the taxonomic class Saccharomycetes or Pichiomycetes, the function will return \code{TRUE}. It returns \code{FALSE} otherwise (or \code{NA} when the input is \code{NA} or the MO code is \code{UNKNOWN}).
Determination of intrinsic resistance (\code{\link[=mo_is_intrinsic_resistant]{mo_is_intrinsic_resistant()}}) will be based on the \link{intrinsic_resistant} data set, which is based on \href{https://www.eucast.org/expert_rules_and_expected_phenotypes}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021). The \code{\link[=mo_is_intrinsic_resistant]{mo_is_intrinsic_resistant()}} function can be vectorised over both argument \code{x} (input for microorganisms) and \code{ab} (input for antibiotics).
Determination of intrinsic resistance (\code{\link[=mo_is_intrinsic_resistant]{mo_is_intrinsic_resistant()}}) will be based on the \link{intrinsic_resistant} data set, which is based on \href{https://www.eucast.org/expert_rules_and_expected_phenotypes}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021). The \code{\link[=mo_is_intrinsic_resistant]{mo_is_intrinsic_resistant()}} function can be vectorised over both argument \code{x} (input for microorganisms) and \code{ab} (input for antimicrobials).
Determination of bacterial oxygen tolerance (\code{\link[=mo_oxygen_tolerance]{mo_oxygen_tolerance()}}) will be based on BacDive, see \emph{Source}. The function \code{\link[=mo_is_anaerobic]{mo_is_anaerobic()}} only returns \code{TRUE} if the oxygen tolerance is \code{"anaerobe"}, indicting an obligate anaerobic species or genus. It always returns \code{FALSE} for species outside the taxonomic kingdom of Bacteria.
@ -229,7 +229,7 @@ This function uses \code{\link[=as.mo]{as.mo()}} internally, which uses an advan
\section{Reference Data Publicly Available}{
All data sets in this \code{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, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
All data sets in this \code{AMR} package (about microorganisms, antimicrobials, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, 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 \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
}
\examples{

View File

@ -151,7 +151,7 @@ labels_sir_count(position = NULL, x = "antibiotic",
\item{position}{position adjustment of bars, either \code{"fill"}, \code{"stack"} or \code{"dodge"}}
\item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}}
\item{translate_ab}{a column name of the \link{antimicrobials} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}}
\item{minimum}{the minimum allowed number of available (tested) isolates. Any isolate count lower than \code{minimum} will return \code{NA} with a warning. The default number of \code{30} isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see \emph{Source}.}

View File

@ -58,7 +58,7 @@ sir_df(data, translate_ab = "name", language = get_AMR_locale(),
\item{as_percent}{a \link{logical} to indicate whether the output must be returned as a hundred fold with \% sign (a character). A value of \code{0.123456} will then be returned as \code{"12.3\%"}.}
\item{only_all_tested}{(for combination therapies, i.e. using more than one variable for \code{...}): a \link{logical} to indicate that isolates must be tested for all antibiotics, see section \emph{Combination Therapy} below}
\item{only_all_tested}{(for combination therapies, i.e. using more than one variable for \code{...}): a \link{logical} to indicate that isolates must be tested for all antimicrobials, see section \emph{Combination Therapy} below}
\item{ab_result}{antibiotic results to test against, must be one or more values of "S", "SDD", "I", or "R"}
@ -70,7 +70,7 @@ sir_df(data, translate_ab = "name", language = get_AMR_locale(),
\item{data}{a \link{data.frame} containing columns with class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}})}
\item{translate_ab}{a column name of the \link{antibiotics} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}}
\item{translate_ab}{a column name of the \link{antimicrobials} data set to translate the antibiotic abbreviations to, using \code{\link[=ab_property]{ab_property()}}}
\item{language}{language of the returned text - the default is the current system language (see \code{\link[=get_AMR_locale]{get_AMR_locale()}}) and can also be set with the package option \code{\link[=AMR-options]{AMR_locale}}. Use \code{language = NULL} or \code{language = ""} to prevent translation.}
@ -99,7 +99,7 @@ The function \code{\link[=proportion_df]{proportion_df()}} takes any variable fr
}
\section{Combination Therapy}{
When using more than one variable for \code{...} (= combination therapy), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Drug A and Drug B, about how \code{\link[=susceptibility]{susceptibility()}} works to calculate the \%SI:
When using more than one variable for \code{...} (= combination therapy), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antimicrobials, Drug A and Drug B, about how \code{\link[=susceptibility]{susceptibility()}} works to calculate the \%SI:
\if{html}{\out{<div class="sourceCode">}}\preformatted{--------------------------------------------------------------------
only_all_tested = FALSE only_all_tested = TRUE

View File

@ -30,16 +30,4 @@
library(testthat)
library(AMR)
# add functions from the tinytest package (which we use for older R versions)
expect_inherits <- function(x, y, ...) {
expect(inherits(x, y),
failure_message = paste0(
"object has class ", paste0(class(x), collapse = "/"),
", required is class ", paste0(y, collapse = "/")
)
)
}
expect_stdout <- expect_output
# start unit tests
test_check("AMR")

View File

@ -0,0 +1,38 @@
# ==================================================================== #
# TITLE: #
# AMR: An R Package for Working with Antimicrobial Resistance Data #
# #
# SOURCE CODE: #
# https://github.com/msberends/AMR #
# #
# PLEASE CITE THIS SOFTWARE AS: #
# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
# AMR: An R Package for Working with Antimicrobial Resistance Data. #
# Journal of Statistical Software, 104(3), 1-31. #
# https://doi.org/10.18637/jss.v104.i03 #
# #
# Developed at the University of Groningen and the University Medical #
# Center Groningen in The Netherlands, in collaboration with many #
# colleagues from around the world, see our website. #
# #
# 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 the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
# add functions from the tinytest package (which we use for older R versions)
expect_inherits <- function(x, y, ...) {
expect(inherits(x, y),
failure_message = paste0(
"object has class ", paste0(class(x), collapse = "/"),
", required is class ", paste0(y, collapse = "/")
)
)
}

View File

@ -27,5 +27,7 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_warning(example_isolates[, ab_class("mycobact")])
expect_warning(example_isolates[, ab_selector(name %like% "trim")])
test_that("deprecated works", {
expect_warning(example_isolates[, ab_class("mycobact")])
expect_warning(example_isolates[, ab_selector(name %like% "trim")])
})

View File

@ -27,70 +27,72 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_equal(AMR:::percentage(0.25), "25%")
expect_equal(AMR:::percentage(0.5), "50%")
expect_equal(AMR:::percentage(0.500, digits = 1), "50.0%")
expect_equal(AMR:::percentage(0.1234), "12.3%")
# round up 0.5
expect_equal(AMR:::percentage(0.0054), "0.5%")
expect_equal(AMR:::percentage(0.0055), "0.6%")
test_that("misc works", {
expect_equal(AMR:::percentage(0.25), "25%")
expect_equal(AMR:::percentage(0.5), "50%")
expect_equal(AMR:::percentage(0.500, digits = 1), "50.0%")
expect_equal(AMR:::percentage(0.1234), "12.3%")
# round up 0.5
expect_equal(AMR:::percentage(0.0054), "0.5%")
expect_equal(AMR:::percentage(0.0055), "0.6%")
# test functions on all R versions - R < 3.3 did not contain these
expect_equal(strrep("A", 5), "AAAAA")
expect_equal(strrep(c("A", "B"), c(5, 2)), c("AAAAA", "BB"))
expect_equal(trimws(" test "), "test")
expect_equal(trimws(" test ", "l"), "test ")
expect_equal(trimws(" test ", "r"), " test")
expect_equal(AMR:::trimws2(" test "), "test")
expect_equal(AMR:::trimws2(" test ", "l"), "test ")
expect_equal(AMR:::trimws2(" test ", "r"), " test")
# test functions on all R versions - R < 3.3 did not contain these
expect_equal(strrep("A", 5), "AAAAA")
expect_equal(strrep(c("A", "B"), c(5, 2)), c("AAAAA", "BB"))
expect_equal(trimws(" test "), "test")
expect_equal(trimws(" test ", "l"), "test ")
expect_equal(trimws(" test ", "r"), " test")
expect_equal(AMR:::trimws2(" test "), "test")
expect_equal(AMR:::trimws2(" test ", "l"), "test ")
expect_equal(AMR:::trimws2(" test ", "r"), " test")
expect_message(AMR:::get_column_abx(example_isolates, soft_dependencies = "FUS"))
expect_message(AMR:::get_column_abx(example_isolates, soft_dependencies = "FUS"))
# we rely on "grouped_tbl" being a class of grouped tibbles, so run a test that checks for this:
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(ward)))
}
# test get_current_data() ----
is_right <- FALSE
check_df <- function(check_element, return_val = 0) {
is_right <<- FALSE
for (env in sys.frames()) {
if (!is.null(env[[check_element]]) && is.data.frame(env[[check_element]])) {
is_right <<- TRUE
}
# we rely on "grouped_tbl" being a class of grouped tibbles, so run a test that checks for this:
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(ward)))
}
return_val
}
df <- example_isolates[, check_df("x")]
expect_true(is_right, info = "the environmental data cannot be found for base/x (1)")
if (getRversion() < "4.0.0") {
df <- example_isolates[c(1:3), check_df("xx")]
expect_true(is_right, info = "the environmental data cannot be found for base/xx")
} else {
df <- example_isolates[c(1:3), check_df("x")]
expect_true(is_right, info = "the environmental data cannot be found for base/x (2)")
}
# test get_current_data() ----
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
df <- example_isolates %>% select(mo, check_df("data123"))
expect_false(is_right, info = "just a check if non-sense is not being gathered by get_current_data()")
is_right <- FALSE
check_df <- function(check_element, return_val = 0) {
is_right <<- FALSE
for (env in sys.frames()) {
if (!is.null(env[[check_element]]) && is.data.frame(env[[check_element]])) {
is_right <<- TRUE
}
}
return_val
}
df <- example_isolates %>% select(mo, check_df(".data"))
expect_true(is_right, info = "the environmental data cannot be found for dplyr/select()")
df <- example_isolates[, check_df("x")]
expect_true(is_right, info = "the environmental data cannot be found for base/x (1)")
df <- example_isolates %>% select_at(check_df(".tbl"))
expect_true(is_right, info = "the environmental data cannot be found for dplyr/select_at()")
}
if (getRversion() < "4.0.0") {
df <- example_isolates[c(1:3), check_df("xx")]
expect_true(is_right, info = "the environmental data cannot be found for base/xx")
} else {
df <- example_isolates[c(1:3), check_df("x")]
expect_true(is_right, info = "the environmental data cannot be found for base/x (2)")
}
if (AMR:::pkg_is_available("tidymodels", also_load = TRUE)) {
resistance_recipe <- recipe(mo ~ ., data = example_isolates) %>%
step_corr(check_df("training")) %>%
prep()
expect_true(is_right, info = "the environmental data cannot be found for tidymodels/prep()")
}
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
df <- example_isolates %>% select(mo, check_df("data123"))
expect_false(is_right, info = "just a check if non-sense is not being gathered by get_current_data()")
df <- example_isolates %>% select(mo, check_df(".data"))
expect_true(is_right, info = "the environmental data cannot be found for dplyr/select()")
df <- example_isolates %>% select_at(check_df(".tbl"))
expect_true(is_right, info = "the environmental data cannot be found for dplyr/select_at()")
}
if (AMR:::pkg_is_available("tidymodels", also_load = TRUE)) {
resistance_recipe <- recipe(mo ~ ., data = example_isolates) %>%
step_corr(check_df("training")) %>%
prep()
expect_true(is_right, info = "the environmental data cannot be found for tidymodels/prep()")
}
})

View File

@ -27,80 +27,82 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
ab_reset_session()
test_that("ab works", {
ab_reset_session()
expect_equal(
as.character(as.ab(c(
"J01FA01",
"J 01 FA 01",
"Erythromycin",
"eryt",
"ERYT",
"ERY",
"erytromicine",
"Erythrocin",
"Romycin"
))),
rep("ERY", 9)
)
expect_equal(
as.character(as.ab(c(
"J01FA01",
"J 01 FA 01",
"Erythromycin",
"eryt",
"ERYT",
"ERY",
"erytromicine",
"Erythrocin",
"Romycin"
))),
rep("ERY", 9)
)
expect_identical(class(as.ab("amox")), c("ab", "character"))
expect_identical(class(antibiotics$ab), c("ab", "character"))
expect_true(is.ab(as.ab("amox")))
expect_stdout(print(as.ab("amox")))
expect_stdout(print(data.frame(a = as.ab("amox"))))
expect_identical(class(as.ab("amox")), c("ab", "character"))
expect_identical(class(AMR::antimicrobials$ab), c("ab", "character"))
expect_true(is.ab(as.ab("amox")))
expect_output(print(as.ab("amox")))
expect_output(print(data.frame(a = as.ab("amox"))))
expect_warning(as.ab("J00AA00")) # ATC not yet available in data set
# expect_warning(as.ab("UNKNOWN"))
expect_warning(as.ab("J00AA00")) # ATC not yet available in data set
# expect_warning(as.ab("UNKNOWN"))
expect_stdout(print(as.ab("amox")))
expect_output(print(as.ab("amox")))
expect_equal(
as.character(as.ab("Phloxapen")),
"FLC"
)
expect_equal(
as.character(as.ab("Phloxapen")),
"FLC"
)
expect_equal(
suppressWarnings(as.character(as.ab(c("Bacteria", "Bacterial")))),
c(NA, "TMP")
)
expect_equal(
suppressWarnings(as.character(as.ab(c("Bacteria", "Bacterial")))),
c(NA, "TMP")
)
expect_equal(
as.character(as.ab("Amoxy + clavulaanzuur")),
"AMC"
)
expect_equal(
as.character(as.ab("Amoxy + clavulaanzuur")),
"AMC"
)
expect_equal(
as.character(as.ab(c("mreopenem", "co-maoxiclav"))),
c("MEM", "AMC")
)
expect_equal(
as.character(as.ab(c("mreopenem", "co-maoxiclav"))),
c("MEM", "AMC")
)
# expect_warning(as.ab("cipro mero"))
# expect_warning(as.ab("cipro mero"))
# based on Levenshtein distance
expect_identical(ab_name("ceftazidim/avibactam", language = NULL), "Ceftazidime/avibactam")
# based on Levenshtein distance
expect_identical(ab_name("ceftazidim/avibactam", language = NULL), "Ceftazidime/avibactam")
expect_identical(
as.character(as.ab(c(
"gentamicine High Level",
"gentamicine High",
"gentamicine (High Level)",
"gentamicine (High)",
"gentamicine HL",
"gentamicine H-L",
"gentamicine (HL)",
"gentamicine (H-L)"
))),
rep("GEH", 8)
)
expect_identical(
as.character(as.ab(c(
"gentamicine High Level",
"gentamicine High",
"gentamicine (High Level)",
"gentamicine (High)",
"gentamicine HL",
"gentamicine H-L",
"gentamicine (HL)",
"gentamicine (H-L)"
))),
rep("GEH", 8)
)
# assigning and subsetting
x <- antibiotics$ab
expect_inherits(x[1], "ab")
expect_inherits(x[[1]], "ab")
expect_inherits(c(x[1], x[9]), "ab")
expect_inherits(unique(x[1], x[9]), "ab")
expect_inherits(rep(x[1], 2), "ab")
# expect_warning(x[1] <- "invalid code")
# expect_warning(x[[1]] <- "invalid code")
# expect_warning(c(x[1], "test"))
# assigning and subsetting
x <- AMR::antimicrobials$ab
expect_inherits(x[1], "ab")
expect_inherits(x[[1]], "ab")
expect_inherits(c(x[1], x[9]), "ab")
expect_inherits(unique(x[1], x[9]), "ab")
expect_inherits(rep(x[1], 2), "ab")
# expect_warning(x[1] <- "invalid code")
# expect_warning(x[[1]] <- "invalid code")
# expect_warning(c(x[1], "test"))
})

View File

@ -27,34 +27,36 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
ab_reset_session()
test_that("ab_from_text works", {
ab_reset_session()
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds")[[1]],
as.ab("Amoxicillin")
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", thorough_search = TRUE)[[1]],
as.ab("Amoxicillin")
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", thorough_search = FALSE)[[1]],
as.ab("Amoxicillin")
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", translate_ab = TRUE)[[1]],
"Amoxicillin"
)
expect_identical(
ab_from_text("administered amoxi/clav and cipro", collapse = ", ")[[1]],
"AMC, CIP"
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds")[[1]],
as.ab("Amoxicillin")
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", thorough_search = TRUE)[[1]],
as.ab("Amoxicillin")
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", thorough_search = FALSE)[[1]],
as.ab("Amoxicillin")
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", translate_ab = TRUE)[[1]],
"Amoxicillin"
)
expect_identical(
ab_from_text("administered amoxi/clav and cipro", collapse = ", ")[[1]],
"AMC, CIP"
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", type = "dose")[[1]],
500
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", type = "admin")[[1]],
"oral"
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", type = "dose")[[1]],
500
)
expect_identical(
ab_from_text("28/03/2020 amoxicilliin 500mg po tds", type = "admin")[[1]],
"oral"
)
})

View File

@ -27,72 +27,74 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
ab_reset_session()
test_that("ab_property works", {
ab_reset_session()
expect_identical(ab_name("AMX", language = NULL), "Amoxicillin")
expect_identical(ab_atc("AMX"), "J01CA04")
expect_identical(ab_cid("AMX"), as.integer(33613))
expect_identical(ab_name("AMX", language = NULL), "Amoxicillin")
expect_identical(ab_atc("AMX"), "J01CA04")
expect_identical(ab_cid("AMX"), as.integer(33613))
expect_inherits(ab_tradenames("AMX"), "character")
expect_inherits(ab_tradenames(c("AMX", "AMX")), "list")
expect_inherits(ab_tradenames("AMX"), "character")
expect_inherits(ab_tradenames(c("AMX", "AMX")), "list")
expect_identical(ab_group("AMX", language = NULL), "Beta-lactams/penicillins")
expect_identical(ab_atc_group1("AMX", language = NULL), "Beta-lactam antibacterials, penicillins")
expect_identical(ab_atc_group2("AMX", language = NULL), "Penicillins with extended spectrum")
expect_identical(ab_group("AMX", language = NULL), "Beta-lactams/penicillins")
expect_identical(ab_atc_group1("AMX", language = NULL), "Beta-lactam antibacterials, penicillins")
expect_identical(ab_atc_group2("AMX", language = NULL), "Penicillins with extended spectrum")
expect_identical(ab_name("Fluclox", language = NULL), "Flucloxacillin")
expect_identical(ab_name("fluklox", language = NULL), "Flucloxacillin")
expect_identical(ab_name("floxapen", language = NULL), "Flucloxacillin")
expect_identical(ab_name(21319, language = NULL), "Flucloxacillin")
expect_identical(ab_name("J01CF05", language = NULL), "Flucloxacillin")
expect_identical(ab_name("Fluclox", language = NULL), "Flucloxacillin")
expect_identical(ab_name("fluklox", language = NULL), "Flucloxacillin")
expect_identical(ab_name("floxapen", language = NULL), "Flucloxacillin")
expect_identical(ab_name(21319, language = NULL), "Flucloxacillin")
expect_identical(ab_name("J01CF05", language = NULL), "Flucloxacillin")
expect_identical(ab_ddd("AMX", "oral"), 1.5)
expect_identical(ab_ddd_units("AMX", "iv"), "g")
expect_identical(ab_ddd("AMX", "iv"), 3)
expect_identical(ab_ddd("AMX", "oral"), 1.5)
expect_identical(ab_ddd_units("AMX", "iv"), "g")
expect_identical(ab_ddd("AMX", "iv"), 3)
expect_identical(ab_name(x = c("AMC", "PLB"), language = NULL), c("Amoxicillin/clavulanic acid", "Polymyxin B"))
expect_identical(
ab_name(x = c("AMC", "PLB"), tolower = TRUE, language = NULL),
c("amoxicillin/clavulanic acid", "polymyxin B")
)
expect_inherits(ab_info("AMX"), "list")
expect_error(ab_property("amox", "invalid property"))
expect_error(ab_name("amox", language = "INVALID"))
expect_stdout(print(ab_name("amox", language = NULL)))
expect_equal(ab_name("21066-6", language = NULL), "Ampicillin")
expect_equal(
ab_loinc("ampicillin"),
c("101477-8", "101478-6", "18864-9", "18865-6", "20374-5", "21066-6", "23618-2", "27-3", "28-1", "29-9", "30-7", "31-5", "32-3", "33-1", "3355-5", "33562-0", "33919-2", "34-9", "43883-8", "43884-6", "6979-9", "6980-7", "87604-5")
)
expect_true(ab_url("AMX") %like% "fhi[.]no")
expect_identical(
colnames(set_ab_names(example_isolates[, 17:22])),
c("cefoxitin", "cefotaxime", "ceftazidime", "ceftriaxone", "gentamicin", "tobramycin")
)
expect_identical(
colnames(set_ab_names(example_isolates[, 17:22], language = "nl", snake_case = FALSE)),
c("Cefoxitine", "Cefotaxim", "Ceftazidim", "Ceftriaxon", "Gentamicine", "Tobramycine")
)
expect_identical(
colnames(set_ab_names(example_isolates[, 17:22], property = "atc")),
c("J01DC01", "J01DD01", "J01DD02", "J01DD04", "J01GB03", "J01GB01")
)
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_identical(ab_name(x = c("AMC", "PLB"), language = NULL), c("Amoxicillin/clavulanic acid", "Polymyxin B"))
expect_identical(
example_isolates %>% set_ab_names(),
example_isolates %>% rename_with(set_ab_names)
ab_name(x = c("AMC", "PLB"), tolower = TRUE, language = NULL),
c("amoxicillin/clavulanic acid", "polymyxin B")
)
expect_true(all(c(
"SXT", "nitrofurantoin", "fosfomycin", "linezolid", "ciprofloxacin",
"moxifloxacin", "vancomycin", "TEC"
) %in%
(example_isolates %>%
set_ab_names(NIT:VAN) %>%
colnames())))
}
expect_inherits(ab_info("AMX"), "list")
expect_error(ab_property("amox", "invalid property"))
expect_error(ab_name("amox", language = "INVALID"))
expect_output(print(ab_name("amox", language = NULL)))
expect_equal(ab_name("21066-6", language = NULL), "Ampicillin")
expect_equal(
ab_loinc("ampicillin"),
c("101477-8", "101478-6", "18864-9", "18865-6", "20374-5", "21066-6", "23618-2", "27-3", "28-1", "29-9", "30-7", "31-5", "32-3", "33-1", "3355-5", "33562-0", "33919-2", "34-9", "43883-8", "43884-6", "6979-9", "6980-7", "87604-5")
)
expect_true(ab_url("AMX") %like% "fhi[.]no")
expect_identical(
colnames(set_ab_names(example_isolates[, 17:22])),
c("cefoxitin", "cefotaxime", "ceftazidime", "ceftriaxone", "gentamicin", "tobramycin")
)
expect_identical(
colnames(set_ab_names(example_isolates[, 17:22], language = "nl", snake_case = FALSE)),
c("Cefoxitine", "Cefotaxim", "Ceftazidim", "Ceftriaxon", "Gentamicine", "Tobramycine")
)
expect_identical(
colnames(set_ab_names(example_isolates[, 17:22], property = "atc")),
c("J01DC01", "J01DD01", "J01DD02", "J01DD04", "J01GB03", "J01GB01")
)
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_identical(
example_isolates %>% set_ab_names(),
example_isolates %>% rename_with(set_ab_names)
)
expect_true(all(c(
"SXT", "nitrofurantoin", "fosfomycin", "linezolid", "ciprofloxacin",
"moxifloxacin", "vancomycin", "TEC"
) %in%
(example_isolates %>%
set_ab_names(NIT:VAN) %>%
colnames())))
}
})

View File

@ -27,69 +27,71 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_equal(
age(
test_that("age works", {
expect_equal(
age(
x = c("1980-01-01", "1985-01-01", "1990-01-01"),
reference = "2019-01-01"
),
c(39, 34, 29)
)
expect_equal(
age(
x = c("2019-01-01", "2019-04-01", "2019-07-01"),
reference = "2019-09-01",
exact = TRUE
),
c(0.6656393, 0.4191781, 0.1698630),
tolerance = 0.001
)
expect_error(age(
x = c("1980-01-01", "1985-01-01", "1990-01-01"),
reference = "2019-01-01"
),
c(39, 34, 29)
)
reference = c("2019-01-01", "2019-01-01")
))
expect_equal(
age(
x = c("2019-01-01", "2019-04-01", "2019-07-01"),
reference = "2019-09-01",
exact = TRUE
),
c(0.6656393, 0.4191781, 0.1698630),
tolerance = 0.001
)
# expect_warning(age(x = c("1980-01-01", "1985-01-01", "1990-01-01"), reference = "1975-01-01"))
# expect_warning(age(x = c("1800-01-01", "1805-01-01", "1810-01-01"), reference = "2019-01-01"))
expect_error(age(
x = c("1980-01-01", "1985-01-01", "1990-01-01"),
reference = c("2019-01-01", "2019-01-01")
))
# expect_warning(age(x = c("1980-01-01", "1985-01-01", "1990-01-01"), reference = "1975-01-01"))
# expect_warning(age(x = c("1800-01-01", "1805-01-01", "1810-01-01"), reference = "2019-01-01"))
expect_equal(
length(age(x = c("2019-01-01", NA), na.rm = TRUE)),
1
)
expect_equal(
length(age(x = c("2019-01-01", NA), na.rm = TRUE)),
1
)
ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21)
ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21)
expect_equal(
length(unique(age_groups(ages, 50))),
2
)
expect_equal(
length(unique(age_groups(ages, c(50, 60)))),
3
)
expect_identical(
class(age_groups(ages, "child")),
c("ordered", "factor")
)
expect_equal(
length(unique(age_groups(ages, 50))),
2
)
expect_equal(
length(unique(age_groups(ages, c(50, 60)))),
3
)
expect_identical(
class(age_groups(ages, "child")),
c("ordered", "factor")
)
expect_identical(
class(age_groups(ages, "elderly")),
c("ordered", "factor")
)
expect_identical(
class(age_groups(ages, "elderly")),
c("ordered", "factor")
)
expect_identical(
class(age_groups(ages, "tens")),
c("ordered", "factor")
)
expect_identical(
class(age_groups(ages, "tens")),
c("ordered", "factor")
)
expect_identical(
class(age_groups(ages, "fives")),
c("ordered", "factor")
)
expect_identical(
class(age_groups(ages, "fives")),
c("ordered", "factor")
)
expect_equal(
length(age_groups(c(10, 20, 30, NA), na.rm = TRUE)),
3
)
expect_equal(
length(age_groups(c(10, 20, 30, NA), na.rm = TRUE)),
3
)
})

View File

@ -27,90 +27,92 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
# antibiotic class selectors
expect_equal(ncol(example_isolates[, amr_class("antimyco"), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, amr_selector(name %like% "trim"), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, aminoglycosides(), drop = FALSE]), 4, tolerance = 0.5)
expect_equal(ncol(example_isolates[, aminopenicillins(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, betalactams(), drop = FALSE]), 16, tolerance = 0.5)
expect_equal(ncol(example_isolates[, carbapenems(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins(), drop = FALSE]), 7, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_1st(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_2nd(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_3rd(), drop = FALSE]), 3, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_4th(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_5th(), drop = FALSE]), 0, tolerance = 0.5)
expect_equal(ncol(example_isolates[, fluoroquinolones(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, glycopeptides(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, isoxazolylpenicillins(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, lincosamides(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, lipoglycopeptides(), drop = FALSE]), 0, tolerance = 0.5)
expect_equal(ncol(example_isolates[, macrolides(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, monobactams(), drop = FALSE]), 0, tolerance = 0.5)
expect_equal(ncol(example_isolates[, nitrofurans(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, oxazolidinones(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, penicillins(), drop = FALSE]), 7, tolerance = 0.5)
expect_equal(ncol(example_isolates[, phenicols(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, polymyxins(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, rifamycins(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, streptogramins(), drop = FALSE]), 0, tolerance = 0.5)
expect_equal(ncol(example_isolates[, quinolones(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, tetracyclines(), drop = FALSE]), 3, tolerance = 0.5)
expect_equal(ncol(example_isolates[, trimethoprims(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, ureidopenicillins(), drop = FALSE]), 1, tolerance = 0.5)
test_that("amr selectors works", {
# antibiotic class selectors
expect_equal(ncol(example_isolates[, amr_class("antimyco"), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, amr_selector(name %like% "trim"), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, aminoglycosides(), drop = FALSE]), 4, tolerance = 0.5)
expect_equal(ncol(example_isolates[, aminopenicillins(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, betalactams(), drop = FALSE]), 16, tolerance = 0.5)
expect_equal(ncol(example_isolates[, carbapenems(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins(), drop = FALSE]), 7, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_1st(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_2nd(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_3rd(), drop = FALSE]), 3, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_4th(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, cephalosporins_5th(), drop = FALSE]), 0, tolerance = 0.5)
expect_equal(ncol(example_isolates[, fluoroquinolones(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, glycopeptides(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, isoxazolylpenicillins(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, lincosamides(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, lipoglycopeptides(), drop = FALSE]), 0, tolerance = 0.5)
expect_equal(ncol(example_isolates[, macrolides(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, monobactams(), drop = FALSE]), 0, tolerance = 0.5)
expect_equal(ncol(example_isolates[, nitrofurans(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, oxazolidinones(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, penicillins(), drop = FALSE]), 7, tolerance = 0.5)
expect_equal(ncol(example_isolates[, phenicols(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, polymyxins(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, rifamycins(), drop = FALSE]), 1, tolerance = 0.5)
expect_equal(ncol(example_isolates[, streptogramins(), drop = FALSE]), 0, tolerance = 0.5)
expect_equal(ncol(example_isolates[, quinolones(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, tetracyclines(), drop = FALSE]), 3, tolerance = 0.5)
expect_equal(ncol(example_isolates[, trimethoprims(), drop = FALSE]), 2, tolerance = 0.5)
expect_equal(ncol(example_isolates[, ureidopenicillins(), drop = FALSE]), 1, tolerance = 0.5)
expect_message(expect_stdout(print(carbapenems())))
expect_error(administrable_per_os())
expect_message(expect_output(print(carbapenems())))
expect_error(administrable_per_os())
# Examples:
# Examples:
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
expect_equal(ncol(example_isolates[, c("mo", aminoglycosides())]), 5, tolerance = 0.5)
# select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB'
expect_equal(ncol(example_isolates[, c("mo", aminoglycosides())]), 5, tolerance = 0.5)
expect_equal(ncol(example_isolates[, c(administrable_per_os() & penicillins())]), 5, tolerance = 0.5)
expect_equal(ncol(example_isolates[, c(administrable_iv() & penicillins())]), 7, tolerance = 0.5)
expect_equal(ncol(example_isolates[, c(administrable_iv() | penicillins())]), 37, tolerance = 0.5)
expect_equal(ncol(example_isolates[, c(administrable_per_os() & penicillins())]), 5, tolerance = 0.5)
expect_equal(ncol(example_isolates[, c(administrable_iv() & penicillins())]), 7, tolerance = 0.5)
expect_equal(ncol(example_isolates[, c(administrable_iv() | penicillins())]), 37, tolerance = 0.5)
# filter using any() or all()
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), ]), 55, tolerance = 0.5)
expect_equal(nrow(subset(example_isolates, any(carbapenems() == "R"))), 55, tolerance = 0.5)
# filter using any() or all()
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), ]), 55, tolerance = 0.5)
expect_equal(nrow(subset(example_isolates, any(carbapenems() == "R"))), 55, tolerance = 0.5)
# filter on any or all results in the carbapenem columns (i.e., IPM, MEM):
expect_equal(nrow(example_isolates[any(carbapenems()), ]), 962, tolerance = 0.5)
expect_equal(nrow(example_isolates[all(carbapenems()), ]), 756, tolerance = 0.5)
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), ]), 55, tolerance = 0.5)
expect_equal(nrow(example_isolates[any(carbapenems() != "R"), ]), 910, tolerance = 0.5)
expect_equal(nrow(example_isolates[carbapenems() != "R", ]), 704, tolerance = 0.5)
# filter on any or all results in the carbapenem columns (i.e., IPM, MEM):
expect_equal(nrow(example_isolates[any(carbapenems()), ]), 962, tolerance = 0.5)
expect_equal(nrow(example_isolates[all(carbapenems()), ]), 756, tolerance = 0.5)
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), ]), 55, tolerance = 0.5)
expect_equal(nrow(example_isolates[any(carbapenems() != "R"), ]), 910, tolerance = 0.5)
expect_equal(nrow(example_isolates[carbapenems() != "R", ]), 704, tolerance = 0.5)
# filter with multiple antibiotic selectors using c()
expect_equal(nrow(example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]), 26, tolerance = 0.5)
# filter with multiple antibiotic selectors using c()
expect_equal(nrow(example_isolates[all(c(carbapenems(), aminoglycosides()) == "R"), ]), 26, tolerance = 0.5)
# filter + select in one go: get penicillins in carbapenems-resistant strains
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), penicillins()]), 55, tolerance = 0.5)
expect_equal(ncol(example_isolates[any(carbapenems() == "R"), penicillins()]), 7, tolerance = 0.5)
# filter + select in one go: get penicillins in carbapenems-resistant strains
expect_equal(nrow(example_isolates[any(carbapenems() == "R"), penicillins()]), 55, tolerance = 0.5)
expect_equal(ncol(example_isolates[any(carbapenems() == "R"), penicillins()]), 7, tolerance = 0.5)
x <- data.frame(
x = 0,
mo = 0,
gen = "S",
genta = "S",
J01GB03 = "S",
tobra = "S",
Tobracin = "S"
)
# should have the first hits
expect_identical(
colnames(x[, aminoglycosides(return_all = FALSE)]),
c("gen", "tobra")
)
expect_identical(
colnames(x[, aminoglycosides()]),
c("gen", "genta", "J01GB03", "tobra", "Tobracin")
)
x <- data.frame(
x = 0,
mo = 0,
gen = "S",
genta = "S",
J01GB03 = "S",
tobra = "S",
Tobracin = "S"
)
# should have the first hits
expect_identical(
colnames(x[, aminoglycosides(return_all = FALSE)]),
c("gen", "tobra")
)
expect_identical(
colnames(x[, aminoglycosides()]),
c("gen", "genta", "J01GB03", "tobra", "Tobracin")
)
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_equal(example_isolates %>% select(administrable_per_os() & penicillins()) %>% ncol(), 5, tolerance = 0.5)
expect_equal(example_isolates %>% select(administrable_iv() & penicillins()) %>% ncol(), 7, tolerance = 0.5)
expect_equal(example_isolates %>% select(administrable_iv() | penicillins()) %>% ncol(), 37, tolerance = 0.5)
# expect_warning(example_isolates %>% select(GEH = GEN) %>% select(aminoglycosides(only_treatable = TRUE)))
}
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_equal(example_isolates %>% select(administrable_per_os() & penicillins()) %>% ncol(), 5, tolerance = 0.5)
expect_equal(example_isolates %>% select(administrable_iv() & penicillins()) %>% ncol(), 7, tolerance = 0.5)
expect_equal(example_isolates %>% select(administrable_iv() | penicillins()) %>% ncol(), 37, tolerance = 0.5)
# expect_warning(example_isolates %>% select(GEH = GEN) %>% select(aminoglycosides(only_treatable = TRUE)))
}
})

View File

@ -27,130 +27,131 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
test_that("antibiogram works", {
# Traditional antibiogram ----------------------------------------------
# Traditional antibiogram ----------------------------------------------
ab1 <- antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems())
)
ab1 <- antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems())
)
ab2 <- antibiogram(example_isolates,
antibiotics = aminoglycosides(),
ab_transform = "atc",
mo_transform = "gramstain",
add_total_n = TRUE
)
ab2 <- antibiogram(example_isolates,
antibiotics = aminoglycosides(),
ab_transform = "atc",
mo_transform = "gramstain",
add_total_n = TRUE
)
ab3 <- antibiogram(example_isolates,
antibiotics = carbapenems(),
ab_transform = "ab",
mo_transform = "name",
formatting_type = 1
)
ab3 <- antibiogram(example_isolates,
antibiotics = carbapenems(),
ab_transform = "ab",
mo_transform = "name",
formatting_type = 1
)
expect_inherits(ab1, "antibiogram")
expect_inherits(ab2, "antibiogram")
expect_inherits(ab3, "antibiogram")
expect_equal(colnames(ab1), c("Pathogen", "Amikacin", "Gentamicin", "Imipenem", "Kanamycin", "Meropenem", "Tobramycin"))
expect_equal(colnames(ab2), c("Pathogen (N min-max)", "J01GB01", "J01GB03", "J01GB04", "J01GB06"))
expect_equal(colnames(ab3), c("Pathogen", "IPM", "MEM"))
expect_equal(ab3$MEM, c(52, NA, 100, 100, NA))
expect_inherits(ab1, "antibiogram")
expect_inherits(ab2, "antibiogram")
expect_inherits(ab3, "antibiogram")
expect_equal(colnames(ab1), c("Pathogen", "Amikacin", "Gentamicin", "Imipenem", "Kanamycin", "Meropenem", "Tobramycin"))
expect_equal(colnames(ab2), c("Pathogen (N min-max)", "J01GB01", "J01GB03", "J01GB04", "J01GB06"))
expect_equal(colnames(ab3), c("Pathogen", "IPM", "MEM"))
expect_equal(ab3$MEM, c(52, NA, 100, 100, NA))
# Combined antibiogram -------------------------------------------------
# Combined antibiogram -------------------------------------------------
# combined antibiotics yield higher empiric coverage
ab4 <- antibiogram(example_isolates,
antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
mo_transform = "gramstain"
)
# combined antibiotics yield higher empiric coverage
ab4 <- antibiogram(example_isolates,
antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
mo_transform = "gramstain"
)
ab5 <- antibiogram(example_isolates,
antibiotics = c("TZP", "TZP+TOB"),
mo_transform = "gramstain",
ab_transform = "name",
sep = " & ",
add_total_n = FALSE
)
ab5 <- antibiogram(example_isolates,
antibiotics = c("TZP", "TZP+TOB"),
mo_transform = "gramstain",
ab_transform = "name",
sep = " & ",
add_total_n = FALSE
)
expect_inherits(ab4, "antibiogram")
expect_inherits(ab5, "antibiogram")
expect_equal(colnames(ab4), c("Pathogen", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
expect_equal(colnames(ab5), c("Pathogen", "Piperacillin/tazobactam", "Piperacillin/tazobactam & Tobramycin"))
expect_inherits(ab4, "antibiogram")
expect_inherits(ab5, "antibiogram")
expect_equal(colnames(ab4), c("Pathogen", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
expect_equal(colnames(ab5), c("Pathogen", "Piperacillin/tazobactam", "Piperacillin/tazobactam & Tobramycin"))
# Syndromic antibiogram ------------------------------------------------
# Syndromic antibiogram ------------------------------------------------
# the data set could contain a filter for e.g. respiratory specimens
ab6 <- antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems()),
syndromic_group = "ward",
ab_transform = NULL
)
# the data set could contain a filter for e.g. respiratory specimens
ab6 <- antibiogram(example_isolates,
antibiotics = c(aminoglycosides(), carbapenems()),
syndromic_group = "ward",
ab_transform = NULL
)
# with a custom language, though this will be determined automatically
# (i.e., this table will be in Dutch on Dutch systems)
ex1 <- example_isolates[which(mo_genus() == "Escherichia"), ]
ab7 <- antibiogram(ex1,
antibiotics = aminoglycosides(),
ab_transform = "name",
syndromic_group = ifelse(ex1$ward == "ICU",
"IC", "Geen IC"
),
language = "nl",
add_total_n = TRUE
)
# with a custom language, though this will be determined automatically
# (i.e., this table will be in Dutch on Dutch systems)
ex1 <- example_isolates[which(mo_genus() == "Escherichia"), ]
ab7 <- antibiogram(ex1,
antibiotics = aminoglycosides(),
ab_transform = "name",
syndromic_group = ifelse(ex1$ward == "ICU",
"IC", "Geen IC"
),
language = "nl",
add_total_n = TRUE
)
expect_inherits(ab6, "antibiogram")
expect_inherits(ab7, "antibiogram")
expect_equal(colnames(ab6), c("Syndromic Group", "Pathogen", "AMK", "GEN", "IPM", "KAN", "MEM", "TOB"))
expect_equal(colnames(ab7), c("Syndroomgroep", "Pathogeen (N min-max)", "Amikacine", "Gentamicine", "Tobramycine"))
expect_inherits(ab6, "antibiogram")
expect_inherits(ab7, "antibiogram")
expect_equal(colnames(ab6), c("Syndromic Group", "Pathogen", "AMK", "GEN", "IPM", "KAN", "MEM", "TOB"))
expect_equal(colnames(ab7), c("Syndroomgroep", "Pathogeen (N min-max)", "Amikacine", "Gentamicine", "Tobramycine"))
# Weighted-incidence syndromic combination antibiogram (WISCA) ---------
# Weighted-incidence syndromic combination antibiogram (WISCA) ---------
# the data set could contain a filter for e.g. respiratory specimens
ab8 <- suppressWarnings(antibiogram(example_isolates,
antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
wisca = TRUE
))
# the data set could contain a filter for e.g. respiratory specimens
ab8 <- suppressWarnings(antibiogram(example_isolates,
antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
wisca = TRUE
))
expect_inherits(ab8, "antibiogram")
expect_equal(colnames(ab8), c("Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
expect_inherits(ab8, "antibiogram")
expect_equal(colnames(ab8), c("Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
# grouped tibbles
# grouped tibbles
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
ab9 <- example_isolates %>%
group_by(ward, gender) %>%
wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
expect_equal(colnames(ab9), c("ward", "gender", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
}
# Generate plots with ggplot2 or base R --------------------------------
pdf(NULL) # prevent Rplots.pdf being created
expect_silent(plot(ab1))
expect_silent(plot(ab2))
expect_silent(plot(ab3))
expect_silent(plot(ab4))
expect_silent(plot(ab5))
expect_silent(plot(ab6))
expect_silent(plot(ab7))
expect_silent(plot(ab8))
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_silent(plot(ab9))
}
if (AMR:::pkg_is_available("ggplot2")) {
expect_inherits(ggplot2::autoplot(ab1), "gg")
expect_inherits(ggplot2::autoplot(ab2), "gg")
expect_inherits(ggplot2::autoplot(ab3), "gg")
expect_inherits(ggplot2::autoplot(ab4), "gg")
expect_inherits(ggplot2::autoplot(ab5), "gg")
expect_inherits(ggplot2::autoplot(ab6), "gg")
expect_inherits(ggplot2::autoplot(ab7), "gg")
expect_inherits(ggplot2::autoplot(ab8), "gg")
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_inherits(ggplot2::autoplot(ab9), "gg")
ab9 <- example_isolates %>%
group_by(ward, gender) %>%
wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
expect_equal(colnames(ab9), c("ward", "gender", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
}
}
# Generate plots with ggplot2 or base R --------------------------------
pdf(NULL) # prevent Rplots.pdf being created
expect_silent(plot(ab1))
expect_silent(plot(ab2))
expect_silent(plot(ab3))
expect_silent(plot(ab4))
expect_silent(plot(ab5))
expect_silent(plot(ab6))
expect_silent(plot(ab7))
expect_silent(plot(ab8))
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_silent(plot(ab9))
}
if (AMR:::pkg_is_available("ggplot2")) {
expect_inherits(ggplot2::autoplot(ab1), "gg")
expect_inherits(ggplot2::autoplot(ab2), "gg")
expect_inherits(ggplot2::autoplot(ab3), "gg")
expect_inherits(ggplot2::autoplot(ab4), "gg")
expect_inherits(ggplot2::autoplot(ab5), "gg")
expect_inherits(ggplot2::autoplot(ab6), "gg")
expect_inherits(ggplot2::autoplot(ab7), "gg")
expect_inherits(ggplot2::autoplot(ab8), "gg")
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
expect_inherits(ggplot2::autoplot(ab9), "gg")
}
}
})

View File

@ -27,12 +27,14 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
if (AMR:::pkg_is_available("curl") &&
AMR:::pkg_is_available("rvest") &&
AMR:::pkg_is_available("xml2") &&
tryCatch(curl::has_internet(), error = function(e) FALSE)) {
expect_true(length(atc_online_groups(ab_atc("AMX"))) >= 1)
expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "O"), 1.5)
expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "P"), 3)
expect_equal(atc_online_ddd_units("AMX", administration = "P"), "g")
}
test_that("atc_online works", {
if (AMR:::pkg_is_available("curl") &&
AMR:::pkg_is_available("rvest") &&
AMR:::pkg_is_available("xml2") &&
tryCatch(curl::has_internet(), error = function(e) FALSE)) {
expect_true(length(atc_online_groups(ab_atc("AMX"))) >= 1)
expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "O"), 1.5)
expect_equal(atc_online_ddd(ab_atc("AMX"), administration = "P"), 3)
expect_equal(atc_online_ddd_units("AMX", administration = "P"), "g")
}
})

View File

@ -27,54 +27,56 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_equal(
as.character(as.av(c(
"J05AB01",
"J 05 AB 01",
"Aciclovir",
"aciclo",
" aciclo 123",
"ACICL",
"ACI",
"Virorax",
"Zovirax"
))),
rep("ACI", 9)
)
test_that("av works", {
expect_equal(
as.character(as.av(c(
"J05AB01",
"J 05 AB 01",
"Aciclovir",
"aciclo",
" aciclo 123",
"ACICL",
"ACI",
"Virorax",
"Zovirax"
))),
rep("ACI", 9)
)
expect_identical(class(as.av("acic")), c("av", "character"))
expect_identical(class(antivirals$av), c("av", "character"))
expect_true(is.av(as.av("acic")))
expect_stdout(print(as.av("acic")))
expect_stdout(print(data.frame(a = as.av("acic"))))
expect_identical(class(as.av("acic")), c("av", "character"))
expect_identical(class(antivirals$av), c("av", "character"))
expect_true(is.av(as.av("acic")))
expect_output(print(as.av("acic")))
expect_output(print(data.frame(a = as.av("acic"))))
# expect_warning(as.av("J00AA00")) # ATC not yet available in data set
# expect_warning(as.av("UNKNOWN"))
# expect_warning(as.av("J00AA00")) # ATC not yet available in data set
# expect_warning(as.av("UNKNOWN"))
expect_stdout(print(as.av("acic")))
expect_output(print(as.av("acic")))
expect_equal(
as.character(as.av("zovirax")),
"ACI"
)
expect_equal(
as.character(as.av("zovirax")),
"ACI"
)
expect_equal(
as.character(as.av(c("Abacaivr", "Celvudine"))),
c("ABA", "CLE")
)
expect_equal(
as.character(as.av(c("Abacaivr", "Celvudine"))),
c("ABA", "CLE")
)
# expect_warning(as.av("Abacavir Clevudine"))
# expect_warning(as.av("Abacavir Clevudine"))
# based on Levenshtein distance
expect_identical(av_name("adevofir dypifo", language = NULL), "Adefovir dipivoxil")
# based on Levenshtein distance
expect_identical(av_name("adevofir dypifo", language = NULL), "Adefovir dipivoxil")
# assigning and subsetting
x <- antivirals$av
expect_inherits(x[1], "av")
expect_inherits(x[[1]], "av")
expect_inherits(c(x[1], x[9]), "av")
expect_inherits(unique(x[1], x[9]), "av")
expect_inherits(rep(x[1], 2), "av")
# expect_warning(x[1] <- "invalid code")
# expect_warning(x[[1]] <- "invalid code")
# expect_warning(c(x[1], "test"))
# assigning and subsetting
x <- antivirals$av
expect_inherits(x[1], "av")
expect_inherits(x[[1]], "av")
expect_inherits(c(x[1], x[9]), "av")
expect_inherits(unique(x[1], x[9]), "av")
expect_inherits(rep(x[1], 2), "av")
# expect_warning(x[1] <- "invalid code")
# expect_warning(x[[1]] <- "invalid code")
# expect_warning(c(x[1], "test"))
})

View File

@ -27,32 +27,34 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_identical(
av_from_text("28/03/2020 regular aciclovir 500mg po tds")[[1]],
as.av("Aciclovir")
)
expect_identical(
av_from_text("28/03/2020 regular aciclovir 500mg po tds", thorough_search = TRUE)[[1]],
as.av("Aciclovir")
)
expect_identical(
av_from_text("28/03/2020 regular aciclovir 500mg po tds", thorough_search = FALSE)[[1]],
as.av("Aciclovir")
)
expect_identical(
av_from_text("28/03/2020 regular aciclovir 500mg po tds", translate_av = TRUE)[[1]],
"Aciclovir"
)
expect_identical(
av_from_text("administered aciclo and valaciclo", collapse = ", ")[[1]],
"ACI, VALA"
)
test_that("av_from_text works", {
expect_identical(
av_from_text("28/03/2020 regular aciclovir 500mg po tds")[[1]],
as.av("Aciclovir")
)
expect_identical(
av_from_text("28/03/2020 regular aciclovir 500mg po tds", thorough_search = TRUE)[[1]],
as.av("Aciclovir")
)
expect_identical(
av_from_text("28/03/2020 regular aciclovir 500mg po tds", thorough_search = FALSE)[[1]],
as.av("Aciclovir")
)
expect_identical(
av_from_text("28/03/2020 regular aciclovir 500mg po tds", translate_av = TRUE)[[1]],
"Aciclovir"
)
expect_identical(
av_from_text("administered aciclo and valaciclo", collapse = ", ")[[1]],
"ACI, VALA"
)
expect_identical(
av_from_text("28/03/2020 regular aciclo 500mg po tds", type = "dose")[[1]],
500
)
expect_identical(
av_from_text("28/03/2020 regular aciclo 500mg po tds", type = "admin")[[1]],
"oral"
)
expect_identical(
av_from_text("28/03/2020 regular aciclo 500mg po tds", type = "dose")[[1]],
500
)
expect_identical(
av_from_text("28/03/2020 regular aciclo 500mg po tds", type = "admin")[[1]],
"oral"
)
})

View File

@ -27,37 +27,39 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
expect_identical(av_name("ACI", language = NULL), "Aciclovir")
expect_identical(av_atc("ACI"), "J05AB01")
expect_identical(av_cid("ACI"), as.integer(135398513))
test_that("ab_property works", {
expect_identical(av_name("ACI", language = NULL), "Aciclovir")
expect_identical(av_atc("ACI"), "J05AB01")
expect_identical(av_cid("ACI"), as.integer(135398513))
expect_inherits(av_tradenames("ACI"), "character")
expect_inherits(av_tradenames(c("ACI", "ACI")), "list")
expect_inherits(av_tradenames("ACI"), "character")
expect_inherits(av_tradenames(c("ACI", "ACI")), "list")
expect_identical(av_group("ACI", language = NULL), "Nucleosides and nucleotides excl. reverse transcriptase inhibitors")
expect_identical(av_group("ACI", language = NULL), "Nucleosides and nucleotides excl. reverse transcriptase inhibitors")
expect_identical(av_name(135398513, language = NULL), "Aciclovir")
expect_identical(av_name("J05AB01", language = NULL), "Aciclovir")
expect_identical(av_name(135398513, language = NULL), "Aciclovir")
expect_identical(av_name("J05AB01", language = NULL), "Aciclovir")
expect_identical(av_ddd("ACI", "oral"), 4)
expect_identical(av_ddd_units("ACI", "iv"), "g")
expect_identical(av_ddd("ACI", "iv"), 4)
expect_identical(av_ddd("ACI", "oral"), 4)
expect_identical(av_ddd_units("ACI", "iv"), "g")
expect_identical(av_ddd("ACI", "iv"), 4)
expect_identical(
av_name(x = c("ACI", "VALA"), tolower = TRUE, language = NULL),
c("aciclovir", "valaciclovir")
)
expect_identical(
av_name(x = c("ACI", "VALA"), tolower = TRUE, language = NULL),
c("aciclovir", "valaciclovir")
)
expect_inherits(av_info("ACI"), "list")
expect_inherits(av_info("ACI"), "list")
expect_error(av_property("acic", "invalid property"))
expect_error(av_name("acic", language = "INVALID"))
expect_stdout(print(av_name("acic", language = NULL)))
expect_error(av_property("acic", "invalid property"))
expect_error(av_name("acic", language = "INVALID"))
expect_output(print(av_name("acic", language = NULL)))
expect_equal(av_name("29113-8", language = NULL), "Abacavir")
expect_equal(
av_loinc("Abacavir"),
c("29113-8", "30273-7", "30287-7", "30303-2", "78772-1", "78773-9", "79134-3", "80118-3")
)
expect_equal(av_name("29113-8", language = NULL), "Abacavir")
expect_equal(
av_loinc("Abacavir"),
c("29113-8", "30273-7", "30287-7", "30303-2", "78772-1", "78773-9", "79134-3", "80118-3")
)
expect_true(av_url("ACI") %like% "fhi[.]no")
expect_true(av_url("ACI") %like% "fhi[.]no")
})

Some files were not shown because too many files have changed in this diff Show More