vignettes/datasets.Rmd
datasets.Rmd
NEWS.md
- AMR
1.6.0.9047AMR
1.6.0.9048All antibiotic class selectors (such as carbapenems()
, aminoglycosides()
) can now be used for filtering as well, making all their accompanying filter_*()
functions redundant (such as filter_carbapenems()
, filter_aminoglycosides()
). These functions are now deprecated and will be removed in a next release.
+
+# select columns with results for carbapenems
+example_isolates[, carbapenems()] # base R
+example_isolates %>% select(carbapenems()) # dplyr
+
+# filter rows for resistance in any carbapenem
+example_isolates[any(carbapenems() == "R"), ] # base R
+example_isolates %>% filter(any(carbapenems() == "R")) # dplyr
+example_isolates %>% filter(if_any(carbapenems(), ~.x == "R")) # dplyr (formal)
+
+# filter rows for resistance in all carbapenems
+example_isolates[all(carbapenems() == "R"), ] # base R
+example_isolates[carbapenems() == "R", ]
+example_isolates %>% filter(all(carbapenems() == "R")) # dplyr
+example_isolates %>% filter(carbapenems() == "R")
first_isolate()
and key_antimicrobials()
functions has been completely rewritten.betalactams()
as additional antbiotic column selector and function filter_betalactams()
as additional antbiotic column filter. The group of betalactams consists of all carbapenems, cephalosporins and penicillins.betalactams()
as additional antbiotic column selector and function filter_betalactams()
as additional antbiotic column filter. The group of betalactams consists of all carbapenems, cephalosporins and penicillins.ggplot()
method for resistance_predict()
Now checks if pattern
is a valid regular expression
Added %unlike%
and %unlike_case%
(as negations of the existing %like%
and %like_case%
). This greatly improves readability:
+if (!grepl("EUCAST", guideline)) ... # same: @@ -307,17 +332,17 @@
Updated skimr::skim()
usage for MIC values to also include 25th and 75th percentilesFix for plotting missing MIC/disk diffusion values Updated join functions to always use -dplyr
join functions if thedplyr
package is installed - now also preserving grouped variablesUpdates for filtering on antibiotic classes (e.g., using filter_carbapenems()
): +Updates for filtering on antibiotic classes (e.g., using filter_carbapenems()
):
Support for dplyr groups
Support for base R row filtering:
-+@@ -357,7 +382,7 @@dim(example_isolates) #> [1] 2000 49 -example_isolates[filter_carbapenems(), ] +example_isolates[filter_carbapenems(), ] #> ℹ Applying `filter_carbapenems()`: values in any of columns 'IPM' (imipenem) #> or 'MEM' (meropenem) are either "R", "S" or "I" #> [1] 962 49
Added argument
only_rsi_columns
for some functions, which defaults toFALSE
, to indicate if the functions must only be applied to columns that are of class<rsi>
(i.e., transformed withas.rsi()
). This increases speed since automatic determination of antibiotic columns is not needed anymore. Affected functions are:
- All antibiotic selector functions (
-ab_class()
and its wrappers, such asaminoglycosides()
,carbapenems()
,penicillins()
)- All antibiotic filter functions (
+filter_ab_class()
and its wrappers, such asfilter_aminoglycosides()
,filter_carbapenems()
,filter_penicillins()
)- All antibiotic filter functions (
filter_ab_class()
and its wrappers, such asfilter_aminoglycosides()
,filter_carbapenems()
,filter_penicillins()
)eucast_rules()
- @@ -365,21 +390,21 @@
mdro()
(including wrappers such asbrmo()
,mrgn()
andeucast_exceptional_phenotypes()
)- -
Functions
-oxazolidinones()
(an antibiotic selector function) andfilter_oxazolidinones()
(an antibiotic filter function) to select/filter on e.g. linezolid and tedizolid+Functions
+oxazolidinones()
(an antibiotic selector function) andfilter_oxazolidinones()
(an antibiotic filter function) to select/filter on e.g. linezolid and tedizolidlibrary(dplyr) x <- example_isolates %>% select(date, hospital_id, oxazolidinones()) #> Selecting oxazolidinones: column 'LNZ' (linezolid) -x <- example_isolates %>% filter_oxazolidinones() +x <- example_isolates %>% filter_oxazolidinones() #> Filtering on oxazolidinones: value in column `LNZ` (linezolid) is either "R", "S" or "I"
Support for custom MDRO guidelines, using the new
custom_mdro_guideline()
function, please seemdro()
for additional info
ggplot()
generics for classes<mic>
and<disk>
Function
-mo_is_yeast()
, which determines whether a microorganism is a member of the taxonomic class Saccharomycetes or the taxonomic order Saccharomycetales:+mo_kingdom(c("Aspergillus", "Candida")) #> [1] "Fungi" "Fungi" @@ -391,7 +416,7 @@ example_isolates[which(mo_is_yeast()), ] # base R example_isolates %>% filter(mo_is_yeast()) # dplyr
The
-mo_type()
function has also been updated to reflect this change:+mo_type(c("Aspergillus", "Candida")) # [1] "Fungi" "Yeasts" @@ -401,7 +426,7 @@
Added Pretomanid (PMD, J04AK08) to the
antibiotics
data setMIC values (see
-as.mic()
) can now be used in any mathematical processing, such as usage inside functionsmin()
,max()
,range()
, and with binary operators (+
,-
, etc.). This allows for easy distribution analysis and fast filtering on MIC values:+x <- random_mic(10) x @@ -484,7 +509,7 @@
Functions
-get_episode()
andis_new_episode()
to determine (patient) episodes which are not necessarily based on microorganisms. Theget_episode()
function returns the index number of the episode per group, while theis_new_episode()
function returns valuesTRUE
/FALSE
to indicate whether an item in a vector is the start of a new episode. They also supportdplyr
s grouping (i.e. usinggroup_by()
):+library(dplyr) example_isolates %>% @@ -538,7 +563,7 @@
mdr_cmi2012()
,- -
eucast_exceptional_phenotypes()
+# to select first isolates that are Gram-negative # and view results of cephalosporins and aminoglycosides: @@ -550,7 +575,7 @@
For antibiotic selection functions (such as
-cephalosporins()
,aminoglycosides()
) to select columns based on a certain antibiotic group, the dependency on thetidyselect
package was removed, meaning that they can now also be used without the need to have this package installed and now also work in base R function calls (they rely on R 3.2 or later):+# above example in base R: example_isolates[which(first_isolate() & mo_is_gram_negative()), @@ -600,7 +625,7 @@
Data set
intrinsic_resistant
. This data set contains all bug-drug combinations where the ‘bug’ is intrinsic resistant to the ‘drug’ according to the latest EUCAST insights. It contains just two columns:microorganism
andantibiotic
.Curious about which enterococci are actually intrinsic resistant to vancomycin?
-+library(AMR) library(dplyr) @@ -623,7 +648,7 @@
Support for using
-dplyr
’sacross()
to interpret MIC values or disk zone diameters, which also automatically determines the column with microorganism names or codes.+# until dplyr 1.0.0 your_data %>% mutate_if(is.mic, as.rsi) @@ -641,7 +666,7 @@
Added intelligent data cleaning to
-as.disk()
, so numbers can also be extracted from text and decimal numbers will always be rounded up:+as.disk(c("disk zone: 23.4 mm", 23.4)) #> Class <disk> @@ -701,7 +726,7 @@
Function
ab_from_text()
to retrieve antimicrobial drug names, doses and forms of administration from clinical texts in e.g. health care records, which also corrects for misspelling since it usesas.ab()
internallyTidyverse selection helpers for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows selection helpers, like
-dplyr::select()
andtidyr::pivot_longer()
:+- -
Added
mo_domain()
as an alias tomo_kingdom()
- -
Added function
filter_penicillins()
to filter isolates on a specific result in any column with a name in the antimicrobial ‘penicillins’ class (more specific: ATC subgroup Beta-lactam antibacterials, penicillins)- +
Added official antimicrobial names to all
filter_ab_class()
functions, such asfilter_aminoglycosides()
- +
Added function
filter_penicillins()
to filter isolates on a specific result in any column with a name in the antimicrobial ‘penicillins’ class (more specific: ATC subgroup Beta-lactam antibacterials, penicillins)Added official antimicrobial names to all
filter_ab_class()
functions, such asfilter_aminoglycosides()
Added antibiotics code “FOX1” for cefoxitin screening (abbreviation “cfsc”) to the
antibiotics
data setAdded Monuril as trade name for fosfomycin
- @@ -759,7 +784,7 @@
Added argument
conserve_capped_values
toas.rsi()
for interpreting MIC values - it makes sure that values starting with “<” (but not “<=”) will always return “S” and values starting with “>” (but not “>=”) will always return “R”. The default behaviour ofas.rsi()
has not changed, so you need to specifically doas.rsi(..., conserve_capped_values = TRUE)
.Changed the summary for class
<rsi>
, to highlight the %SI vs. %RImproved error handling, giving more useful info when functions return an error
- -
Any progress bar will now only show in interactive mode (i.e. not in R Markdown)
- +
Speed improvement for
mdro()
andfilter_ab_class()
Speed improvement for
mdro()
andfilter_ab_class()
New option
arrows_textangled
forggplot_pca()
to indicate whether the text at the end of the arrows should be angled (defaults toTRUE
, as it was in previous versions)Added parenteral DDD to benzylpenicillin
- @@ -887,7 +912,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Fixed a bug where
as.mic()
could not handle dots without a leading zero (like"<=.25
)Fixed important floating point error for some MIC comparisons in EUCAST 2020 guideline
Interpretation from MIC values (and disk zones) to R/SI can now be used with
-mutate_at()
of thedplyr
package:+yourdata %>% mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = "E. coli") @@ -915,7 +940,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Support for LOINC codes in the
-antibiotics
data set. Useab_loinc()
to retrieve LOINC codes, or use a LOINC code for input in anyab_*
function:+ab_loinc("ampicillin") #> [1] "21066-6" "3355-5" "33562-0" "33919-2" "43883-8" "43884-6" "87604-5" @@ -926,7 +951,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Support for SNOMED CT codes in the
-microorganisms
data set. Usemo_snomed()
to retrieve SNOMED codes, or use a SNOMED code for input in anymo_*
function:+mo_snomed("S. aureus") #> [1] 115329001 3092008 113961008 @@ -990,11 +1015,11 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
If you were dependent on the old Enterobacteriaceae family e.g. by using in your code:
-+if (mo_family(somebugs) == "Enterobacteriaceae") ...
then please adjust this to:
-+@@ -1008,7 +1033,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/if (mo_order(somebugs) == "Enterobacterales") ...
Functions
-susceptibility()
andresistance()
as aliases ofproportion_SI()
andproportion_R()
, respectively. These functions were added to make it more clear that “I” should be considered susceptible and not resistant.+library(dplyr) example_isolates %>% @@ -1037,7 +1062,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
More intelligent way of coping with some consonants like “l” and “r”
Added a score (a certainty percentage) to
-mo_uncertainties()
, that is calculated using the Levenshtein distance:+as.mo(c("Stafylococcus aureus", "staphylokok aureuz")) @@ -1095,14 +1120,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Determination of first isolates now excludes all ‘unknown’ microorganisms at default, i.e. microbial code
-"UNKNOWN"
. They can be included with the new argumentinclude_unknown
:+first_isolate(..., include_unknown = TRUE)
For WHONET users, this means that all records/isolates with organism code
"con"
(contamination) will be excluded at default, sinceas.mo("con") = "UNKNOWN"
. The function always shows a note with the number of ‘unknown’ microorganisms that were included or excluded.For code consistency, classes
-ab
andmo
will now be preserved in any subsetting or assignment. For the sake of data integrity, this means that invalid assignments will now result inNA
:+# how it works in base R: x <- factor("A") @@ -1127,7 +1152,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Function
-bug_drug_combinations()
to quickly get adata.frame
with the results of all bug-drug combinations in a data set. The column containing microorganism codes is guessed automatically and its input is transformed withmo_shortname()
at default:+x <- bug_drug_combinations(example_isolates) #> NOTE: Using column `mo` as input for `col_mo`. @@ -1150,13 +1175,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ #> 4 Gram-negative AMX 227 0 405 632 #> NOTE: Use 'format()' on this result to get a publicable/printable format.
You can format this to a printable format, ready for reporting or exporting to e.g. Excel with the base R
-format()
function:+format(x, combine_IR = FALSE)
Additional way to calculate co-resistance, i.e. when using multiple antimicrobials as input for
-portion_*
functions orcount_*
functions. This can be used to determine the empiric susceptibility of a combination therapy. A new argumentonly_all_tested
(which defaults toFALSE
) replaces the oldalso_single_tested
and can be used to select one of the two methods to count isolates and calculate portions. The difference can be seen in this example table (which is also on theportion
andcount
help pages), where the %SI is being determined:+# -------------------------------------------------------------------- # only_all_tested = FALSE only_all_tested = TRUE @@ -1178,7 +1203,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
-
tibble
printing support for classesrsi
,mic
,disk
,ab
mo
. When usingtibble
s containing antimicrobial columns, valuesS
will print in green, valuesI
will print in yellow and valuesR
will print in red. Microbial IDs (classmo
) will emphasise on the genus and species, not on the kingdom.+# (run this on your own console, as this page does not support colour printing) library(dplyr) @@ -1229,7 +1254,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
- The
name
ofRIF
is now Rifampicin instead of Rifampin- The
antibiotics
data set is now sorted by name and all cephalosporins now have their generation between brackets- Speed improvement for
-guess_ab_col()
which is now 30 times faster for antibiotic abbreviations- Improved
+filter_ab_class()
to be more reliable and to support 5th generation cephalosporins- Improved
filter_ab_class()
to be more reliable and to support 5th generation cephalosporins- Function
availability()
now usesportion_R()
instead ofportion_IR()
, to comply with EUCAST insights- Functions
age()
andage_groups()
now have ana.rm
argument to remove empty values- Renamed function
@@ -1260,7 +1285,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/p.symbol()
top_symbol()
(the former is now deprecated and will be removed in a future version)
Function
-rsi_df()
to transform adata.frame
to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functionscount_df()
andportion_df()
to immediately show resistance percentages and number of available isolates:+septic_patients %>% select(AMX, CIP) %>% @@ -1287,7 +1312,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
- UPEC (Uropathogenic E. coli)
All these lead to the microbial ID of E. coli:
-+as.mo("UPEC") # B_ESCHR_COL @@ -1391,7 +1416,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
when all values are unique it now shows a message instead of a warning
support for boxplots:
-+septic_patients %>% freq(age) %>% @@ -1484,30 +1509,30 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:
----filter_aminoglycosides() -filter_carbapenems() -filter_cephalosporins() -filter_1st_cephalosporins() -filter_2nd_cephalosporins() -filter_3rd_cephalosporins() -filter_4th_cephalosporins() -filter_fluoroquinolones() -filter_glycopeptides() -filter_macrolides() -filter_tetracyclines()
The
antibiotics
data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in theantibiotics
data set. For example:+-septic_patients %>% filter_glycopeptides(result = "R") +filter_aminoglycosides() +filter_carbapenems() +filter_cephalosporins() +filter_1st_cephalosporins() +filter_2nd_cephalosporins() +filter_3rd_cephalosporins() +filter_4th_cephalosporins() +filter_fluoroquinolones() +filter_glycopeptides() +filter_macrolides() +filter_tetracyclines()
The
+antibiotics
data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in theantibiotics
data set. For example:++septic_patients %>% filter_glycopeptides(result = "R") # Filtering on glycopeptide antibacterials: any of `vanc` or `teic` is R -septic_patients %>% filter_glycopeptides(result = "R", scope = "all") +septic_patients %>% filter_glycopeptides(result = "R", scope = "all") # Filtering on glycopeptide antibacterials: all of `vanc` and `teic` is R
All
-ab_*
functions are deprecated and replaced byatc_*
functions:+ab_property -> atc_property() ab_name -> atc_name() @@ -1528,7 +1553,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
New function
age_groups()
to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic AMR data analysis per age group.New function
-ggplot_rsi_predict()
as well as the base Rplot()
function can now be used for resistance prediction calculated withresistance_predict()
:+x <- resistance_predict(septic_patients, col_ab = "amox") plot(x) @@ -1536,13 +1561,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Functions
-filter_first_isolate()
andfilter_first_weighted_isolate()
to shorten and fasten filtering on data sets with antimicrobial results, e.g.:+septic_patients %>% filter_first_isolate(...) # or filter_first_isolate(septic_patients, ...)
is equal to:
-+septic_patients %>% mutate(only_firsts = first_isolate(septic_patients, ...)) %>% @@ -1575,7 +1600,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Now handles incorrect spelling, like
-i
instead ofy
andf
instead ofph
:+# mo_fullname() uses as.mo() internally @@ -1587,7 +1612,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default
-allow_uncertain = TRUE
is equal to uncertainty level 2. Run?as.mo
for more info about these levels.+# equal: as.mo(..., allow_uncertain = TRUE) @@ -1602,7 +1627,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
All microbial IDs that found are now saved to a local file
~/.Rhistory_mo
. Use the new functionclean_mo_history()
to delete this file, which resets the algorithms.Incoercible results will now be considered ‘unknown’, MO code
-UNKNOWN
. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:+mo_genus("qwerty", language = "es") # Warning: @@ -1652,7 +1677,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:
-+# Determine genus of microorganisms (mo) in `septic_patients` data set: # OLD WAY @@ -1735,7 +1760,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Fewer than 3 characters as input for
as.mo
will return NAFunction
-as.mo
(and allmo_*
wrappers) now supports genus abbreviations with “species” attached+as.mo("E. species") # B_ESCHR mo_fullname("E. spp.") # "Escherichia species" @@ -1752,7 +1777,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Support for grouping variables, test with:
-+septic_patients %>% group_by(hospital_id) %>% @@ -1760,7 +1785,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Support for (un)selecting columns:
-+septic_patients %>% freq(hospital_id) %>% @@ -1839,7 +1864,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:
-+mo_gramstain("E. coli") # [1] "Gram negative" @@ -1850,7 +1875,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ 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) @@ -1865,7 +1890,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Function
is.rsi.eligible
to check for columns that have valid antimicrobial results, but do not have thersi
class yet. Transform the columns of your raw data with:data %>% mutate_if(is.rsi.eligible, as.rsi)
Functions
-as.mo
andis.mo
as replacements foras.bactid
andis.bactid
(since themicrooganisms
data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. Theas.mo
function determines microbial IDs using intelligent rules:+as.mo("E. coli") # [1] B_ESCHR_COL @@ -1874,7 +1899,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ as.mo("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(as.mo(thousands_of_E_colis), unit = "s") @@ -1908,7 +1933,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
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.:+ab_official("Bactroban") # [1] "Mupirocin" @@ -1925,7 +1950,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Added arguments
minimum
andas_percent
toportion_df
Support for quasiquotation in the functions series
-count_*
andportions_*
, andn_rsi
. This allows to check for more than 2 vectors or columns.+septic_patients %>% select(amox, cipr) %>% count_IR() # which is the same as: @@ -1945,12 +1970,12 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Added longest en shortest character length in the frequency table (
freq
) header of classcharacter
Support for types (classes) list and matrix for
-freq