Antimicrobial Resistance Analysis

Functions to simplify the analysis and prediction of Antimicrobial Resistance (AMR) to work with microbial and antimicrobial properties by using evidence-based methods.

An R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with antibiotic properties by using evidence-based methods.

This R package was created for academic research by PhD students of the Faculty of Medical Sciences of the University of Groningen and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG).

▶️ Get it with install.packages("AMR") or see below for other possibilities.

▶️ Read the changelog here.


Matthijs S. Berends 1,2,a, Christian F. Luz 1,a, Erwin E.A. Hassing2, Corinna Glasner 1,b, Alex W. Friedrich 1,b, Bhanu Sinha 1,b

1 Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands -
2 Certe Medical Diagnostics & Advice, Groningen, the Netherlands -
a R package author and thesis dissertant
b Thesis advisor


Why this package?

This R package was intended to make microbial epidemiology easier. Most functions contain extensive help pages to get started.

The AMR package basically does four important things:

  1. It cleanses existing data, by transforming it to reproducible and profound classes, making the most efficient use of R. These functions all use artificial intelligence to guess results that you would expect:

    • Use to get an ID of a microorganism. The IDs are human readable for the trained eye - the ID of Klebsiella pneumoniae is "B_KLBSL_PNE" (B stands for Bacteria) and the ID of S. aureus is "B_STPHY_AUR". The function takes almost any text as input that looks like the name or code of a microorganism like "E. coli", "esco" and "esccol". Even"MRSA") will return the ID of S. aureus. Moreover, it can group all coagulase negative and positive Staphylococci, and can transform Streptococci into Lancefield groups. To find bacteria based on your input, it uses Artificial Intelligence to look up values in the included ITIS data, consisting of more than 18,000 microorganisms. It is very fast, see Benchmarks.
    • Use as.rsi to transform values to valid antimicrobial results. It produces just S, I or R based on your input and warns about invalid values. Even values like "<=0.002; S" (combined MIC/RSI) will result in "S".
    • Use as.mic to cleanse your MIC values. It produces a so-called factor (called ordinal in SPSS) with valid MIC values as levels. A value like "<=0.002; S" (combined MIC/RSI) will result in "<=0.002".
    • Use as.atc to get the ATC code of an antibiotic as defined by the WHO. This package contains a database with most LIS codes, official names, DDDs and even trade names of antibiotics. For example, the values "Furabid", "Furadantin", "nitro" all return the ATC code of Nitrofurantoine.
  2. It enhances existing data and adds new data from data sets included in this package.

    • Use EUCAST_rules to apply EUCAST expert rules to isolates.
    • Use first_isolate to identify the first isolates of every patient using guidelines from the CLSI (Clinical and Laboratory Standards Institute).
      • You can also identify first weighted isolates of every patient, an adjusted version of the CLSI guideline. This takes into account key antibiotics of every strain and compares them.
    • Use MDRO (abbreviation of Multi Drug Resistant Organisms) to check your isolates for exceptional resistance with country-specific guidelines or EUCAST rules. Currently, national guidelines for Germany and the Netherlands are supported.
    • The data set microorganisms contains the complete taxonomic tree of more than 18,000 microorganisms (bacteria, fungi/yeasts and protozoa). Furthermore, the colloquial name and Gram stain are available, which enables resistance analysis of e.g. different antibiotics per Gram stain. The package also contains functions to look up values in this data set like mo_genus, mo_family, mo_gramstain or even mo_phylum. As they use internally, they also use artificial intelligence. For example, mo_genus("MRSA") and mo_genus("S. aureus") will both return "Staphylococcus". They also come with support for German, Dutch, Spanish, Italian, French and Portuguese. These functions can be used to add new variables to your data.
    • The data set antibiotics contains the ATC code, LIS codes, official name, trivial name and DDD of both oral and parenteral administration. It also contains a total of 298 trade names. Use functions like ab_name and ab_tradenames to look up values. The ab_* functions use as.atc internally so they support AI to guess your expected result. For example, ab_name("Fluclox"), ab_name("Floxapen") and ab_name("J01CF05") will all return "Flucloxacillin". These functions can again be used to add new variables to your data.
  3. It analyses the data with convenient functions that use well-known methods.

    • Calculate the resistance (and even co-resistance) of microbial isolates with the portion_R, portion_IR, portion_I, portion_SI and portion_S functions. Similarly, the number of isolates can be determined with the count_R, count_IR, count_I, count_SI and count_S functions. All these functions can be used with the dplyr package (e.g. in conjunction with summarise)
    • Plot AMR results with geom_rsi, a function made for the ggplot2 package
    • Predict antimicrobial resistance for the nextcoming years using logistic regression models with the resistance_predict function
    • Conduct descriptive statistics to enhance base R: calculate kurtosis, skewness and create frequency tables
  4. It teaches the user how to use all the above actions.

    • The package contains extensive help pages with many examples.
    • It also contains an example data set called septic_patients. This data set contains:
      • 2,000 blood culture isolates from anonymised septic patients between 2001 and 2017 in the Northern Netherlands
      • Results of 40 antibiotics (each antibiotic in its own column) with a total of 38,414 antimicrobial results
      • Real and genuine data


This package contains the complete microbial taxonomic data (with all eight taxonomic ranks - from kingdom to subspecies) from the publicly available Integrated Taxonomic Information System (ITIS,

All (sub)species from the taxonomic kingdoms Bacteria, Fungi and Protozoa are included in this package, as well as all previously accepted names known to ITIS. Furthermore, the responsible authors and year of publication are available. This allows users to use authoritative taxonomic information for their data analysis on any microorganism, not only human pathogens. It also helps to quickly determine the Gram stain of bacteria, since all bacteria are classified into subkingdom Negibacteria or Posibacteria.

ITIS is a partnership of U.S., Canadian, and Mexican agencies and taxonomic specialists.

Get a note when a species was renamed

mo_shortname("Chlamydia psittaci")
# Note: 'Chlamydia psittaci' (Page, 1968) was renamed 'Chlamydophila psittaci' (Everett et al., 1999)
# [1] "C. psittaci"

Get any property from the entire taxonomic tree for all included species

mo_class("E. coli")
# [1] "Gammaproteobacteria"
mo_family("E. coli")
# [1] "Enterobacteriaceae"
mo_subkingdom("E. coli")
# [1] "Negibacteria"
mo_gramstain("E. coli") # based on subkingdom
# [1] "Gram negative"
mo_ref("E. coli")
# [1] "Castellani and Chalmers, 1919"

Do not get mistaken - the package only includes microorganisms

mo_phylum("C. elegans")
# [1] "Cyanobacteria"                   # Bacteria?!
mo_fullname("C. elegans")
# [1] "Chroococcus limneticus elegans"  # Because a microorganism was found 

How to get it?

All stable versions of this package are published on CRAN, the official R network with a peer-reviewed submission process.

Install from CRAN

CRAN_Badge CRAN_Downloads

(Note: Downloads measured only by, this excludes e.g. the official

  • RStudio favicon Install using RStudio (recommended):

    • Click on Tools and then Install Packages...
    • Type in AMR and press Install
  • R favicon Install in R directly:

    • install.packages("AMR")

Install from Zenodo


This package was also published on Zenodo (stable releases only):

Install from GitLab

This is the latest development version. Although it may contain bugfixes and even new functions compared to the latest released version on CRAN, it is also subject to change and may be unstable or behave unexpectedly. Always consider this a beta version. All below 'badges' should be green:

Development Test Result Reference
All functions checked on Linux pipeline status GitLab CI [ref 1]
All functions checked on Windows AppVeyor_Build Appveyor Systems Inc. [ref 2]
Percentage of syntax lines checked Code_Coverage Codecov LLC [ref 3]

If so, try it with:


How to use it?

# Call it with:
# For a list of functions:
help(package = "AMR")

New classes

This package contains two new S3 classes: mic for MIC values (e.g. from Vitek or Phoenix) and rsi for antimicrobial drug interpretations (i.e. S, I and R). Both are actually ordered factors under the hood (an MIC of 2 being higher than <=1 but lower than >=32, and for class rsi factors are ordered as S < I < R). Both classes have extensions for existing generic functions like print, summary and plot.

These functions also try to coerce valid values.


The septic_patients data set comes with antimicrobial results of more than 40 different drugs. For example, columns amox and cipr contain results of amoxicillin and ciprofloxacin, respectively.

summary(septic_patients[, c("amox", "cipr")])
#      amox          cipr     
#  Mode  :rsi    Mode  :rsi   
#  <NA>  :1002   <NA>  :596   
#  Sum S :336    Sum S :1108  
#  Sum IR:662    Sum IR:296   
#  -Sum R:659    -Sum R:227   
#  -Sum I:3      -Sum I:69  

You can use the plot function from base R:



Or use the ggplot2 and dplyr packages to create more appealing plots:

septic_patients %>%
  select(amox, nitr, fosf, trim, cipr) %>%


Adjust it with any parameter you know from the ggplot2 package:

septic_patients %>%
  select(amox, nitr, fosf, trim, cipr) %>%
  ggplot_rsi(datalabels = FALSE, 
             width = 0.5, colour = "purple", size = 1, linetype = 2, alpha = 0.5)


It also supports grouping variables. Let's say we want to compare resistance of drugs against Urine Tract Infections (UTI) between hospitals A to D (variable hospital_id):

septic_patients %>%
  select(hospital_id, amox, nitr, fosf, trim, cipr) %>%
  group_by(hospital_id) %>%
  ggplot_rsi(x = "hospital_id",
             facet = "Antibiotic",
             nrow = 1,
             datalabels = FALSE) +
  labs(title = "AMR of Anti-UTI Drugs Per Hospital",
       x = "Hospital")


You could use this to group on anything in your plots: Gram stain, age (group), genus, geographic location, et cetera.

Is there a significant difference between hospital A and D when it comes to Fosfomycin?

check_A_and_D <- septic_patients %>%
  filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
  select(hospital_id, fosf) %>%            # select the hospitals and fosfomycin
  group_by(hospital_id) %>%
  count_df(combine_IR = TRUE) %>%          # count all isolates per group (hospital_id)
  tidyr::spread(hospital_id, Value) %>%    # transform output so A and D are columns
  select(A, D) %>%                         # and select these only
  as.matrix()                              # transform to good old matrix for fisher.test
#       A  D
# [1,] 24 33
# [2,] 25 77

Total sum is lower than 1,000 so we'd prefer a Fisher's exact test, not a G-test (or its formerly used equivalent, the famous Chi2 test):

#  Fisher's Exact Test for Count Data
# data:  check_A_and_D
# p-value = 0.03104
# alternative hypothesis: true odds ratio is not equal to 1
# 95 percent confidence interval:
#  1.054283 4.735995
# sample estimates:
# odds ratio 
#   2.228006 

Well, there you go!


# Transform values to new class
mic_data <- as.mic(c(">=32", "1.0", "8", "<=0.128", "8", "16", "16"))
#  Mode:mic      
#  <NA>:0        
#  Min.:<=0.128  
#  Max.:>=32 


Overwrite/force resistance based on EUCAST rules

This is also called interpretive reading.

a <- data.frame(mo = c("Staphylococcus aureus",
                       "Enterococcus faecalis",
                       "Escherichia coli",
                       "Klebsiella pneumoniae",
                       "Pseudomonas aeruginosa"),
                vanc = "-",       # Vancomycin
                amox = "-",       # Amoxicillin
                coli = "-",       # Colistin
                cfta = "-",       # Ceftazidime
                cfur = "-",       # Cefuroxime
                peni = "S",       # Benzylpenicillin
                cfox = "S",       # Cefoxitin
                stringsAsFactors = FALSE)
#                       mo vanc amox coli cfta cfur peni cfox
# 1  Staphylococcus aureus    -    -    -    -    -    S    S
# 2  Enterococcus faecalis    -    -    -    -    -    S    S
# 3       Escherichia coli    -    -    -    -    -    S    S
# 4  Klebsiella pneumoniae    -    -    -    -    -    S    S
# 5 Pseudomonas aeruginosa    -    -    -    -    -    S    S
b <- EUCAST_rules(a) # 18 results are forced as R or S
#                       mo vanc amox coli cfta cfur peni cfox
# 1  Staphylococcus aureus    -    S    R    R    S    S    S
# 2  Enterococcus faecalis    -    -    R    R    R    S    R
# 3       Escherichia coli    R    -    -    -    -    R    S
# 4  Klebsiella pneumoniae    R    R    -    -    -    R    S
# 5 Pseudomonas aeruginosa    R    R    -    -    R    R    R

Bacteria IDs can be retrieved with the guess_mo function. It uses any type of info about a microorganism as input. For example, all these will return value B_STPHY_AUR, the ID of S. aureus:

guess_mo("S. aureus")
guess_mo("S aureus")
guess_mo("Staphylococcus aureus")
guess_mo("MRSA") # Methicillin Resistant S. aureus
guess_mo("MSSA") # Methicillin Susceptible S. aureus
guess_mo("VISA") # Vancomycin Intermediate S. aureus
guess_mo("VRSA") # Vancomycin Resistant S. aureus

Other (microbial) epidemiological functions

# G-test to replace Chi squared test
# Determine key antibiotic based on bacteria ID
# Selection of first isolates of any patient
# Predict resistance levels of antibiotics
# Get name of antibiotic by ATC code
abname("J01CR02", from = "atc", to = "umcg") # "AMCL"

Frequency tables

Base R lacks a simple function to create frequency tables. We created such a function that works with almost all data types: freq (or frequency_tbl). It can be used in two ways:

# Like base R:
# And like tidyverse:
mydata %>% freq(myvariable)

Frequency are of course sorted by count at default:

septic_patients %>% freq(hospital_id)
# Class:     factor (numeric)
# Length:    2000 (of which NA: 0 = 0.00%)
# Unique:    4
#      Item    Count   Percent   Cum. Count   Cum. Percent
# ---  -----  ------  --------  -----------  -------------
# 1    D         762     38.1%          762          38.1%
# 2    B         663     33.1%         1425          71.2%
# 3    A         321     16.1%         1746          87.3%
# 4    C         254     12.7%         2000         100.0%

This can be changed with the sort.count parameter:

septic_patients %>% freq(hospital_id, sort.count = FALSE)
# Class:     factor (numeric)
# Length:    2000 (of which NA: 0 = 0.00%)
# Unique:    4
#      Item    Count   Percent   Cum. Count   Cum. Percent
# ---  -----  ------  --------  -----------  -------------
# 1    A         321     16.1%          321          16.1%
# 2    B         663     33.1%          984          49.2%
# 3    C         254     12.7%         1238          61.9%
# 4    D         762     38.1%         2000         100.0%

For numeric values, some extra descriptive statistics will be calculated:

freq(runif(n = 10, min = 1, max = 5))
# Frequency table  
# Class:     numeric
# Length:    10 (of which NA: 0 = 0.00%)
# Unique:    10
# Mean:      3.1
# Std. dev.: 1.3 (CV: 0.43, MAD: 1.8)
# Five-Num:  1.3 | 1.7 | 3.2 | 4.3 | 5.0 (IQR: 2.6, CQV: 0.43)
# Outliers:  0
#           Item   Count   Percent   Cum. Count   Cum. Percent
# ---  ---------  ------  --------  -----------  -------------
# 1     1.271079       1     10.0%            1          10.0%
# 2     1.333975       1     10.0%            2          20.0%
# 3     1.714946       1     10.0%            3          30.0%
# 4     2.751871       1     10.0%            4          40.0%
# 5     3.090140       1     10.0%            5          50.0%
# 6     3.260850       1     10.0%            6          60.0%
# 7     3.824105       1     10.0%            7          70.0%
# 8     4.278028       1     10.0%            8          80.0%
# 9     4.436265       1     10.0%            9          90.0%
# 10    4.996694       1     10.0%           10         100.0%
# Warning message:
# All observations are unique. 

Learn more about this function with:


Data sets included in package

Data sets to work with antibiotics and bacteria properties.

# Data set with complete taxonomic trees from ITIS, containing of 
# the three kingdoms Bacteria, Fungi and Protozoa
microorganisms     # data.frame: 18,833 x 15
microorganisms.old # data.frame: 2,383 x 4
# Data set with ATC antibiotics codes, official names, trade names 
# and DDDs (oral and parenteral)
antibiotics       #  data.frame: 423 x 18
# Data set with 2000 random blood culture isolates from anonymised
# septic patients between 2001 and 2017 in 5 Dutch hospitals
septic_patients    # data.frame: 2,000 x 49


One of the most important features of this package is the complete microbial taxonomic database, supplied by ITIS ( We created a function that transforms any user input value to a valid microbial ID by using AI (Artificial Intelligence) and based on the taxonomic tree of ITIS.

Using the microbenchmark package, we can review the calculation performance of this function.


In the next test, we try to 'coerce' different input values for Staphylococcus aureus. The actual result is the same every time: it returns its MO code B_STPHY_AUR (B stands for Bacteria, the taxonomic kingdom).

But the calculation time differs a lot. Here, the AI effect can be reviewed best:

microbenchmark(A ="stau"),
               B ="staaur"),
               C ="S. aureus"),
               D ="S.  aureus"),
               E ="STAAUR"),
               F ="Staphylococcus aureus"),
               G ="B_STPHY_AUR"),
               times = 10,
               unit = "ms")
# Unit: milliseconds
#  expr       min        lq       mean     median        uq       max neval
#     A 34.745551 34.798630 35.2596102 34.8994810 35.258325 38.067062    10
#     B  7.095386  7.125348  7.2219948  7.1613865  7.240377  7.495857    10
#     C 11.677114 11.733826 11.8304789 11.7715050 11.843756 12.317559    10
#     D 11.694435 11.730054 11.9859313 11.8775585 12.206371 12.750016    10
#     E  7.044402  7.117387  7.2271630  7.1923610  7.246104  7.742396    10
#     F  6.642326  6.778446  6.8988042  6.8753165  6.923577  7.513945    10
#     G  0.106788  0.131023  0.1351229  0.1357725  0.144014  0.146458    10

In the table above, all measurements are shown in milliseconds (thousands of seconds), tested on a quite regular Linux server from 2007 (Core 2 Duo 2.7 GHz, 2 GB DDR2 RAM). A value of 6.9 milliseconds means it will roughly determine 144 input values per second. It case of 39.2 milliseconds, this is only 26 input values per second. The more an input value resembles a full name (like C, D and F), the faster the result will be found. In case of G, the input is already a valid MO code, so it only almost takes no time at all (0.0001 seconds on our server).

To achieve this speed, the function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined far less faster. See this example for the ID of Burkholderia nodosa (B_BRKHL_NOD):

microbenchmark(A ="buno"),
               B ="burnod"),
               C ="B. nodosa"),
               D ="B.  nodosa"),
               E ="BURNOD"),
               F ="Burkholderia nodosa"),
               G ="B_BRKHL_NOD"),
               times = 10,
               unit = "ms")
# Unit: milliseconds
#  expr        min         lq        mean      median         uq        max neval
#     A 124.175427 124.474837 125.8610536 125.3750560 126.160945 131.485994    10
#     B 154.249713 155.364729 160.9077032 156.8738940 157.136183 197.315105    10
#     C  66.066571  66.162393  66.5538611  66.4488130  66.698077  67.623404    10
#     D  86.747693  86.918665  90.7831016  87.8149725  89.440982 116.767991    10
#     E 154.863827 155.208563 162.6535954 158.4062465 168.593785 187.378088    10
#     F  32.427028  32.638648  32.9929454  32.7860475  32.992813  34.674241    10
#     G   0.213155   0.216578   0.2369226   0.2338985   0.253734   0.285581    10

That takes up to 11 times as much time! A value of 158.4 milliseconds means it can only determine ~6 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance.

To relieve this pitfall and further improve performance, two important calculations take almost no time at all: repetive results and already precalculated results.

Repetive results mean that unique values are present more than once. Unique values will only be calculated once by We will use mo_fullname for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) and uses internally.

# take 500,000 random MO codes from the septic_patients data set
x = septic_patients %>%
  sample_n(500000, replace = TRUE) %>%
# got the right length?
# [1] 500000
# and how many unique values do we have?
# [1] 96
# only 96, but distributed in 500,000 results. now let's see:
microbenchmark(X = mo_fullname(x),
               times = 10,
               unit = "ms")
# Unit: milliseconds
#  expr      min       lq     mean   median       uq      max neval
#     X 114.9342 117.1076 129.6448 120.2047 131.5005 168.6371    10

So transforming 500,000 values (!) of 96 unique values only takes 0.12 seconds (120 ms). You only lose time on your unique input values.

Results of a tenfold - 5,000,000 values:

# Unit: milliseconds
#  expr      min       lq     mean   median       uq      max neval
#     X 882.9045 901.3011 1001.677 940.3421 1168.088 1226.846    10

Even the full names of 5 Million values are calculated within a second.

What about precalculated results? If the input is an already precalculated result of a helper function like mo_fullname, it almost doesn't take any time at all (see 'C' below):

microbenchmark(A = mo_fullname("B_STPHY_AUR"),
               B = mo_fullname("S. aureus"),
               C = mo_fullname("Staphylococcus aureus"),
               times = 10,
               unit = "ms")
# Unit: milliseconds
#  expr       min        lq       mean     median        uq       max neval
#     A 11.364086 11.460537 11.5104799 11.4795330 11.524860 11.818263    10
#     B 11.976454 12.012352 12.1704592 12.0853020 12.210004 12.881737    10
#     C  0.095823  0.102528  0.1167754  0.1153785  0.132629  0.140661    10

So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0001 seconds - it doesn't even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:

microbenchmark(A = mo_species("aureus"),
               B = mo_genus("Staphylococcus"),
               C = mo_fullname("Staphylococcus aureus"),
               D = mo_family("Staphylococcaceae"),
               E = mo_order("Bacillales"),
               F = mo_class("Bacilli"),
               G = mo_phylum("Firmicutes"),
               H = mo_subkingdom("Posibacteria"),
               I = mo_kingdom("Bacteria"),
               times = 10,
               unit = "ms")
# Unit: milliseconds
#  expr      min       lq      mean    median       uq      max neval
#     A 0.105181 0.121314 0.1478538 0.1465265 0.166711 0.211409    10
#     B 0.132558 0.146388 0.1584278 0.1499835 0.164895 0.208477    10
#     C 0.135492 0.160355 0.2341847 0.1884665 0.348857 0.395931    10
#     D 0.109650 0.115727 0.1270481 0.1264130 0.128648 0.168317    10
#     E 0.081574 0.096940 0.0992582 0.0980915 0.101479 0.120477    10
#     F 0.081575 0.088489 0.0988463 0.0989650 0.103365 0.126482    10
#     G 0.091981 0.095333 0.1043568 0.1001530 0.111327 0.129625    10
#     H 0.092610 0.093169 0.1009135 0.0985455 0.101828 0.120406    10
#     I 0.087371 0.091213 0.1069758 0.0941815 0.109302 0.192831    10

Of course, when running mo_phylum("Firmicutes") the function has zero knowledge about the actual microorganism, namely S. aureus. But since the result would be "Firmicutes" too, there is no point in calculating the result. And because this package 'knows' all phyla of all known microorganisms (according to ITIS), it can just return the initial value immediately.

When the system language is non-English and supported by this AMR package, some functions take a little while longer:

mo_fullname("CoNS", language = "en") # or just mo_fullname("CoNS") on an English system
# "Coagulase Negative Staphylococcus (CoNS)"
mo_fullname("CoNS", language = "fr") # or just mo_fullname("CoNS") on a French system
# "Staphylococcus à coagulase négative (CoNS)"
microbenchmark(en = mo_fullname("CoNS", language = "en"),
               de = mo_fullname("CoNS", language = "de"),
               nl = mo_fullname("CoNS", language = "nl"),
               es = mo_fullname("CoNS", language = "es"),
               it = mo_fullname("CoNS", language = "it"),
               fr = mo_fullname("CoNS", language = "fr"),
               pt = mo_fullname("CoNS", language = "pt"),
               times = 10,
               unit = "ms")
# Unit: milliseconds
#  expr       min       lq      mean    median        uq      max neval
#    en  6.093583  6.51724  6.555105  6.562986  6.630663  6.99698   100
#    de 13.934874 14.35137 16.891587 14.462210 14.764658 43.63956   100
#    nl 13.900092 14.34729 15.943268 14.424565 14.581535 43.76283   100
#    es 13.833813 14.34596 14.574783 14.439757 14.653994 17.49168   100
#    it 13.811883 14.36621 15.179060 14.453515 14.812359 43.64284   100
#    fr 13.798683 14.37019 16.344731 14.468775 14.697610 48.62923   100
#    pt 13.789674 14.36244 15.706321 14.443772 14.679905 44.76701   100

Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.


This R package is licensed under the GNU General Public License (GPL) v2.0. In a nutshell, this means that this package:

  • May be used for commercial purposes

  • May be used for private purposes

  • May not be used for patent purposes

  • May be modified, although:

    • Modifications must be released under the same license when distributing the package
    • Changes made to the code must be documented
  • May be distributed, although:

    • Source code must be made available when the package is distributed
    • A copy of the license and copyright notice must be included with the package.
  • Comes with a LIMITATION of liability

  • Comes with NO warranty



Published on CRAN: 2018-12-01


  • Repository moved to GitLab:
  • Function count_all to get all available isolates (that like all portion_* and count_* functions also supports summarise and group_by), the old n_rsi is now an alias of count_all
  • Function get_locale to determine language for language-dependent output for some mo_* functions. This is now the default value for their language parameter, by which the system language will be used at default.
  • Data sets microorganismsDT, microorganisms.prevDT, microorganisms.unprevDT and microorganisms.oldDT to improve the speed of They are for reference only, since they are primarily for internal use of
  • Function read.4D to read from the 4D database of the MMB department of the UMCG
  • Functions mo_authors and mo_year to get specific values about the scientific reference of a taxonomic entry


  • Functions MDRO, BRMO, MRGN and EUCAST_exceptional_phenotypes were renamed to mdro, brmo, mrgn and eucast_exceptional_phenotypes
  • EUCAST_rules was renamed to eucast_rules, the old function still exists as a deprecated function
  • Big changes to the eucast_rules function:
    • Now also applies rules from the EUCAST 'Breakpoint tables for bacteria', version 8.1, 2018, (see Source of the function)
    • New parameter rules to specify which rules should be applied (expert rules, breakpoints, others or all)
    • New parameter verbose which can be set to TRUE to get very specific messages about which columns and rows were affected
    • Better error handling when rules cannot be applied (i.e. new values could not be inserted)
    • The number of affected values will now only be measured once per row/column combination
    • Data set septic_patients now reflects these changes
    • Added parameter pipe for piperacillin (J01CA12), also to the mdro function
    • Small fixes to EUCAST clinical breakpoint rules
  • Added column kingdom to the microorganisms data set, and function mo_kingdom to look up values
  • Tremendous speed improvement for (and subsequently all mo_* functions), as empty values wil be ignored a priori
  • Fewer than 3 characters as input for will return NA
  • Function (and all mo_* wrappers) now supports genus abbreviations with "species" attached"E. species")        # B_ESCHR
    mo_fullname("E. spp.")     # "Escherichia species""S. spp")            # B_STPHY
    mo_fullname("S. species")  # "Staphylococcus species"
  • Added parameter combine_IR (TRUE/FALSE) to functions portion_df and count_df, to indicate that all values of I and R must be merged into one, so the output only consists of S vs. IR (susceptible vs. non-susceptible)
  • Fix for portion_*(..., as_percent = TRUE) when minimal number of isolates would not be met
  • Added parameter also_single_tested for portion_* and count_* functions to also include cases where not all antibiotics were tested but at least one of the tested antibiotics includes the target antimicribial interpretation, see ?portion
  • Using portion_* functions now throws a warning when total available isolate is below parameter minimum
  • Functions, as.rsi, as.mic, as.atc and freq will not set package name as attribute anymore
  • Frequency tables - freq():
    • Support for grouping variables, test with:
      septic_patients %>% 
        group_by(hospital_id) %>% 
    • Support for (un)selecting columns:
      septic_patients %>% 
        freq(hospital_id) %>% 
        select(-count, -cum_count) # only get item, percent, cum_percent
    • Check for hms::is.hms
    • Now prints in markdown at default in non-interactive sessions
    • No longer adds the factor level column and sorts factors on count again
    • Support for class difftime
    • New parameter na, to choose which character to print for empty values
    • New parameter header to turn the header info off (default when markdown = TRUE)
    • New parameter title to manually setbthe title of the frequency table
  • first_isolate now tries to find columns to use as input when parameters are left blank
  • Improvements for MDRO algorithm (function mdro)
  • Data set septic_patients is now a data.frame, not a tibble anymore
  • Removed diacritics from all authors (columns microorganisms$ref and microorganisms.old$ref) to comply with CRAN policy to only allow ASCII characters
  • Fix for mo_property not working properly
  • Fix for eucast_rules where some Streptococci would become ceftazidime R in EUCAST rule 4.5
  • Support for named vectors of class mo, useful for top_freq()
  • ggplot_rsi and scale_y_percent have breaks parameter
  • AI improvements for
    • "CRS" -> Stenotrophomonas maltophilia
    • "CRSM" -> Stenotrophomonas maltophilia
    • "MSSA" -> Staphylococcus aureus
    • "MSSE" -> Staphylococcus epidermidis
  • Fix for join functions
  • Speed improvement for is.rsi.eligible, now 15-20 times faster
  • In g.test, when sum(x) is below 1000 or any of the expected values is below 5, Fisher's Exact Test will be suggested
  • ab_name will try to fall back on as.atc when no results are found
  • Removed the addin to view data sets
  • Percentages will now will rounded more logically (e.g. in freq function)


  • New dependency on package crayon, to support formatted text in the console
  • Dependency tidyr is now mandatory (went to Import field) since portion_df and count_df rely on it
  • Updated vignettes to comply with README


Published on CRAN: 2018-10-01


  • The data set microorganisms now contains all microbial taxonomic data from ITIS (kingdoms Bacteria, Fungi and Protozoa), the Integrated Taxonomy Information System, available via The data set now contains more than 18,000 microorganisms with all known bacteria, fungi and protozoa according ITIS with genus, species, subspecies, family, order, class, phylum and subkingdom. The new data set microorganisms.old contains all previously known taxonomic names from those kingdoms.

  • New functions based on the existing function mo_property:

    • Taxonomic names: mo_phylum, mo_class, mo_order, mo_family, mo_genus, mo_species, mo_subspecies
    • Semantic names: mo_fullname, mo_shortname
    • Microbial properties: mo_type, mo_gramstain
    • Author and year: mo_ref

    They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:

    mo_gramstain("E. coli")
    # [1] "Gram negative"
    mo_gramstain("E. coli", language = "de") # German
    # [1] "Gramnegativ"
    mo_gramstain("E. coli", language = "es") # Spanish
    # [1] "Gram negativo"
    mo_fullname("S. group A", language = "pt") # Portuguese
    # [1] "Streptococcus grupo A"

    Furthermore, former taxonomic names will give a note about the current taxonomic name:

    mo_gramstain("Esc blattae")
    # Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010)
    # [1] "Gram negative"
  • Functions count_R, count_IR, count_I, count_SI and count_S to selectively count resistant or susceptible isolates

    • Extra function count_df (which works like portion_df) to get all counts of S, I and R of a data set with antibiotic columns, with support for grouped variables
  • Function is.rsi.eligible to check for columns that have valid antimicrobial results, but do not have the rsi class yet. Transform the columns of your raw data with: data %>% mutate_if(is.rsi.eligible, as.rsi)

  • Functions and as replacements for as.bactid and is.bactid (since the microoganisms data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The function determines microbial IDs using Artificial Intelligence (AI):"E. coli")
    # [1] B_ESCHR_COL"MRSA")
    # [1] B_STPHY_AUR"S group A")
    # [1] B_STRPTC_GRA

    And with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items:

    thousands_of_E_colis <- rep("E. coli", 25000)
    microbenchmark::microbenchmark(, unit = "s")
    # Unit: seconds
    #         min       median         max  neval
    #  0.01817717  0.01843957  0.03878077    100
  • Added parameter reference_df for, so users can supply their own microbial IDs, name or codes as a reference table

  • Renamed all previous references to bactid to mo, like:

    • Column names inputs of EUCAST_rules, first_isolate and key_antibiotics
    • Column names of datasets microorganisms and septic_patients
    • All old syntaxes will still work with this version, but will throw warnings
  • Function labels_rsi_count to print datalabels on a RSI ggplot2 model

  • Functions as.atc and is.atc to transform/look up antibiotic ATC codes as defined by the WHO. The existing function guess_atc is now an alias of as.atc.

  • Function ab_property and its aliases: ab_name, ab_tradenames, ab_certe, ab_umcg and ab_trivial_nl

  • Introduction to AMR as a vignette

  • Removed clipboard functions as it violated the CRAN policy

  • Renamed septic_patients$sex to septic_patients$gender


  • Added three antimicrobial agents to the antibiotics data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)
  • Added 163 trade names to the antibiotics data set, it now contains 298 different trade names in total, e.g.:
    # [1] "Mupirocin"
    ab_name(c("Bactroban", "Amoxil", "Zithromax", "Floxapen"))
    # [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin"
    ab_atc(c("Bactroban", "Amoxil", "Zithromax", "Floxapen"))
    # [1] "R01AX06" "J01CA04" "J01FA10" "J01CF05"
  • For first_isolate, rows will be ignored when there's no species available
  • Function ratio is now deprecated and will be removed in a future release, as it is not really the scope of this package
  • Fix for as.mic for values ending in zeroes after a real number
  • Small fix where B. fragilis would not be found in the microorganisms.umcg data set
  • Added prevalence column to the microorganisms data set
  • Added parameters minimum and as_percent to portion_df
  • Support for quasiquotation in the functions series count_* and portions_*, and n_rsi. This allows to check for more than 2 vectors or columns.
    septic_patients %>% select(amox, cipr) %>% count_IR()
    # which is the same as:
    septic_patients %>% count_IR(amox, cipr)
    septic_patients %>% portion_S(amcl)
    septic_patients %>% portion_S(amcl, gent)
    septic_patients %>% portion_S(amcl, gent, pita)
  • Edited ggplot_rsi and geom_rsi so they can cope with count_df. The new fun parameter has value portion_df at default, but can be set to count_df.
  • Fix for ggplot_rsi when the ggplot2 package was not loaded
  • Added datalabels function labels_rsi_count to ggplot_rsi
  • Added possibility to set any parameter to geom_rsi (and ggplot_rsi) so you can set your own preferences
  • Fix for joins, where predefined suffices would not be honoured
  • Added parameter quote to the freq function
  • Added generic function diff for frequency tables
  • Added longest en shortest character length in the frequency table (freq) header of class character
  • Support for types (classes) list and matrix for freq
    my_matrix = with(septic_patients, matrix(c(age, gender), ncol = 2))
    For lists, subsetting is possible:
    my_list = list(age = septic_patients$age, gender = septic_patients$gender)
    my_list %>% freq(age)
    my_list %>% freq(gender)


  • More unit tests to ensure better integrity of functions


Published on CRAN: 2018-08-14


  • BREAKING: rsi_df was removed in favour of new functions portion_R, portion_IR, portion_I, portion_SI and portion_S to selectively calculate resistance or susceptibility. These functions are 20 to 30 times faster than the old rsi function. The old function still works, but is deprecated.
    • New function portion_df to get all portions of S, I and R of a data set with antibiotic columns, with support for grouped variables
  • BREAKING: the methodology for determining first weighted isolates was changed. The antibiotics that are compared between isolates (call key antibiotics) to include more first isolates (afterwards called first weighted isolates) are now as follows:
    • Universal: amoxicillin, amoxicillin/clavlanic acid, cefuroxime, piperacillin/tazobactam, ciprofloxacin, trimethoprim/sulfamethoxazole
    • Gram-positive: vancomycin, teicoplanin, tetracycline, erythromycin, oxacillin, rifampicin
    • Gram-negative: gentamicin, tobramycin, colistin, cefotaxime, ceftazidime, meropenem
  • Support for ggplot2
    • New functions geom_rsi, facet_rsi, scale_y_percent, scale_rsi_colours and theme_rsi
    • New wrapper function ggplot_rsi to apply all above functions on a data set:
      • septic_patients %>% select(tobr, gent) %>% ggplot_rsi will show portions of S, I and R immediately in a pretty plot
      • Support for grouped variables, see ?ggplot_rsi
  • Determining bacterial ID:
    • New functions as.bactid and is.bactid to transform/ look up microbial ID's.
    • The existing function guess_bactid is now an alias of as.bactid
    • New Becker classification for Staphylococcus to categorise them into Coagulase Negative Staphylococci (CoNS) and Coagulase Positve Staphylococci (CoPS)
    • New Lancefield classification for Streptococcus to categorise them into Lancefield groups
  • For convience, new descriptive statistical functions kurtosis and skewness that are lacking in base R - they are generic functions and have support for vectors, data.frames and matrices
  • Function g.test to perform the Χ2 distributed G-test, which use is the same as chisq.test
  • Function ratio to transform a vector of values to a preset ratio
    • For example: ratio(c(10, 500, 10), ratio = "1:2:1") would return 130, 260, 130
  • Support for Addins menu in RStudio to quickly insert %in% or %like% (and give them keyboard shortcuts), or to view the datasets that come with this package
  • Function p.symbol to transform p values to their related symbols: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  • Functions clipboard_import and clipboard_export as helper functions to quickly copy and paste from/to software like Excel and SPSS. These functions use the clipr package, but are a little altered to also support headless Linux servers (so you can use it in RStudio Server)
  • New for frequency tables (function freq):
    • A vignette to explain its usage
    • Support for rsi (antimicrobial resistance) to use as input
    • Support for table to use as input: freq(table(x, y))
    • Support for existing functions hist and plot to use a frequency table as input: hist(freq(df$age))
    • Support for as.vector,, as_tibble and format
    • Support for quasiquotation: freq(mydata, mycolumn) is the same as mydata %>% freq(mycolumn)
    • Function top_freq function to return the top/below n items as vector
    • Header of frequency tables now also show Mean Absolute Deviaton (MAD) and Interquartile Range (IQR)
    • Possibility to globally set the default for the amount of items to print, with options(max.print.freq = n) where n is your preset value


  • Improvements for forecasting with resistance_predict and added more examples
  • More antibiotics added as parameters for EUCAST rules
  • Updated version of the septic_patients data set to better reflect the reality
  • Pretty printing for tibbles removed as it is not really the scope of this package
  • Printing of mic and rsi classes now returns all values - use freq to check distributions
  • Improved speed of key antibiotics comparison for determining first isolates
  • Column names for the key_antibiotics function are now generic: 6 for broadspectrum ABs, 6 for Gram-positive specific and 6 for Gram-negative specific ABs
  • Speed improvement for the abname function
  • %like% now supports multiple patterns
  • Frequency tables are now actual data.frames with altered console printing to make it look like a frequency table. Because of this, the parameter toConsole is not longer needed.
  • Fix for freq where the class of an item would be lost
  • Small translational improvements to the septic_patients dataset and the column bactid now has the new class "bactid"
  • Small improvements to the microorganisms dataset (especially for Salmonella) and the column bactid now has the new class "bactid"
  • Combined MIC/RSI values will now be coerced by the rsi and mic functions:
    • as.rsi("<=0.002; S") will return S
    • as.mic("<=0.002; S") will return <=0.002
  • Now possible to coerce MIC values with a space between operator and value, i.e. as.mic("<= 0.002") now works
  • Classes rsi and mic do not add the attribute package.version anymore
  • Added "groups" option for atc_property(..., property). It will return a vector of the ATC hierarchy as defined by the WHO. The new function atc_groups is a convenient wrapper around this.
  • Build-in host check for atc_property as it requires the host set by url to be responsive
  • Improved first_isolate algorithm to exclude isolates where bacteria ID or genus is unavailable
  • Fix for warning hybrid evaluation forced for row_number (924b62) from the dplyr package v0.7.5 and above
  • Support for empty values and for 1 or 2 columns as input for guess_bactid (now called as.bactid)
    • So yourdata %>% select(genus, species) %>% as.bactid() now also works
  • Other small fixes



Published on CRAN: 2018-05-03


  • Full support for Windows, Linux and macOS
  • Full support for old R versions, only R-3.0.0 (April 2013) or later is needed (needed packages may have other dependencies)
  • Function n_rsi to count cases where antibiotic test results were available, to be used in conjunction with dplyr::summarise, see ?rsi
  • Function guess_bactid to determine the ID of a microorganism based on genus/species or known abbreviations like MRSA
  • Function guess_atc to determine the ATC of an antibiotic based on name, trade name, or known abbreviations
  • Function freq to create frequency tables, with additional info in a header
  • Function MDRO to determine Multi Drug Resistant Organisms (MDRO) with support for country-specific guidelines.
  • New algorithm to determine weighted isolates, can now be "points" or "keyantibiotics", see ?first_isolate
  • New print format for tibbles and data.tables


  • Fixed rsi class for vectors that contain only invalid antimicrobial interpretations
  • Renamed dataset ablist to antibiotics
  • Renamed dataset bactlist to microorganisms
  • Added common abbreviations and trade names to the antibiotics dataset
  • Added more microorganisms to the microorganisms dataset
  • Added analysis examples on help page of dataset septic_patients
  • Added support for character vector in join functions
  • Added warnings when a join results in more rows after than before the join
  • Altered %like% to make it case insensitive
  • For parameters of functions first_isolate and EUCAST_rules column names are now case-insensitive
  • Functions as.rsi and as.mic now add the package name and version as attributes


  • Expanded with more examples
  • Added ORCID of authors to DESCRIPTION file
  • Added unit testing with the testthat package
  • Added build tests for Linux and macOS using Travis CI (
  • Added line coverage checking using CodeCov (


Published on CRAN: 2018-03-14

  • EUCAST_rules applies for amoxicillin even if ampicillin is missing
  • Edited column names to comply with GLIMS, the laboratory information system
  • Added more valid MIC values
  • Renamed 'Daily Defined Dose' to 'Defined Daily Dose'
  • Added barplots for rsi and mic classes


Published on CRAN: 2018-02-22

  • First submission to CRAN.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.5.0 by Matthijs S. Berends, 4 months ago

Report a bug at

Browse source code at

Authors: Matthijs S. Berends [aut, cre] , Christian F. Luz [aut, rev] , Erwin E.A. Hassing [ctb] , Corinna Glasner [ths] , Alex W. Friedrich [ths] , Bhanu Sinha [ths]

Documentation:   PDF Manual  

GPL-2 | file LICENSE license

Imports backports, curl, crayon, data.table, dplyr, hms, knitr, rlang, rvest, tidyr, xml2

Suggests covr, ggplot2, rmarkdown, rstudioapi, testthat

See at CRAN