diff --git a/DESCRIPTION b/DESCRIPTION
index 2791bafc..67aa2f2e 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: AMR
-Version: 1.2.0.9003
-Date: 2020-06-05
+Version: 1.2.0.9004
+Date: 2020-06-09
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(role = c("aut", "cre"),
diff --git a/NEWS.md b/NEWS.md
index 9e8fac12..f98e4dd2 100755
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,12 +1,14 @@
-# AMR 1.2.0.9003
-## Last updated: 05-Jun-2020
+# AMR 1.2.0.9004
+## Last updated: 09-Jun-2020
### Changed
* Fixed a bug where `eucast_rules()` would not work on a tibble when the `tibble` or `dplyr` package was loaded
* All `*_join_microorganisms()` functions now return the original data class (e.g. tibbles and data.tables)
* Fixed a bug where `as.ab()` would return an error on invalid input values
+* Fixed a bug for using grouped versions of `rsi_df()`, `proportion_df()` and `count_df()`
* 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 as `filter_aminoglycosides()`
+* Added antibiotics code "FOX1" for cefoxitin screening (abbreviation "cfsc") to the `antibiotics` data set
# AMR 1.2.0
diff --git a/R/guess_ab_col.R b/R/guess_ab_col.R
index b31f07eb..6d0f371e 100755
--- a/R/guess_ab_col.R
+++ b/R/guess_ab_col.R
@@ -114,9 +114,16 @@ get_column_abx <- function(x,
verbose = FALSE,
...) {
- message(font_blue("NOTE: Auto-guessing columns suitable for analysis..."), appendLF = FALSE)
+ message(font_blue("NOTE: Auto-guessing columns suitable for analysis"), appendLF = FALSE)
x <- as.data.frame(x, stringsAsFactors = FALSE)
+ if (NROW(x) > 10000) {
+ # only test maximum of 10,000 values per column
+ message(font_blue(paste0(" (using only ", font_bold("the first 10,000 rows"), ")...")), appendLF = FALSE)
+ x <- x[1:10000, , drop = FALSE]
+ } else {
+ message(font_blue("..."), appendLF = FALSE)
+ }
x_bak <- x
# only check columns that are a valid AB code, ATC code, name, abbreviation or synonym,
# or already have the rsi class (as.rsi)
diff --git a/R/rsi_calc.R b/R/rsi_calc.R
index 49f0eb07..369785a3 100755
--- a/R/rsi_calc.R
+++ b/R/rsi_calc.R
@@ -220,10 +220,18 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both"
.data <- .data[, which(!colnames(.data) %in% groups), drop = FALSE]
}
for (i in seq_len(ncol(.data))) {
- col_results <- as.data.frame(as.matrix(table(.data[, i, drop = TRUE])))
+ values <- .data[, i, drop = TRUE]
+ if (isTRUE(combine_SI)) {
+ values <- factor(values, levels = c("SI", "R"), ordered = TRUE)
+ } else if (isTRUE(combine_IR)) {
+ values <- factor(values, levels = c("S", "IR"), ordered = TRUE)
+ } else {
+ values <- factor(values, levels = c("S", "I", "R"), ordered = TRUE)
+ }
+ col_results <- as.data.frame(as.matrix(table(values)))
col_results$interpretation <- rownames(col_results)
col_results$isolates <- col_results[, 1, drop = TRUE]
- if (nrow(col_results) > 0) {
+ if (NROW(col_results) > 0 && sum(col_results$isolates, na.rm = TRUE) > 0) {
if (sum(col_results$isolates, na.rm = TRUE) >= minimum) {
col_results$value <- col_results$isolates / sum(col_results$isolates, na.rm = TRUE)
} else {
@@ -237,6 +245,12 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both"
isolates = col_results$isolates,
stringsAsFactors = FALSE)
if (data_has_groups) {
+ if (nrow(group_values) < nrow(out_new)) {
+ # repeat group_values for the number of rows in out_new
+ repeated <- rep(seq_len(nrow(group_values)),
+ each = nrow(out_new) / nrow(group_values))
+ group_values <- group_values[repeated, , drop = FALSE]
+ }
out_new <- cbind(group_values, out_new)
}
out <- rbind(out, out_new)
@@ -273,7 +287,7 @@ rsi_calc_df <- function(type, # "proportion", "count" or "both"
if (data_has_groups) {
# ordering by the groups and two more: "antibiotic" and "interpretation"
- out <- out[do.call("order", out[, seq_len(length(groups) + 2)]), ]
+ out <- ungroup(out[do.call("order", out[, seq_len(length(groups) + 2)]), ])
} else {
out <- out[order(out$antibiotic, out$interpretation), ]
}
diff --git a/data-raw/antibiotics.txt b/data-raw/antibiotics.txt
index cf4381cc..3e72f6bb 100644
--- a/data-raw/antibiotics.txt
+++ b/data-raw/antibiotics.txt
@@ -89,7 +89,8 @@
"CTF" "J01DC07" 43708 "Cefotiam" "Cephalosporins (2nd gen.)" "Other beta-lactam antibacterials" "Second-generation cephalosporins" "" "c(\"cefotiam\", \"cefotiam?\", \"cefotiamum\", \"ceradolan\", \"ceradon\", \"haloapor\")" 1.2 "g" 4 "g"
"CHE" 125846 "Cefotiam hexetil" "Cephalosporins (3rd gen.)" "" "c(\"cefotiam cilexetil\", \"pansporin t\")"
"FOV" 9578573 "Cefovecin" "Cephalosporins (3rd gen.)" "" ""
-"FOX" "J01DC01" 441199 "Cefoxitin" "Cephalosporins (2nd gen.)" "Other beta-lactam antibacterials" "Second-generation cephalosporins" "c(\"cfox\", \"cfsc\", \"cfx\", \"cfxt\", \"cx\", \"fox\", \"fx\")" "c(\"cefoxitin\", \"cefoxitina\", \"cefoxitine\", \"cefoxitinum\", \"cefoxotin\", \"cephoxitin\", \"mefoxin\", \"mefoxitin\", \"rephoxitin\")" 6 "g" "c(\"25240-3\", \"3448-8\")"
+"FOX" "J01DC01" 441199 "Cefoxitin" "Cephalosporins (2nd gen.)" "Other beta-lactam antibacterials" "Second-generation cephalosporins" "c(\"cfox\", \"cfx\", \"cfxt\", \"cx\", \"fox\", \"fx\")" "c(\"cefoxitin\", \"cefoxitina\", \"cefoxitine\", \"cefoxitinum\", \"cefoxotin\", \"cephoxitin\", \"mefoxin\", \"mefoxitin\", \"rephoxitin\")" 6 "g" "c(\"25240-3\", \"3448-8\")"
+"FOX1" "Cefoxitin screening" "Cephalosporins (2nd gen.)" "cfsc" "" "NA"
"ZOP" 9571080 "Cefozopran" "Cephalosporins (4th gen.)" "" "cefozopran"
"CFZ" 68597 "Cefpimizole" "Cephalosporins (3rd gen.)" "" "c(\"cefpimizol\", \"cefpimizole\", \"cefpimizole sodium\", \"cefpimizolum\")"
"CPM" "J01DD11" 636405 "Cefpiramide" "Cephalosporins (3rd gen.)" "Other beta-lactam antibacterials" "Third-generation cephalosporins" "" "c(\"cefpiramide\", \"cefpiramide acid\", \"cefpiramido\", \"cefpiramidum\")" 2 "g"
diff --git a/data-raw/reproduction_of_antibiotics.R b/data-raw/reproduction_of_antibiotics.R
index 5643d4c5..6523a6e7 100644
--- a/data-raw/reproduction_of_antibiotics.R
+++ b/data-raw/reproduction_of_antibiotics.R
@@ -322,7 +322,16 @@ antibiotics[which(antibiotics$ab == as.ab("cefuroxim")), "abbreviations"][[1]] <
antibiotics[which(antibiotics$ab == as.ab("cefotaxim")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("cefotaxim")), "abbreviations"][[1]], "cftx"))
antibiotics[which(antibiotics$ab == as.ab("ceftazidime")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("ceftazidime")), "abbreviations"][[1]], "cftz"))
antibiotics[which(antibiotics$ab == as.ab("cefepime")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("cefepime")), "abbreviations"][[1]], "cfpi"))
-antibiotics[which(antibiotics$ab == as.ab("cefoxitin")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("cefoxitin")), "abbreviations"][[1]], "cfxt", "cfsc"))
+antibiotics[which(antibiotics$ab == as.ab("cefoxitin")), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == as.ab("cefoxitin")), "abbreviations"][[1]], "cfxt"))
+# Add cefoxitin screening
+class(antibiotics$ab) <- "character"
+antibiotics <- rbind(antibiotics,data.frame(ab = "FOX1", atc = NA, cid = NA,
+ name = "Cefoxitin screening",
+ group = "Cephalosporins (2nd gen.)", atc_group1 = NA, atc_group2 = NA,
+ abbreviations = "cfsc", synonyms = NA,
+ oral_ddd = NA, oral_units = NA, iv_ddd = NA, iv_units = NA,
+ loinc = NA,
+ stringsAsFactors = FALSE))
# More GLIMS codes
antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CAZ"), "abbreviations"][[1]], "cftz"))
antibiotics[which(antibiotics$ab == "CRO"), "abbreviations"][[1]] <- list(c(antibiotics[which(antibiotics$ab == "CRO"), "abbreviations"][[1]], "cftr"))
@@ -579,7 +588,7 @@ antibiotics <- antibiotics %>%
# set as data.frame again
antibiotics <- as.data.frame(antibiotics, stringsAsFactors = FALSE)
class(antibiotics$ab) <- c("ab", "character")
-antibiotics <- antibiotics %>% arrange(name)
+antibiotics <- antibiotics %>% dplyr::arrange(name)
# make all abbreviations and synonyms lower case, unique and alphabetically sorted ----
for (i in 1:nrow(antibiotics)) {
diff --git a/data/antibiotics.rda b/data/antibiotics.rda
index 8174ae29..07138432 100755
Binary files a/data/antibiotics.rda and b/data/antibiotics.rda differ
diff --git a/docs/404.html b/docs/404.html
index 717e30f7..e3e94dbb 100644
--- a/docs/404.html
+++ b/docs/404.html
@@ -81,7 +81,7 @@
NEWS.md
-
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()
+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)filter_ab_class()
functions, such as filter_aminoglycosides()
antibiotics
data setR/data.R
antibiotics.Rd
data.frame
with 455 observations and 14 variables:data.frame
with 456 observations and 14 variables:ab
Antibiotic ID as used in this package (like AMC
), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available
Data sets with 557 antimicrobials
Data sets with 558 antimicrobials