NEWS.md
- Tidyverse selections, 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 Tidyverse selections, like dplyr::select()
and tidyr::pivot_longer()
:
library(dplyr) + +example_isolates %>% + select(carbapenems()) +#> Selecting carbapenems: `IPM` (imipenem), `MEM` (meropenem) + +tibble(J01CA01 = "S") %>% + select(penicillins()) +#> Selecting beta-lactams/penicillins: `J01CA01` (ampicillin)
eucast_rules()
would not work on a tibble when the tibble
or dplyr
package was loaded*_join_microorganisms()
functions now return the original data class (e.g. tibbles and data.tables)as.ab()
would return an error on invalid input valuesrsi_df()
, proportion_df()
and count_df()
-rsi_df()
, proportion_df()
and count_df()
, and fixed a bug where not all different antimicrobial results were added as rowsfilter_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)filter_ab_class()
functions, such as filter_aminoglycosides()
antibiotics
data set<mo>
and <Date>
pca()
functionggplot_pca()
functionFixed 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 the dplyr
package:
yourdata %>% - mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = "E. coli") ++ mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = .$mybacteria)yourdata %>% + mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = "E. coli") yourdata %>% - mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo = .$mybacteria)
Added antibiotic abbreviations for a laboratory manufacturer (GLIMS) for cefuroxime, cefotaxime, ceftazidime, cefepime, cefoxitin and trimethoprim/sulfamethoxazole
Added uti
(as abbreviation of urinary tract infections) as parameter to as.rsi()
, so interpretation of MIC values and disk zones can be made dependent on isolates specifically from UTIs
This software is now out of beta and considered stable. Nonetheless, this package will be developed continually.
-as.rsi()
and inferred resistance and susceptibility using eucast_rules()
.Support for LOINC codes in the antibiotics
data set. Use ab_loinc()
to retrieve LOINC codes, or use a LOINC code for input in any ab_*
function:
ab_loinc("ampicillin") +ab_loinc("ampicillin") #> [1] "21066-6" "3355-5" "33562-0" "33919-2" "43883-8" "43884-6" "87604-5" ab_name("21066-6") #> [1] "Ampicillin" @@ -409,7 +426,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") +-mo_snomed("S. aureus") #> [1] 115329001 3092008 113961008 mo_name(115329001) #> [1] "Staphylococcus aureus" @@ -472,21 +489,21 @@ 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") ...if (mo_family(somebugs) == "Enterobacteriaceae") ...then please adjust this to:
-+if (mo_order(somebugs) == "Enterobacterales") ...if (mo_order(somebugs) == "Enterobacterales") ...+-New
+New
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) +library(dplyr) example_isolates %>% group_by(bug = mo_name(mo)) %>% summarise(amoxicillin = resistance(AMX), @@ -513,7 +530,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", +as.mo(c("Stafylococcus aureus", "staphylokok aureuz")) #> Warning: #> Results of two values were guessed with uncertainty. Use mo_uncertainties() to review them. @@ -570,12 +587,12 @@ 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 parameterinclude_unknown
:+first_isolate(..., include_unknown = TRUE)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: +-# how it works in base R: x <- factor("A") x[1] <- "B" #> Warning message: @@ -592,13 +609,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/Renamed data set
septic_patients
toexample_isolates
+-New
+New
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) +x <- bug_drug_combinations(example_isolates) #> NOTE: Using column `mo` as input for `col_mo`. x[1:4, ] #> mo ab S I R total @@ -619,11 +636,11 @@ 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)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 parameteronly_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 # ----------------------- ----------------------- # Drug A Drug B include as include as include as include as @@ -643,7 +660,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) +# (run this on your own console, as this page does not support colour printing) library(dplyr) example_isolates %>% select(mo:AMC) %>% @@ -718,13 +735,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/AMR 0.7.1 2019-06-23
-+-New
+New
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 %>% +septic_patients %>% select(AMX, CIP) %>% rsi_df() # antibiotic interpretation value isolates @@ -749,7 +766,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") +as.mo("UPEC") # B_ESCHR_COL mo_name("UPEC") # "Escherichia coli" @@ -799,9 +816,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/AMR 0.7.0 2019-06-03
-+-New
+New
- Support for translation of disk diffusion and MIC values to RSI values (i.e. antimicrobial interpretations). Supported guidelines are EUCAST (2011 to 2019) and CLSI (2011 to 2019). Use
as.rsi()
on an MIC value (created withas.mic()
), a disk diffusion value (created with the newas.disk()
) or on a complete date set containing columns with MIC or disk diffusion values.- Function
mo_name()
as alias ofmo_fullname()
@@ -856,7 +873,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 %>% +septic_patients %>% freq(age) %>% boxplot() # grouped boxplots: @@ -916,9 +933,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/- Contains the complete manual of this package and all of its functions with an explanation of their parameters
- Contains a comprehensive tutorial about how to conduct antimicrobial resistance analysis, import data from WHONET or SPSS and many more.
-+-New
+New
BREAKING: removed deprecated functions, parameters and references to ‘bactid’. Use
as.mo()
to identify an MO code.- @@ -947,7 +964,7 @@ 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_aminoglycosides() filter_carbapenems() filter_cephalosporins() filter_1st_cephalosporins() @@ -959,14 +976,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/ 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") +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") # Filtering on glycopeptide antibacterials: all of `vanc` and `teic` is RAll
-ab_*
functions are deprecated and replaced byatc_*
functions:ab_property -> atc_property() +ab_property -> atc_property() ab_name -> atc_name() ab_official -> atc_official() ab_trivial_nl -> atc_trivial_nl() @@ -985,17 +1002,17 @@ 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 antimicrobial resistance 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") +x <- resistance_predict(septic_patients, col_ab = "amox") plot(x) ggplot_rsi_predict(x)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(...) +septic_patients %>% filter_first_isolate(...) # or filter_first_isolate(septic_patients, ...)is equal to:
-septic_patients %>% +@@ -1026,7 +1043,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/septic_patients %>% mutate(only_firsts = first_isolate(septic_patients, ...)) %>% filter(only_firsts == TRUE) %>% select(-only_firsts)
Now handles incorrect spelling, like
-i
instead ofy
andf
instead ofph
:# mo_fullname() uses as.mo() internally +# mo_fullname() uses as.mo() internally mo_fullname("Sthafilokockus aaureuz") #> [1] "Staphylococcus aureus" @@ -1036,7 +1053,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: +# equal: as.mo(..., allow_uncertain = TRUE) as.mo(..., allow_uncertain = 2) @@ -1049,7 +1066,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") +@@ -1097,7 +1114,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/mo_genus("qwerty", language = "es") # Warning: # one unique value (^= 100.0%) could not be coerced and is considered 'unknown': "qwerty". Use mo_failures() to review it. #> [1] "(género desconocido)"
Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:
-# Determine genus of microorganisms (mo) in `septic_patients` data set: +# Determine genus of microorganisms (mo) in `septic_patients` data set: # OLD WAY septic_patients %>% mutate(genus = mo_genus(mo)) %>% @@ -1142,9 +1159,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/AMR 0.5.0 2018-11-30
-+-New
+New
- Repository moved to GitLab: https://gitlab.com/msberends/AMR
@@ -1180,7 +1197,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” attachedas.mo("E. species") # B_ESCHR +@@ -1195,13 +1212,13 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/as.mo("E. species") # B_ESCHR mo_fullname("E. spp.") # "Escherichia species" as.mo("S. spp") # B_STPHY mo_fullname("S. species") # "Staphylococcus species"
Support for grouping variables, test with:
-septic_patients %>% +septic_patients %>% group_by(hospital_id) %>% freq(gender)Support for (un)selecting columns:
-septic_patients %>% +@@ -1261,9 +1278,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/septic_patients %>% freq(hospital_id) %>% select(-count, -cum_count) # only get item, percent, cum_percentAMR 0.4.0 2018-10-01
-+-New
+New
The data set
microorganisms
now contains all microbial taxonomic data from ITIS (kingdoms Bacteria, Fungi and Protozoa), the Integrated Taxonomy Information System, available via https://itis.gov. 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 setmicroorganisms.old
contains all previously known taxonomic names from those kingdoms.- @@ -1279,7 +1296,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") +mo_gramstain("E. coli") # [1] "Gram negative" mo_gramstain("E. coli", language = "de") # German # [1] "Gramnegativ" @@ -1288,7 +1305,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") +@@ -1301,14 +1318,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/mo_gramstain("Esc blattae") # Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010) # [1] "Gram negative"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") +as.mo("E. coli") # [1] B_ESCHR_COL as.mo("MRSA") # [1] B_STPHY_AUR as.mo("S group A") # [1] B_STRPTC_GRAAnd 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) +thousands_of_E_colis <- rep("E. coli", 25000) microbenchmark::microbenchmark(as.mo(thousands_of_E_colis), unit = "s") # Unit: seconds # min median max neval @@ -1340,7 +1357,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") +ab_official("Bactroban") # [1] "Mupirocin" ab_name(c("Bactroban", "Amoxil", "Zithromax", "Floxapen")) # [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin" @@ -1355,7 +1372,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/Added parameters
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() +septic_patients %>% select(amox, cipr) %>% count_IR() # which is the same as: septic_patients %>% count_IR(amox, cipr) @@ -1373,10 +1390,10 @@ 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
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) +@@ -1394,9 +1411,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/my_list = list(age = septic_patients$age, gender = septic_patients$gender) my_list %>% freq(age) my_list %>% freq(gender)AMR 0.3.0 2018-08-14
-+-New
+New
- BREAKING:
rsi_df
was removed in favour of new functionsportion_R
,portion_IR
,portion_I
,portion_SI
andportion_S
to selectively calculate resistance or susceptibility. These functions are 20 to 30 times faster than the oldrsi
function. The old function still works, but is deprecated. @@ -1531,9 +1548,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/AMR 0.2.0 2018-05-03
-+@@ -272,7 +272,7 @@-New
+New
- 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)
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 373d9ea5..f3164d9f 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -10,7 +10,7 @@ articles: WHONET: WHONET.html benchmarks: benchmarks.html resistance_predict: resistance_predict.html -last_built: 2020-06-11T17:56Z +last_built: 2020-06-16T23:38Z urls: reference: https://msberends.gitlab.io/AMR/reference article: https://msberends.gitlab.io/AMR/articles diff --git a/docs/reference/antibiotic_class_selectors.html b/docs/reference/antibiotic_class_selectors.html new file mode 100644 index 00000000..f4e2195b --- /dev/null +++ b/docs/reference/antibiotic_class_selectors.html @@ -0,0 +1,318 @@ + + + + + + + + +Antibiotic class selectors — antibiotic_class_selectors • AMR (for R) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +++ + + + + + + + diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index 2554f2b0..2dd575ba 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -82,7 +82,7 @@+ + + + + + +++ + + ++ + ++ +++ +Use these selection helpers inside any function that allows Tidyverse selections, like
+dplyr::select()
ortidyr::pivot_longer()
. They help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations.aminoglycosides() + +carbapenems() + +cephalosporins() + +cephalosporins_1st() + +cephalosporins_2nd() + +cephalosporins_3rd() + +cephalosporins_4th() + +cephalosporins_5th() + +fluoroquinolones() + +glycopeptides() + +macrolides() + +penicillins() + +tetracyclines()+ + +Details
+ +All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a selector like e.g.
+aminoglycosides()
will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.These functions only work if the
+tidyselect
package is installed, that comes with thedplyr
package. An error will be thrown iftidyselect
package is not installed, or if the functions are used outside a function that allows Tidyverse selections likeselect()
orpivot_longer()
.See also
+ ++ +
filter_ab_class()
for thefilter()
equivalent.Examples
+if (require("dplyr")) { + + # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem): + example_isolates %>% + select(carbapenems()) + + + # this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB': + example_isolates %>% + select(mo, aminoglycosides()) + + + data.frame(irrelevant = "value", + J01CA01 = "S") %>% # ATC code of ampicillin + select(penicillins()) # so the 'J01CA01' column is selected + +}+ab_class -+ an antimicrobial class, like
"carbapenems"
, as can be found inantibiotics$group
an antimicrobial class, like
"carbapenems"
. The columnsgroup
,atc_group1
andatc_group2
of the antibiotics data set will be searched (case-insensitive) for this value.result @@ -290,7 +290,7 @@Details
-The columns
+group
,atc_group1
andatc_group2
of the antibiotics data set will be searched for the input given inab_class
(case-insensitive). Next,x
will be checked for column names with a value in any abbreviation, code or official name found in the antibiotics data set.All columns of
x
will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a filter function like e.g.filter_aminoglycosides()
will include column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc.Stable lifecycle
@@ -298,6 +298,9 @@
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.
+See also
+ +
antibiotic_class_selectors()
for theselect()
equivalent.Examples
if (FALSE) { diff --git a/docs/reference/index.html b/docs/reference/index.html index 274ff04c..3d951d31 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 38a73684..320f21f0 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -24,6 +24,9 @@+ https://msberends.gitlab.io/AMR/reference/age_groups.html + https://msberends.gitlab.io/AMR/reference/antibiotic_class_selectors.html +diff --git a/man/antibiotic_class_selectors.Rd b/man/antibiotic_class_selectors.Rd new file mode 100644 index 00000000..71e5712b --- /dev/null +++ b/man/antibiotic_class_selectors.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ab_class_selectors.R +\name{antibiotic_class_selectors} +\alias{antibiotic_class_selectors} +\alias{aminoglycosides} +\alias{carbapenems} +\alias{cephalosporins} +\alias{cephalosporins_1st} +\alias{cephalosporins_2nd} +\alias{cephalosporins_3rd} +\alias{cephalosporins_4th} +\alias{cephalosporins_5th} +\alias{fluoroquinolones} +\alias{glycopeptides} +\alias{macrolides} +\alias{penicillins} +\alias{tetracyclines} +\title{Antibiotic class selectors} +\usage{ +aminoglycosides() + +carbapenems() + +cephalosporins() + +cephalosporins_1st() + +cephalosporins_2nd() + +cephalosporins_3rd() + +cephalosporins_4th() + +cephalosporins_5th() + +fluoroquinolones() + +glycopeptides() + +macrolides() + +penicillins() + +tetracyclines() +} +\description{ +Use these selection helpers inside any function that allows \href{https://tidyselect.r-lib.org/reference/language.html}{Tidyverse selections}, like \code{dplyr::select()} or \code{tidyr::pivot_longer()}. They help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. +} +\details{ +All columns will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a selector like e.g. \code{\link[=aminoglycosides]{aminoglycosides()}} will pick up column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc. + +These functions only work if the \code{tidyselect} package is installed, that comes with the \code{dplyr} package. An error will be thrown if \code{tidyselect} package is not installed, or if the functions are used outside a function that allows Tidyverse selections like \code{select()} or \code{pivot_longer()}. +} +\examples{ +if (require("dplyr")) { + + # this will select columns 'IPM' (imipenem) and 'MEM' (meropenem): + example_isolates \%>\% + select(carbapenems()) + + + # this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB': + example_isolates \%>\% + select(mo, aminoglycosides()) + + + data.frame(irrelevant = "value", + J01CA01 = "S") \%>\% # ATC code of ampicillin + select(penicillins()) # so the 'J01CA01' column is selected + +} +} +\seealso{ +\code{\link[=filter_ab_class]{filter_ab_class()}} for the \code{filter()} equivalent. +} diff --git a/man/filter_ab_class.Rd b/man/filter_ab_class.Rd index 44e724ef..c3c7f890 100644 --- a/man/filter_ab_class.Rd +++ b/man/filter_ab_class.Rd @@ -48,7 +48,7 @@ filter_tetracyclines(x, result = NULL, scope = "any", ...) \arguments{ \item{x}{a data set} -\item{ab_class}{an antimicrobial class, like \code{"carbapenems"}, as can be found in \code{\link[=antibiotics]{antibiotics$group}}} +\item{ab_class}{an antimicrobial class, like \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{result}{an antibiotic result: S, I or R (or a combination of more of them)} @@ -60,7 +60,7 @@ filter_tetracyclines(x, result = NULL, scope = "any", ...) Filter isolates on results in specific antimicrobial classes. This makes it easy to filter on isolates that were tested for e.g. any aminoglycoside, or to filter on carbapenem-resistant isolates without the need to specify the drugs. } \details{ -The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched for the input given in \code{ab_class} (case-insensitive). Next, \code{x} will be checked for column names with a value in any abbreviation, code or official name found in the \link{antibiotics} data set. +All columns of \code{x} will be searched for known antibiotic names, abbreviations, brand names and codes (ATC, EARS-Net, WHO, etc.). This means that a filter function like e.g. \code{\link[=filter_aminoglycosides]{filter_aminoglycosides()}} will include column names like 'gen', 'genta', 'J01GB03', 'tobra', 'Tobracin', etc. } \section{Stable lifecycle}{ @@ -103,3 +103,6 @@ example_isolates \%>\% filter_fluoroquinolones("R", "all") } } +\seealso{ +\code{\link[=antibiotic_class_selectors]{antibiotic_class_selectors()}} for the \code{select()} equivalent. +} diff --git a/tests/testthat/test-antibiotic_class_selectors.R b/tests/testthat/test-antibiotic_class_selectors.R new file mode 100644 index 00000000..9f45b70a --- /dev/null +++ b/tests/testthat/test-antibiotic_class_selectors.R @@ -0,0 +1,41 @@ +# ==================================================================== # +# TITLE # +# Antimicrobial Resistance (AMR) Analysis # +# # +# SOURCE # +# https://gitlab.com/msberends/AMR # +# # +# LICENCE # +# (c) 2018-2020 Berends MS, Luz CF et al. # +# # +# 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 more info: https://msberends.gitlab.io/AMR. # +# ==================================================================== # + +context("ab_class_selectors.R") + +test_that("Antibiotic class selectors work", { + skip_on_cran() + + expect_lt(example_isolates %>% dplyr::select(aminoglycosides()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(carbapenems()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_1st()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_2nd()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_3rd()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_4th()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(cephalosporins_5th()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(fluoroquinolones()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(glycopeptides()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(macrolides()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(penicillins()) %>% ncol(), ncol(example_isolates)) + expect_lt(example_isolates %>% dplyr::select(tetracyclines()) %>% ncol(), ncol(example_isolates)) + +}) https://msberends.gitlab.io/AMR/reference/antibiotics.html