Used in 135 countries
Since its first public release in early 2018, this package has been downloaded from 135 countries. Click the map to enlarge.
AMR
(for R), there’s always a knowledgeable microbiologist by your side!# AMR works great with dplyr, but it's not required or neccesary
-library(AMR)
-library(dplyr)
-
-example_isolates %>%
- mutate(mo = mo_fullname(mo)) %>%
- filter(mo_is_gram_negative(), mo_is_intrinsic_resistant(ab = "cefotax")) %>%
- select(mo, aminoglycosides(), carbapenems())
-#> NOTE: Using column 'mo' as input for mo_is_gram_negative()
-#> NOTE: Using column 'mo' as input for mo_is_intrinsic_resistant()
-#> Selecting aminoglycosides: 'AMK' (amikacin), 'GEN' (gentamicin),
- 'KAN' (kanamycin), 'TOB' (tobramycin)
-#> Selecting carbapenems: 'IPM' (imipenem), 'MEM' (meropenem)
# AMR works great with dplyr, but it's not required or neccesary
+library(AMR)
+library(dplyr)
+
+%>%
+ example_isolates mutate(mo = mo_fullname(mo)) %>%
+ filter(mo_is_gram_negative(), mo_is_intrinsic_resistant(ab = "cefotax")) %>%
+ select(mo, aminoglycosides(), carbapenems())
+ #> NOTE: Using column 'mo' as input for mo_is_gram_negative()
+#> NOTE: Using column 'mo' as input for mo_is_intrinsic_resistant()
+#> Selecting aminoglycosides: 'AMK' (amikacin), 'GEN' (gentamicin),
+'KAN' (kanamycin), 'TOB' (tobramycin)
+ #> Selecting carbapenems: 'IPM' (imipenem), 'MEM' (meropenem)
With only having defined a row filter on Gram-negative bacteria with intrinsic resistance to cefotaxime (mo_is_gram_positive()
and mo_is_intrinsic_resistant()
) and a column selection on two antibiotic groups (aminoglycosides()
and carbapenems()
), the reference data about all microorganisms and all antibiotics in the AMR
package make sure you get what you meant:
The development of this package is part of, related to, or made possible by:
This package is available here on the official R network (CRAN), which has a peer-reviewed submission process. Install this package in R from CRAN by using the command:
-+install.packages("AMR")It will be downloaded and installed automatically. For RStudio, click on the menu Tools > Install Packages… and then type in “AMR” and press Install.
Note: Not all functions on this website may be available in this latest release. To use all functions and data sets mentioned on this website, install the latest development version.
@@ -393,7 +392,7 @@ Since you are one of our users, we would like to know how you use the package anLatest development version
The latest and unpublished development version can be installed from GitHub using:
-diff --git a/docs/news/index.html b/docs/news/index.html index b1991b09..762ca72e 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@+install.packages("remotes") remotes::install_github("msberends/AMR")
NEWS.md
- Functions mo_is_gram_negative()
and mo_is_gram_positive()
as wrappers around mo_gramstain()
. They always return TRUE
or FALSE
(except when the input is NA
or the MO code is UNKNOWN
), thus always return FALSE
for species outside the taxonomic kingdom of Bacteria.
Function mo_is_intrinsic_resistant()
to test for intrinsic resistance, based on EUCAST Intrinsic Resistance and Unusual Phenotypes v3.2 from 2020.
Functions random_mic()
, random_disk()
and random_rsi()
for random number generation. They take microorganism names and antibiotic names as input to make generation more realistic.
Fixed a bug where as.ab()
would sometimes fail
If using as.rsi()
on MICs or disk diffusion while there is intrinsic antimicrobial resistance, a warning will be thrown to remind about this
Better tibble printing for MIC values
Fix for plotting MIC values with plot()
Added plot()
generic to class <disk>
plot(<mic>)
barplot(<mic>)
plot(<rsi>)
barplot(<rsi>)
plot(<disk>)
plot(<mic>)
barplot(<mic>)
plot(<rsi>)
barplot(<rsi>)
Plotting for classes rsi
and disk
Principal Component Analysis (for AMR)
Random MIC values/disk zones/RSI generation
Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least episode_days
days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least episode_days
days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored.
The first_isolate()
function is a wrapper around the is_new_episode()
function, but more efficient for data sets containing microorganism codes or names.
The dplyr
package is not required for this function to work, but this function works conveniently inside dplyr
verbs such as filter()
, mutate()
and summarise()
.
-The lifecycle of this function is experimental. An experimental function is in early stages of development. The unlying code might be changing frequently. Experimental functions might be removed without deprecation, so you are generally best off waiting until a function is more mature before you use it in production code. Experimental functions are only available in development versions of this AMR
package and will thus not be included in releases that are submitted to CRAN, since such functions have not yet matured enough.
+The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.
If the unlying code needs breaking changes, they will occur gradually. For example, a parameter will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
rsi
and disk
R/amr.R
, R/mic.R
, R/rsi.R
+ Source: R/amr.R
, R/disk.R
, R/mic.R
, and 1 more
plot.Rd
Functions to print classes of the AMR
package.
# S3 method for mic +# S3 method for disk +plot( + x, + main = paste("Disk zones values of", deparse(substitute(x))), + ylab = "Frequency", + xlab = "Disk diffusion (mm)", + axes = FALSE, + ... +) + +# S3 method for mic plot( x, main = paste("MIC values of", deparse(substitute(x))), diff --git a/docs/reference/random.html b/docs/reference/random.html new file mode 100644 index 00000000..86475dc8 --- /dev/null +++ b/docs/reference/random.html @@ -0,0 +1,338 @@ + + + + + + + + +Random MIC values/disk zones/RSI generation — random • AMR (for R) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +++ + + + + + + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml index aace7d9c..8071036d 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -144,6 +144,9 @@+ + + + + + +++ + + ++ + ++ +++ +These functions can be used for generating random MIC values and disk diffusion diameters, for AMR analysis practice.
+random_mic(size, mo = NULL, ab = NULL, ...) + +random_disk(size, mo = NULL, ab = NULL, ...) + +random_rsi(size, prob_RSI = c(0.33, 0.33, 0.33), ...)+ +Arguments
++
+ ++ + +size ++ desired size of the returned vector
+ +mo ++ any character that can be coerced to a valid microorganism code with
as.mo()
+ +ab ++ any character that can be coerced to a valid antimicrobial agent code with
as.ab()
+ +... ++ extension for future versions, not used at the moment
+ +prob_RSI ++ a vector of length 3: the probabilities for R (1st value), S (2nd value) and I (3rd value)
Value
+ +class
+<mic>
forrandom_mic()
(seeas.mic()
) and class<disk>
forrandom_disk()
(seeas.disk()
)Details
+ +The base R function
+sample()
is used for generating values.Generated values are based on the latest EUCAST guideline implemented in the rsi_translation data set. To create specific generated values per bug or drug, set the
+mo
and/orab
parameter.Maturing lifecycle
+ + + ++
+The lifecycle of this function is maturing. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome to suggest changes at our repository or write us an email (see section 'Contact Us').Read more on our website!
+ + + +On our website https://msberends.github.io/AMR/ you can find a comprehensive tutorial about how to conduct AMR analysis, the complete documentation of all functions and an example analysis using WHONET data. As we would like to better understand the backgrounds and needs of our users, please participate in our survey!
+ +Examples
+random_mic(100) +random_disk(100) +random_rsi(100) + +# \donttest{ +# make the random generation more realistic by setting a bug and/or drug: +random_mic(100, "Klebsiella pneumoniae") # range 0.0625-64 +random_mic(100, "Klebsiella pneumoniae", "meropenem") # range 0.0625-16 +random_mic(100, "Streptococcus pneumoniae", "meropenem") # range 0.0625-4 + +random_disk(100, "Klebsiella pneumoniae") # range 11-50 +random_disk(100, "Klebsiella pneumoniae", "ampicillin") # range 6-14 +random_disk(100, "Streptococcus pneumoniae", "ampicillin") # range 16-22 +# } +++ https://msberends.github.io/AMR//reference/proportion.html + https://msberends.github.io/AMR//reference/random.html +diff --git a/docs/survey.html b/docs/survey.html index 4039473f..ef3156d8 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ diff --git a/man/is_new_episode.Rd b/man/is_new_episode.Rd index 0f4df478..2d9bc08e 100644 --- a/man/is_new_episode.Rd +++ b/man/is_new_episode.Rd @@ -22,12 +22,16 @@ This function determines which items in a vector can be considered (the start of \details{ Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least \code{episode_days} days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least \code{episode_days} days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored. +The \code{\link[=first_isolate]{first_isolate()}} function is a wrapper around the \code{\link[=is_new_episode]{is_new_episode()}} function, but more efficient for data sets containing microorganism codes or names. + The \code{dplyr} package is not required for this function to work, but this function works conveniently inside \code{dplyr} verbs such as \code{\link[dplyr:filter]{filter()}}, \code{\link[dplyr:mutate]{mutate()}} and \code{\link[dplyr:summarise]{summarise()}}. } -\section{Experimental lifecycle}{ +\section{Stable lifecycle}{ -\if{html}{\figure{lifecycle_experimental.svg}{options: style=margin-bottom:5px} \cr} -The \link[=lifecycle]{lifecycle} of this function is \strong{experimental}. An experimental function is in early stages of development. The unlying code might be changing frequently. Experimental functions might be removed without deprecation, so you are generally best off waiting until a function is more mature before you use it in production code. Experimental functions are only available in development versions of this \code{AMR} package and will thus not be included in releases that are submitted to CRAN, since such functions have not yet matured enough. +\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr} +The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided. + +If the unlying code needs breaking changes, they will occur gradually. For example, a parameter will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error. } \section{Read more on our website!}{ diff --git a/man/plot.Rd b/man/plot.Rd index facd350e..2ca1d5df 100644 --- a/man/plot.Rd +++ b/man/plot.Rd @@ -1,13 +1,23 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/amr.R, R/mic.R, R/rsi.R +% Please edit documentation in R/amr.R, R/disk.R, R/mic.R, R/rsi.R \name{plot} \alias{plot} +\alias{plot.disk} \alias{plot.mic} \alias{barplot.mic} \alias{plot.rsi} \alias{barplot.rsi} \title{Plotting for classes \code{rsi} and \code{disk}} \usage{ +\method{plot}{disk}( + x, + main = paste("Disk zones values of", deparse(substitute(x))), + ylab = "Frequency", + xlab = "Disk diffusion (mm)", + axes = FALSE, + ... +) + \method{plot}{mic}( x, main = paste("MIC values of", deparse(substitute(x))), diff --git a/man/random.Rd b/man/random.Rd new file mode 100644 index 00000000..fc21f042 --- /dev/null +++ b/man/random.Rd @@ -0,0 +1,64 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/random.R +\name{random} +\alias{random} +\alias{random_mic} +\alias{random_disk} +\alias{random_rsi} +\title{Random MIC values/disk zones/RSI generation} +\usage{ +random_mic(size, mo = NULL, ab = NULL, ...) + +random_disk(size, mo = NULL, ab = NULL, ...) + +random_rsi(size, prob_RSI = c(0.33, 0.33, 0.33), ...) +} +\arguments{ +\item{size}{desired size of the returned vector} + +\item{mo}{any character that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}} + +\item{ab}{any character that can be coerced to a valid antimicrobial agent code with \code{\link[=as.ab]{as.ab()}}} + +\item{...}{extension for future versions, not used at the moment} + +\item{prob_RSI}{a vector of length 3: the probabilities for R (1st value), S (2nd value) and I (3rd value)} +} +\value{ +class \verb{ https://msberends.github.io/AMR//reference/resistance_predict.html } for \code{\link[=random_mic]{random_mic()}} (see \code{\link[=as.mic]{as.mic()}}) and class \verb{ } for \code{\link[=random_disk]{random_disk()}} (see \code{\link[=as.disk]{as.disk()}}) +} +\description{ +These functions can be used for generating random MIC values and disk diffusion diameters, for AMR analysis practice. +} +\details{ +The base R function \code{\link[=sample]{sample()}} is used for generating values. + +Generated values are based on the latest EUCAST guideline implemented in the \link{rsi_translation} data set. To create specific generated values per bug or drug, set the \code{mo} and/or \code{ab} parameter. +} +\section{Maturing lifecycle}{ + +\if{html}{\figure{lifecycle_maturing.svg}{options: style=margin-bottom:5px} \cr} +The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unlying code of a maturing function has been roughed out, but finer details might still change. Since this function needs wider usage and more extensive testing, you are very welcome \href{https://github.com/msberends/AMR/issues}{to suggest changes at our repository} or \link[=AMR]{write us an email (see section 'Contact Us')}. +} + +\section{Read more on our website!}{ + +On our website \url{https://msberends.github.io/AMR/} you can find \href{https://msberends.github.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR analysis, the \href{https://msberends.github.io/AMR/reference/}{complete documentation of all functions} and \href{https://msberends.github.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. As we would like to better understand the backgrounds and needs of our users, please \href{https://msberends.github.io/AMR/survey.html}{participate in our survey}! +} + +\examples{ +random_mic(100) +random_disk(100) +random_rsi(100) + +\donttest{ +# make the random generation more realistic by setting a bug and/or drug: +random_mic(100, "Klebsiella pneumoniae") # range 0.0625-64 +random_mic(100, "Klebsiella pneumoniae", "meropenem") # range 0.0625-16 +random_mic(100, "Streptococcus pneumoniae", "meropenem") # range 0.0625-4 + +random_disk(100, "Klebsiella pneumoniae") # range 11-50 +random_disk(100, "Klebsiella pneumoniae", "ampicillin") # range 6-14 +random_disk(100, "Streptococcus pneumoniae", "ampicillin") # range 16-22 +} +} diff --git a/tests/testthat/test-random.R b/tests/testthat/test-random.R new file mode 100644 index 00000000..dd178bbd --- /dev/null +++ b/tests/testthat/test-random.R @@ -0,0 +1,44 @@ +# ==================================================================== # +# TITLE # +# Antimicrobial Resistance (AMR) Analysis for R # +# # +# SOURCE # +# https://github.com/msberends/AMR # +# # +# LICENCE # +# (c) 2018-2020 Berends MS, Luz CF et al. # +# Developed at the University of Groningen, the Netherlands, in # +# collaboration with non-profit organisations Certe Medical # +# Diagnostics & Advice, and University Medical Center Groningen. # +# # +# 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 analysis: https://msberends.github.io/AMR/ # +# ==================================================================== # + +context("random.R") + +test_that("random works", { + skip_on_cran() + + expect_s3_class(random_mic(100), "mic") + expect_s3_class(random_mic(100, mo = "Klebsiella pneumoniae"), "mic") + expect_s3_class(random_mic(100, mo = "Klebsiella pneumoniae", ab = "meropenem"), "mic") + expect_s3_class(random_mic(100, ab = "meropenem"), "mic") + # no normal factors of 2 + expect_s3_class(random_mic(100, "Haemophilus influenzae", "ceftaroline"), "mic") + + expect_s3_class(random_disk(100), "disk") + expect_s3_class(random_disk(100, mo = "Klebsiella pneumoniae"), "disk") + expect_s3_class(random_disk(100, mo = "Klebsiella pneumoniae", ab = "meropenem"), "disk") + expect_s3_class(random_disk(100, ab = "meropenem"), "disk") + + expect_s3_class(random_rsi(100), "rsi") +})