From 8b5e2b030b386dc232e1c9ad80758b11b5cc942c Mon Sep 17 00:00:00 2001
From: "Matthijs S. Berends"
A frequency table is actually a regular data.frame
, with the exception that it contains an additional class.
[1] “frequency_tbl” “data.frame”
+[1] “freq” “data.frame”
Because of this additional class, a frequency table prints like the examples above. But the object itself contains the complete table without a row limitation:
[1] 74 5
diff --git a/docs/articles/index.html b/docs/articles/index.html index ce08e4eb..6ff3241f 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ diff --git a/docs/authors.html b/docs/authors.html index 7ed4329f..002b35ca 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ diff --git a/docs/index.html b/docs/index.html index 96339e43..766ee653 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ diff --git a/docs/news/index.html b/docs/news/index.html index 245d89c3..fd7eb547 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ @@ -287,6 +287,17 @@ Please create an issue in one of our repositories if you want additions in thissupport for boxplots:
+ +./inst/eucast/eucast.tsv
@@ -367,32 +378,32 @@ This data is updated annually - check the included version with the new function
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()
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 the antibiotics
data set. For example:
All ab_*
functions are deprecated and replaced by atc_*
functions:
ab_property -> atc_property()
-ab_name -> atc_name()
-ab_official -> atc_official()
-ab_trivial_nl -> atc_trivial_nl()
-ab_certe -> atc_certe()
-ab_umcg -> atc_umcg()
-ab_tradenames -> atc_tradenames()
ab_property -> atc_property()
+ab_name -> atc_name()
+ab_official -> atc_official()
+ab_trivial_nl -> atc_trivial_nl()
+ab_certe -> atc_certe()
+ab_umcg -> atc_umcg()
+ab_tradenames -> atc_tradenames()
as.atc()
internally. The old atc_property
has been renamed atc_online_property()
. This is done for two reasons: firstly, not all ATC codes are of antibiotics (ab) but can also be of antivirals or antifungals. Secondly, the input must have class atc
or must be coerable to this class. Properties of these classes should start with the same class name, analogous to as.mo()
and e.g. mo_genus
.set_mo_source()
and get_mo_source()
to use your own predefined MO codes as input for as.mo()
and consequently all mo_*
functionsdplyr
version 0.8.0as.atc()
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 R plot()
function can now be used for resistance prediction calculated with resistance_predict()
:
Functions filter_first_isolate()
and filter_first_weighted_isolate()
to shorten and fasten filtering on data sets with antimicrobial results, e.g.:
is equal to:
- +availability()
to check the number of available (non-empty) results in a data.frame
as.atc()
Now handles incorrect spelling, like i
instead of y
and f
instead of ph
:
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)
-as.mo(..., allow_uncertain = 2)
-
-# also equal:
-as.mo(..., allow_uncertain = FALSE)
-as.mo(..., allow_uncertain = 0)
# equal:
+as.mo(..., allow_uncertain = TRUE)
+as.mo(..., allow_uncertain = 2)
+
+# also equal:
+as.mo(..., allow_uncertain = FALSE)
+as.mo(..., allow_uncertain = 0)
as.mo(..., allow_uncertain = 3)
could lead to very unreliable results.~/.Rhistory_mo
. Use the new function clean_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:
as.mo(..., allow_uncertain = 3)
-
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
-septic_patients %>%
- mutate(genus = mo_genus(mo)) %>%
- freq(genus)
-# NEW WAY
-septic_patients %>%
- freq(mo_genus(mo))
-
-# Even supports grouping variables:
-septic_patients %>%
- group_by(gender) %>%
- freq(mo_genus(mo))
+# Determine genus of microorganisms (mo) in `septic_patients` data set:
+# OLD WAY
+septic_patients %>%
+ mutate(genus = mo_genus(mo)) %>%
+ freq(genus)
+# NEW WAY
+septic_patients %>%
+ freq(mo_genus(mo))
+
+# Even supports grouping variables:
+septic_patients %>%
+ group_by(gender) %>%
+ freq(mo_genus(mo))
- Header info is now available as a list, with the
header
function
- The parameter
header
is now set to TRUE
at default, even for markdown
@@ -605,10 +616,10 @@ Using as.mo(..., allow_uncertain = 3)Fewer than 3 characters as input for as.mo
will return NA
-
Function as.mo
(and all mo_*
wrappers) now supports genus abbreviations with “species” attached
-
+
- 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
@@ -621,15 +632,15 @@ Using as.mo(..., allow_uncertain = 3)
-
Support for grouping variables, test with:
-
+
-
Support for (un)selecting columns:
-
+
- Check for
hms::is.hms
@@ -709,18 +720,18 @@ Using as.mo(..., allow_uncertain = 3)
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"
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"
mo_gramstain("Esc blattae")
+# Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010)
+# [1] "Gram negative"
count_R
, count_IR
, count_I
, count_SI
and count_S
to selectively count resistant or susceptible isolates
as.mo(..., allow_uncertain = 3)
-
Functions as.mo
and is.mo
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 as.mo
function determines microbial IDs using intelligent rules:
-as.mo("E. coli")
-# [1] B_ESCHR_COL
-as.mo("MRSA")
-# [1] B_STPHY_AUR
-as.mo("S group A")
-# [1] B_STRPTC_GRA
+as.mo("E. coli")
+# [1] B_ESCHR_COL
+as.mo("MRSA")
+# [1] B_STPHY_AUR
+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:
-
+
- Added parameter
reference_df
for as.mo
, so users can supply their own microbial IDs, name or codes as a reference table
- Renamed all previous references to
bactid
to mo
, like:
@@ -770,12 +781,12 @@ Using as.mo(..., allow_uncertain = 3)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.:
-
+
- 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
@@ -786,13 +797,13 @@ Using as.mo(..., allow_uncertain = 3)
-
Support for quasiquotation in the functions series count_*
and portions_*
, and n_rsi
. This allows to check for more than 2 vectors or columns.
-
+
- 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
@@ -806,12 +817,12 @@ Using as.mo(..., allow_uncertain = 3)
-
Support for types (classes) list and matrix for freq
-
+
For lists, subsetting is possible:
-
+
A numeric vector. A vector of e.g. c(10, 20)
will split on 0-9, 10-19 and 20+. A value of only 50
will split on 0-49 and 50+.
The default is to split on young children (0-11), youth (12-24), young adults (25-54), middle-aged adults (55-74) and elderly (75+).
A character:
"children"
, equivalent of: c(0, 1, 2, 4, 6, 13, 18)
. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.
"children"
or "kids"
, equivalent of: c(0, 1, 2, 4, 6, 13, 18)
. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.
"elderly"
or "seniors"
, equivalent of: c(65, 75, 85)
. This will split on 0-64, 65-74, 75-84, 85+.
"fives"
, equivalent of: 1:20 * 5
. This will split on 0-4, 5-9, 10-14, ..., 90-94, 95-99, 100+.
"tens"
, equivalent of: 1:10 * 10
. This will split on 0-9, 10-19, 20-29, ... 80-89, 90-99, 100+.
# NOT RUN { -ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21) +@@ -311,15 +311,17 @@# NOT RUN { +ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21) -# split into 0-49 and 50+ -age_groups(ages, 50) +# split into 0-49 and 50+ +age_groups(ages, 50) -# split into 0-19, 20-49 and 50+ -age_groups(ages, c(20, 50)) +# split into 0-19, 20-49 and 50+ +age_groups(ages, c(20, 50)) -# split into groups of ten years -age_groups(ages, 1:10 * 10) -age_groups(ages, split_at = "tens") +# split into groups of ten years +age_groups(ages, 1:10 * 10) +age_groups(ages, split_at = "tens") -# split into groups of five years -age_groups(ages, 1:20 * 5) -age_groups(ages, split_at = "fives") +# split into groups of five years +age_groups(ages, 1:20 * 5) +age_groups(ages, split_at = "fives") -# split specifically for children -age_groups(ages, "children") -# same: -age_groups(ages, c(1, 2, 4, 6, 13, 17)) +# split specifically for children +age_groups(ages, "children") +# same: +age_groups(ages, c(1, 2, 4, 6, 13, 17)) -# resistance of ciprofloxacine per age group -library(dplyr) -septic_patients %>% - mutate(first_isolate = first_isolate(.)) %>% - filter(first_isolate == TRUE, - mo == as.mo("E. coli")) %>% - group_by(age_group = age_groups(age)) %>% - select(age_group, - CIP) %>% - ggplot_rsi(x = "age_group") -# }+# resistance of ciprofloxacine per age group +library(dplyr) +septic_patients %>% + filter_first_isolate) %>% + filter(mo == as.mo("E. coli")) %>% + group_by(age_group = age_groups(age)) %>% + select(age_group, CIP) %>% + ggplot_rsi(x = "age_group") +# } +
To define antibiotics column names, leave as it is to determine it automatically with guess_ab_col
or input a text (case-insensitive), or use NULL
to skip a column (e.g. TIC = NULL
to skip ticarcillin). Manually defined but non-existing columns will be skipped with a warning.
Available abbrevations of the column containing antibiotics in the form 'antimicrobial ID: name (ATC code)':
-AMC: amoxicillin/clavulanic acid (J01CR02), - AMK: amikacin (J01GB06), +
The following antibiotics are used for the functions eucast_rules
and mdro
. These are shown in the format 'antimicrobial ID: name (ATC code)', sorted by name:
AMK: amikacin (J01GB06), AMX: amoxicillin (J01CA04), + AMC: amoxicillin/clavulanic acid (J01CR02), AMP: ampicillin (J01CA01), AZM: azithromycin (J01FA10), AZL: azlocillin (J01CA09), ATM: aztreonam (J01DF01), + CAP: capreomycin (J04AB30), RID: cefaloridine (J01DB02), + CZO: cefazolin (J01DB04), FEP: cefepime (J01DE01), CTX: cefotaxime (J01DD01), FOX: cefoxitin (J01DC01), @@ -331,26 +333,28 @@ CIP: ciprofloxacin (J01MA02), CLR: clarithromycin (J01FA09), CLI: clindamycin (J01FF01), - FLC: flucloxacillin (J01CF05), COL: colistin (J01XB01), - CZO: cefazolin (J01DB04), DAP: daptomycin (J01XX09), DOX: doxycycline (J01AA02), ETP: ertapenem (J01DH03), ERY: erythromycin (J01FA01), + ETH: ethambutol (J04AK02), + FLC: flucloxacillin (J01CF05), FOS: fosfomycin (J01XX01), FUS: fusidic acid (J01XC01), + GAT: gatifloxacin (J01MA16), GEN: gentamicin (J01GB03), IPM: imipenem (J01DH51), + INH: isoniazid (J04AC01), KAN: kanamycin (J01GB04), LVX: levofloxacin (J01MA12), LIN: lincomycin (J01FF02), LNZ: linezolid (J01XX08), MEM: meropenem (J01DH02), + MTR: metronidazole (J01XD01), MEZ: mezlocillin (J01CA10), MNO: minocycline (J01AA08), MFX: moxifloxacin (J01MA14), - MTR: metronidazole (J01XD01), NAL: nalidixic acid (J01MB02), NEO: neomycin (J01GB05), NET: netilmicin (J01GB07), @@ -358,14 +362,18 @@ NOR: norfloxacin (J01MA06), NOV: novobiocin (an ATCvet code: QJ01XX95), OFX: ofloxacin (J01MA01), - OXA: oxacillin (J01CF04), + OXA: oxacillin (J01CF04), PEN: penicillin G (J01CE01), PIP: piperacillin (J01CA12), TZP: piperacillin/tazobactam (J01CR05), PLB: polymyxin B (J01XB02), PRI: pristinamycin (J01FG01), + PZA: pyrazinamide (J04AK01), QDA: quinupristin/dalfopristin (J01FG02), + RIB: rifabutin (J04AB04), RIF: rifampicin (J04AB02), + RIF: rifampin (J04AB02), + RFP: rifapentine (J04AB05), RXT: roxithromycin (J01FA06), SIS: sisomicin (J01GB08), TEC: teicoplanin (J01XA02), diff --git a/docs/reference/freq.html b/docs/reference/freq.html index ad7e1256..693eaa9a 100644 --- a/docs/reference/freq.html +++ b/docs/reference/freq.html @@ -81,7 +81,7 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co @@ -250,27 +250,27 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co -
frequency_tbl(x, ..., sort.count = TRUE, - nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE, - markdown = !interactive(), digits = 2, quote = FALSE, - header = TRUE, title = NULL, na = "<NA>", droplevels = TRUE, - sep = " ", decimal.mark = getOption("OutDec"), - big.mark = ifelse(decimal.mark != ",", ",", ".")) - -freq(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"), +freq(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE, markdown = !interactive(), digits = 2, quote = FALSE, header = TRUE, title = NULL, na = "<NA>", droplevels = TRUE, sep = " ", decimal.mark = getOption("OutDec"), big.mark = ifelse(decimal.mark != ",", ",", ".")) +frequency_tbl(x, ..., sort.count = TRUE, + nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE, + markdown = !interactive(), digits = 2, quote = FALSE, + header = TRUE, title = NULL, na = "<NA>", droplevels = TRUE, + sep = " ", decimal.mark = getOption("OutDec"), + big.mark = ifelse(decimal.mark != ",", ",", ".")) + top_freq(f, n) header(f, property = NULL) -# S3 method for frequency_tbl -print(x, nmax = getOption("max.print.freq", - default = 15), markdown = !interactive(), header = TRUE, +# S3 method for freq +print(x, nmax = getOption("max.print.freq", default = 15), + markdown = !interactive(), header = TRUE, decimal.mark = getOption("OutDec"), big.mark = ifelse(decimal.mark != ",", ",", "."), ...)@@ -361,7 +361,7 @@ top_freq can be used to get the top/bottom n items of a frequency table, with coValue
-A
+data.frame
(with an additional class"frequency_tbl"
) with five columns:item
,count
,percent
,cum_count
andcum_percent
.A
data.frame
(with an additional class"freq"
) with five columns:item
,count
,percent
,cum_count
andcum_percent
.Details
@@ -452,6 +452,16 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co freq(age) %>% hist() +# or a boxplot of numeric values +septic_patients %>% + freq(age) %>% + boxplot() + +# or even a boxplot per group +septic_patients %>% + group_by(hospital_id) %>% + freq(age) %>% + boxplot() # or print all points to a regular plot septic_patients %>% diff --git a/docs/reference/index.html b/docs/reference/index.html index 3c6b6f0a..a6b35ce7 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -78,7 +78,7 @@ @@ -454,7 +454,7 @@- +
frequency_tbl()
freq()
top_freq()
header()
print(<frequency_tbl>)
Frequency table
diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html index ee4b59d6..23a31dea 100644 --- a/docs/reference/mdro.html +++ b/docs/reference/mdro.html @@ -80,7 +80,7 @@ @@ -312,15 +312,17 @@To define antibiotics column names, leave as it is to determine it automatically with
-guess_ab_col
or input a text (case-insensitive), or useNULL
to skip a column (e.g.TIC = NULL
to skip ticarcillin). Manually defined but non-existing columns will be skipped with a warning.Available abbrevations of the column containing antibiotics in the form 'antimicrobial ID: name (ATC code)':
-AMC: amoxicillin/clavulanic acid (J01CR02), - AMK: amikacin (J01GB06), +
The following antibiotics are used for the functions
+eucast_rules
andmdro
. These are shown in the format 'antimicrobial ID: name (ATC code)', sorted by name:AMK: amikacin (J01GB06), AMX: amoxicillin (J01CA04), + AMC: amoxicillin/clavulanic acid (J01CR02), AMP: ampicillin (J01CA01), AZM: azithromycin (J01FA10), AZL: azlocillin (J01CA09), ATM: aztreonam (J01DF01), + CAP: capreomycin (J04AB30), RID: cefaloridine (J01DB02), + CZO: cefazolin (J01DB04), FEP: cefepime (J01DE01), CTX: cefotaxime (J01DD01), FOX: cefoxitin (J01DC01), @@ -332,26 +334,28 @@ CIP: ciprofloxacin (J01MA02), CLR: clarithromycin (J01FA09), CLI: clindamycin (J01FF01), - FLC: flucloxacillin (J01CF05), COL: colistin (J01XB01), - CZO: cefazolin (J01DB04), DAP: daptomycin (J01XX09), DOX: doxycycline (J01AA02), ETP: ertapenem (J01DH03), ERY: erythromycin (J01FA01), + ETH: ethambutol (J04AK02), + FLC: flucloxacillin (J01CF05), FOS: fosfomycin (J01XX01), FUS: fusidic acid (J01XC01), + GAT: gatifloxacin (J01MA16), GEN: gentamicin (J01GB03), IPM: imipenem (J01DH51), + INH: isoniazid (J04AC01), KAN: kanamycin (J01GB04), LVX: levofloxacin (J01MA12), LIN: lincomycin (J01FF02), LNZ: linezolid (J01XX08), MEM: meropenem (J01DH02), + MTR: metronidazole (J01XD01), MEZ: mezlocillin (J01CA10), MNO: minocycline (J01AA08), MFX: moxifloxacin (J01MA14), - MTR: metronidazole (J01XD01), NAL: nalidixic acid (J01MB02), NEO: neomycin (J01GB05), NET: netilmicin (J01GB07), @@ -359,14 +363,18 @@ NOR: norfloxacin (J01MA06), NOV: novobiocin (an ATCvet code: QJ01XX95), OFX: ofloxacin (J01MA01), - OXA: oxacillin (J01CF04), + OXA: oxacillin (J01CF04), PEN: penicillin G (J01CE01), PIP: piperacillin (J01CA12), TZP: piperacillin/tazobactam (J01CR05), PLB: polymyxin B (J01XB02), PRI: pristinamycin (J01FG01), + PZA: pyrazinamide (J04AK01), QDA: quinupristin/dalfopristin (J01FG02), + RIB: rifabutin (J04AB04), RIF: rifampicin (J04AB02), + RIF: rifampin (J04AB02), + RFP: rifapentine (J04AB05), RXT: roxithromycin (J01FA06), SIS: sisomicin (J01GB08), TEC: teicoplanin (J01XA02), diff --git a/man/eucast_rules.Rd b/man/eucast_rules.Rd index d24c37a5..c6760c39 100644 --- a/man/eucast_rules.Rd +++ b/man/eucast_rules.Rd @@ -61,16 +61,18 @@ In the source code the file containing all rules is located \href{https://gitlab To define antibiotics column names, leave as it is to determine it automatically with \code{\link{guess_ab_col}} or input a text (case-insensitive), or use \code{NULL} to skip a column (e.g. \code{TIC = NULL} to skip ticarcillin). Manually defined but non-existing columns will be skipped with a warning. -Available abbrevations of the column containing antibiotics in the form '\strong{antimicrobial ID}: name (\emph{ATC code})': +The following antibiotics are used for the functions \code{\link{eucast_rules}} and \code{\link{mdro}}. These are shown in the format '\strong{antimicrobial ID}: name (\emph{ATC code})', sorted by name: - \strong{AMC}: amoxicillin/clavulanic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR02}{J01CR02}), \strong{AMK}: amikacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB06}{J01GB06}), \strong{AMX}: amoxicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA04}{J01CA04}), + \strong{AMC}: amoxicillin/clavulanic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR02}{J01CR02}), \strong{AMP}: ampicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA01}{J01CA01}), \strong{AZM}: azithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA10}{J01FA10}), \strong{AZL}: azlocillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA09}{J01CA09}), \strong{ATM}: aztreonam (\href{https://www.whocc.no/atc_ddd_index/?code=J01DF01}{J01DF01}), + \strong{CAP}: capreomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB30}{J04AB30}), \strong{RID}: cefaloridine (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB02}{J01DB02}), + \strong{CZO}: cefazolin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB04}{J01DB04}), \strong{FEP}: cefepime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DE01}{J01DE01}), \strong{CTX}: cefotaxime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DD01}{J01DD01}), \strong{FOX}: cefoxitin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DC01}{J01DC01}), @@ -82,26 +84,28 @@ Available abbrevations of the column containing antibiotics in the form '\strong \strong{CIP}: ciprofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA02}{J01MA02}), \strong{CLR}: clarithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA09}{J01FA09}), \strong{CLI}: clindamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FF01}{J01FF01}), - \strong{FLC}: flucloxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF05}{J01CF05}), \strong{COL}: colistin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XB01}{J01XB01}), - \strong{CZO}: cefazolin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB04}{J01DB04}), \strong{DAP}: daptomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX09}{J01XX09}), \strong{DOX}: doxycycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA02}{J01AA02}), \strong{ETP}: ertapenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH03}{J01DH03}), \strong{ERY}: erythromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA01}{J01FA01}), + \strong{ETH}: ethambutol (\href{https://www.whocc.no/atc_ddd_index/?code=J04AK02}{J04AK02}), + \strong{FLC}: flucloxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF05}{J01CF05}), \strong{FOS}: fosfomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX01}{J01XX01}), \strong{FUS}: fusidic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01XC01}{J01XC01}), + \strong{GAT}: gatifloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA16}{J01MA16}), \strong{GEN}: gentamicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB03}{J01GB03}), \strong{IPM}: imipenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH51}{J01DH51}), + \strong{INH}: isoniazid (\href{https://www.whocc.no/atc_ddd_index/?code=J04AC01}{J04AC01}), \strong{KAN}: kanamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB04}{J01GB04}), \strong{LVX}: levofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA12}{J01MA12}), \strong{LIN}: lincomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FF02}{J01FF02}), \strong{LNZ}: linezolid (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX08}{J01XX08}), \strong{MEM}: meropenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH02}{J01DH02}), + \strong{MTR}: metronidazole (\href{https://www.whocc.no/atc_ddd_index/?code=J01XD01}{J01XD01}), \strong{MEZ}: mezlocillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA10}{J01CA10}), \strong{MNO}: minocycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA08}{J01AA08}), \strong{MFX}: moxifloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA14}{J01MA14}), - \strong{MTR}: metronidazole (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA14}{J01XD01}), \strong{NAL}: nalidixic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01MB02}{J01MB02}), \strong{NEO}: neomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB05}{J01GB05}), \strong{NET}: netilmicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB07}{J01GB07}), @@ -109,14 +113,18 @@ Available abbrevations of the column containing antibiotics in the form '\strong \strong{NOR}: norfloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA06}{J01MA06}), \strong{NOV}: novobiocin (an ATCvet code: \href{https://www.whocc.no/atc_ddd_index/?code=QJ01XX95}{QJ01XX95}), \strong{OFX}: ofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA01}{J01MA01}), - \strong{OXA}: oxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA01}{J01CF04}), + \strong{OXA}: oxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF04}{J01CF04}), \strong{PEN}: penicillin G (\href{https://www.whocc.no/atc_ddd_index/?code=J01CE01}{J01CE01}), \strong{PIP}: piperacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA12}{J01CA12}), \strong{TZP}: piperacillin/tazobactam (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR05}{J01CR05}), \strong{PLB}: polymyxin B (\href{https://www.whocc.no/atc_ddd_index/?code=J01XB02}{J01XB02}), \strong{PRI}: pristinamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FG01}{J01FG01}), + \strong{PZA}: pyrazinamide (\href{https://www.whocc.no/atc_ddd_index/?code=J04AK01}{J04AK01}), \strong{QDA}: quinupristin/dalfopristin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FG02}{J01FG02}), + \strong{RIB}: rifabutin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB04}{J04AB04}), \strong{RIF}: rifampicin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB02}{J04AB02}), + \strong{RIF}: rifampin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB02}{J04AB02}), + \strong{RFP}: rifapentine (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB05}{J04AB05}), \strong{RXT}: roxithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA06}{J01FA06}), \strong{SIS}: sisomicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB08}{J01GB08}), \strong{TEC}: teicoplanin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XA02}{J01XA02}), diff --git a/man/freq.Rd b/man/freq.Rd index 2e0c4be2..e2212969 100755 --- a/man/freq.Rd +++ b/man/freq.Rd @@ -5,16 +5,9 @@ \alias{frequency_tbl} \alias{top_freq} \alias{header} -\alias{print.frequency_tbl} +\alias{print.freq} \title{Frequency table} \usage{ -frequency_tbl(x, ..., sort.count = TRUE, - nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE, - markdown = !interactive(), digits = 2, quote = FALSE, - header = TRUE, title = NULL, na = "
", droplevels = TRUE, - sep = " ", decimal.mark = getOption("OutDec"), - big.mark = ifelse(decimal.mark != ",", ",", ".")) - freq(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE, markdown = !interactive(), digits = 2, quote = FALSE, header = TRUE, title = NULL, @@ -22,12 +15,19 @@ freq(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"), decimal.mark = getOption("OutDec"), big.mark = ifelse(decimal.mark != ",", ",", ".")) +frequency_tbl(x, ..., sort.count = TRUE, + nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE, + markdown = !interactive(), digits = 2, quote = FALSE, + header = TRUE, title = NULL, na = " ", droplevels = TRUE, + sep = " ", decimal.mark = getOption("OutDec"), + big.mark = ifelse(decimal.mark != ",", ",", ".")) + top_freq(f, n) header(f, property = NULL) -\method{print}{frequency_tbl}(x, nmax = getOption("max.print.freq", - default = 15), markdown = !interactive(), header = TRUE, +\method{print}{freq}(x, nmax = getOption("max.print.freq", default = 15), + markdown = !interactive(), header = TRUE, decimal.mark = getOption("OutDec"), big.mark = ifelse(decimal.mark != ",", ",", "."), ...) } @@ -75,7 +75,7 @@ header(f, property = NULL) \item{property}{property in header to return this value directly} } \value{ -A \code{data.frame} (with an additional class \code{"frequency_tbl"}) with five columns: \code{item}, \code{count}, \code{percent}, \code{cum_count} and \code{cum_percent}. +A \code{data.frame} (with an additional class \code{"freq"}) with five columns: \code{item}, \code{count}, \code{percent}, \code{cum_count} and \code{cum_percent}. } \description{ Create a frequency table of a vector with items or a \code{data.frame}. Supports quasiquotation and markdown for reports. Best practice is: \code{data \%>\% freq(var)}.\cr @@ -173,6 +173,16 @@ septic_patients \%>\% freq(age) \%>\% hist() +# or a boxplot of numeric values +septic_patients \%>\% + freq(age) \%>\% + boxplot() + +# or even a boxplot per group +septic_patients \%>\% + group_by(hospital_id) \%>\% + freq(age) \%>\% + boxplot() # or print all points to a regular plot septic_patients \%>\% diff --git a/man/mdro.Rd b/man/mdro.Rd index 4bc09b9d..ab97b154 100644 --- a/man/mdro.Rd +++ b/man/mdro.Rd @@ -59,16 +59,18 @@ Other currently supported guidelines are: To define antibiotics column names, leave as it is to determine it automatically with \code{\link{guess_ab_col}} or input a text (case-insensitive), or use \code{NULL} to skip a column (e.g. \code{TIC = NULL} to skip ticarcillin). Manually defined but non-existing columns will be skipped with a warning. -Available abbrevations of the column containing antibiotics in the form '\strong{antimicrobial ID}: name (\emph{ATC code})': +The following antibiotics are used for the functions \code{\link{eucast_rules}} and \code{\link{mdro}}. These are shown in the format '\strong{antimicrobial ID}: name (\emph{ATC code})', sorted by name: - \strong{AMC}: amoxicillin/clavulanic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR02}{J01CR02}), \strong{AMK}: amikacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB06}{J01GB06}), \strong{AMX}: amoxicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA04}{J01CA04}), + \strong{AMC}: amoxicillin/clavulanic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR02}{J01CR02}), \strong{AMP}: ampicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA01}{J01CA01}), \strong{AZM}: azithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA10}{J01FA10}), \strong{AZL}: azlocillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA09}{J01CA09}), \strong{ATM}: aztreonam (\href{https://www.whocc.no/atc_ddd_index/?code=J01DF01}{J01DF01}), + \strong{CAP}: capreomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB30}{J04AB30}), \strong{RID}: cefaloridine (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB02}{J01DB02}), + \strong{CZO}: cefazolin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB04}{J01DB04}), \strong{FEP}: cefepime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DE01}{J01DE01}), \strong{CTX}: cefotaxime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DD01}{J01DD01}), \strong{FOX}: cefoxitin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DC01}{J01DC01}), @@ -80,26 +82,28 @@ Available abbrevations of the column containing antibiotics in the form '\strong \strong{CIP}: ciprofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA02}{J01MA02}), \strong{CLR}: clarithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA09}{J01FA09}), \strong{CLI}: clindamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FF01}{J01FF01}), - \strong{FLC}: flucloxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF05}{J01CF05}), \strong{COL}: colistin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XB01}{J01XB01}), - \strong{CZO}: cefazolin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB04}{J01DB04}), \strong{DAP}: daptomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX09}{J01XX09}), \strong{DOX}: doxycycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA02}{J01AA02}), \strong{ETP}: ertapenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH03}{J01DH03}), \strong{ERY}: erythromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA01}{J01FA01}), + \strong{ETH}: ethambutol (\href{https://www.whocc.no/atc_ddd_index/?code=J04AK02}{J04AK02}), + \strong{FLC}: flucloxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF05}{J01CF05}), \strong{FOS}: fosfomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX01}{J01XX01}), \strong{FUS}: fusidic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01XC01}{J01XC01}), + \strong{GAT}: gatifloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA16}{J01MA16}), \strong{GEN}: gentamicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB03}{J01GB03}), \strong{IPM}: imipenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH51}{J01DH51}), + \strong{INH}: isoniazid (\href{https://www.whocc.no/atc_ddd_index/?code=J04AC01}{J04AC01}), \strong{KAN}: kanamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB04}{J01GB04}), \strong{LVX}: levofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA12}{J01MA12}), \strong{LIN}: lincomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FF02}{J01FF02}), \strong{LNZ}: linezolid (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX08}{J01XX08}), \strong{MEM}: meropenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH02}{J01DH02}), + \strong{MTR}: metronidazole (\href{https://www.whocc.no/atc_ddd_index/?code=J01XD01}{J01XD01}), \strong{MEZ}: mezlocillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA10}{J01CA10}), \strong{MNO}: minocycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA08}{J01AA08}), \strong{MFX}: moxifloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA14}{J01MA14}), - \strong{MTR}: metronidazole (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA14}{J01XD01}), \strong{NAL}: nalidixic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01MB02}{J01MB02}), \strong{NEO}: neomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB05}{J01GB05}), \strong{NET}: netilmicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB07}{J01GB07}), @@ -107,14 +111,18 @@ Available abbrevations of the column containing antibiotics in the form '\strong \strong{NOR}: norfloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA06}{J01MA06}), \strong{NOV}: novobiocin (an ATCvet code: \href{https://www.whocc.no/atc_ddd_index/?code=QJ01XX95}{QJ01XX95}), \strong{OFX}: ofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA01}{J01MA01}), - \strong{OXA}: oxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA01}{J01CF04}), + \strong{OXA}: oxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF04}{J01CF04}), \strong{PEN}: penicillin G (\href{https://www.whocc.no/atc_ddd_index/?code=J01CE01}{J01CE01}), \strong{PIP}: piperacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA12}{J01CA12}), \strong{TZP}: piperacillin/tazobactam (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR05}{J01CR05}), \strong{PLB}: polymyxin B (\href{https://www.whocc.no/atc_ddd_index/?code=J01XB02}{J01XB02}), \strong{PRI}: pristinamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FG01}{J01FG01}), + \strong{PZA}: pyrazinamide (\href{https://www.whocc.no/atc_ddd_index/?code=J04AK01}{J04AK01}), \strong{QDA}: quinupristin/dalfopristin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FG02}{J01FG02}), + \strong{RIB}: rifabutin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB04}{J04AB04}), \strong{RIF}: rifampicin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB02}{J04AB02}), + \strong{RIF}: rifampin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB02}{J04AB02}), + \strong{RFP}: rifapentine (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB05}{J04AB05}), \strong{RXT}: roxithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA06}{J01FA06}), \strong{SIS}: sisomicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB08}{J01GB08}), \strong{TEC}: teicoplanin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XA02}{J01XA02}), diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R index e757e731..60ea4265 100755 --- a/tests/testthat/test-freq.R +++ b/tests/testthat/test-freq.R @@ -47,7 +47,10 @@ test_that("frequency table works", { expect_output(print(freq(septic_patients$age, markdown = TRUE, title = "TITLE"))) # character - expect_output(suppressWarnings(print(freq(microorganisms$fullname)))) + expect_output(print(freq(microorganisms$genus))) + expect_output(print(structure(freq(microorganisms$genus), + # check printing of old class: + class = c("frequency_tbl", "data.frame")))) # mo expect_output(print(freq(septic_patients$mo))) # rsi @@ -121,9 +124,11 @@ test_that("frequency table works", { # input must be freq tbl expect_error(septic_patients %>% top_freq(1)) - # charts from plot and hist, should not raise errors + # charts from plot, hist and boxplot, should not raise errors plot(freq(septic_patients, age)) hist(freq(septic_patients, age)) + boxplot(freq(septic_patients, age)) + boxplot(freq(dplyr::group_by(septic_patients, gender), age)) # check vector expect_identical(septic_patients %>%