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 @@ AMR (for R) - 1.2.0.9003 + 1.2.0.9004 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 14fcc2d0..2098a1c1 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9003 + 1.2.0.9004 diff --git a/docs/articles/index.html b/docs/articles/index.html index 5245afa0..8199e7cc 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9003 + 1.2.0.9004 diff --git a/docs/authors.html b/docs/authors.html index 11180804..49c16443 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9003 + 1.2.0.9004 diff --git a/docs/index.html b/docs/index.html index 01fdb382..655e1c08 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.2.0.9003 + 1.2.0.9004 diff --git a/docs/news/index.html b/docs/news/index.html index 93893f38..eaf9be2f 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9003 + 1.2.0.9004 @@ -229,13 +229,13 @@ Source: NEWS.md -
-

-AMR 1.2.0.9003 Unreleased +
+

+AMR 1.2.0.9004 Unreleased

-
+

-Last updated: 05-Jun-2020 +Last updated: 09-Jun-2020

@@ -244,9 +244,12 @@
  • 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
  • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 4f051c92..5ad5a3d7 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-05T11:55Z +last_built: 2020-06-09T14:15Z urls: reference: https://msberends.gitlab.io/AMR/reference article: https://msberends.gitlab.io/AMR/articles diff --git a/docs/reference/antibiotics.html b/docs/reference/antibiotics.html index a4dd3a17..302b0b4f 100644 --- a/docs/reference/antibiotics.html +++ b/docs/reference/antibiotics.html @@ -6,7 +6,7 @@ -Data sets with 557 antimicrobials — antibiotics • AMR (for R) +Data sets with 558 antimicrobials — antibiotics • AMR (for R) @@ -48,7 +48,7 @@ - + @@ -82,7 +82,7 @@ AMR (for R) - 1.2.0 + 1.2.0.9004
    @@ -226,7 +226,7 @@
    @@ -243,7 +243,7 @@

    Format

    -

    For the antibiotics data set: a data.frame with 455 observations and 14 variables:

    +

    For the antibiotics data set: a 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

    • diff --git a/docs/reference/index.html b/docs/reference/index.html index ca87e365..11b13c0e 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9003 + 1.2.0.9004
    @@ -478,7 +478,7 @@

    antibiotics antivirals

    -

    Data sets with 557 antimicrobials

    +

    Data sets with 558 antimicrobials

    diff --git a/man/antibiotics.Rd b/man/antibiotics.Rd index cd8bd401..aaf228bf 100644 --- a/man/antibiotics.Rd +++ b/man/antibiotics.Rd @@ -4,9 +4,9 @@ \name{antibiotics} \alias{antibiotics} \alias{antivirals} -\title{Data sets with 557 antimicrobials} +\title{Data sets with 558 antimicrobials} \format{ -\subsection{For the \link{antibiotics} data set: a \code{\link{data.frame}} with 455 observations and 14 variables:}{ +\subsection{For the \link{antibiotics} data set: a \code{\link{data.frame}} with 456 observations and 14 variables:}{ \itemize{ \item \code{ab}\cr Antibiotic ID as used in this package (like \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available \item \code{atc}\cr ATC code (Anatomical Therapeutic Chemical) as defined by the WHOCC, like \code{J01CR02}