From ccf13dd6c0cad47d2fe8be45fd07ed2151a92ebd Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Sun, 27 Dec 2020 23:19:41 +0100 Subject: [PATCH] (v1.4.0.9051) ab class --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/ab_class_selectors.R | 41 ++++++++++++------- R/filter_ab_class.R | 1 + docs/404.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 8 ++-- docs/pkgdown.yml | 2 +- .../reference/antibiotic_class_selectors.html | 9 +++- docs/reference/filter_ab_class.html | 3 +- docs/reference/index.html | 2 +- docs/survey.html | 2 +- man/antibiotic_class_selectors.Rd | 7 +++- man/filter_ab_class.Rd | 1 + 17 files changed, 58 insertions(+), 32 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 39b43819..a2c25f10 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.4.0.9050 +Version: 1.4.0.9051 Date: 2020-12-27 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index d16b725b..3317aa13 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.4.0.9050 +# AMR 1.4.0.9051 ## Last updated: 27 December 2020 ### New diff --git a/R/ab_class_selectors.R b/R/ab_class_selectors.R index af484964..1324b4a0 100644 --- a/R/ab_class_selectors.R +++ b/R/ab_class_selectors.R @@ -69,7 +69,12 @@ #' data.frame(some_column = "some_value", #' J01CA01 = "S") %>% # ATC code of ampicillin #' select(penicillins()) # only the 'J01CA01' column will be selected -#' +#' +#' +#' # with dplyr 1.0.0 and higher (that adds 'across()'), this is equal: +#' # (though the row names on the first are more correct) +#' example_isolates %>% filter_carbapenems("R", "all") +#' example_isolates %>% filter(across(carbapenems(), ~. == "R")) #' } ab_class <- function(ab_class) { ab_selector(ab_class, function_name = "ab_class") @@ -156,14 +161,19 @@ tetracyclines <- function() { ab_selector <- function(ab_class, function_name) { meet_criteria(ab_class, allow_class = "character", has_length = 1, .call_depth = 1) meet_criteria(function_name, allow_class = "character", has_length = 1, .call_depth = 1) - + for (i in seq_len(length(sys.frames()))) { - vars_df <- sys.frames()[[i]]$x + vars_df <- tryCatch(sys.frames()[[i]]$x, error = function(e) NULL) if (!is.null(vars_df) && is.data.frame(vars_df)) { + # when using e.g. example_isolates[, carbapenems()] or example_isolates %>% select(carbapenems()) + break + } else if (!is.null(vars_df) && is.list(vars_df)) { + # when using e.g. example_isolates %>% filter(across(carbapenems(), ~. == "R")) + vars_df <- as.data.frame(vars_df, stringsAsFactors = FALSE) break } } - stop_ifnot(is.data.frame(vars_df), "the ", function_name, "() function must be used inside dplyr verbs or a data.frame call.") + stop_ifnot(is.data.frame(vars_df), "this function must be used inside dplyr selection verbs or within a data.frame call.", call = -2) ab_in_data <- get_column_abx(vars_df, info = FALSE) if (length(ab_in_data) == 0) { @@ -184,15 +194,18 @@ ab_selector <- function(ab_class, function_name) { } # get the columns with a group names in the chosen ab class agents <- ab_in_data[names(ab_in_data) %in% ab_reference$ab] - if (length(agents) == 0) { - message_("No antimicrobial agents of class ", ab_group, " found", examples, ".") - } else { - message_("Selecting ", ab_group, ": ", - paste(paste0("'", font_bold(agents, collapse = NULL), - "' (", ab_name(names(agents), tolower = TRUE, language = NULL), ")"), - collapse = ", "), - as_note = FALSE, - extra_indent = nchar(paste0("Selecting ", ab_group, ": "))) - } + if (message_not_thrown_before(function_name)) { + if (length(agents) == 0) { + message_("No antimicrobial agents of class ", ab_group, " found", examples, ".") + } else { + message_("Selecting ", ab_group, ": ", + paste(paste0("'", font_bold(agents, collapse = NULL), + "' (", ab_name(names(agents), tolower = TRUE, language = NULL), ")"), + collapse = ", "), + as_note = FALSE, + extra_indent = nchar(paste0("Selecting ", ab_group, ": "))) + } + remember_thrown_message(function_name) + } unname(agents) } diff --git a/R/filter_ab_class.R b/R/filter_ab_class.R index e88eeffa..96ade2f5 100644 --- a/R/filter_ab_class.R +++ b/R/filter_ab_class.R @@ -71,6 +71,7 @@ #' filter_fluoroquinolones("R", "all") #' #' # with dplyr 1.0.0 and higher (that adds 'across()'), this is equal: +#' # (though the row names on the first are more correct) #' example_isolates %>% filter_carbapenems("R", "all") #' example_isolates %>% filter(across(carbapenems(), ~. == "R")) #' } diff --git a/docs/404.html b/docs/404.html index 88d51b11..770cecc6 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 079f10ab..7f4b9e53 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051 diff --git a/docs/articles/index.html b/docs/articles/index.html index 46a278da..0a74bef6 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051 diff --git a/docs/authors.html b/docs/authors.html index 9b0624c4..cada70bf 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051 diff --git a/docs/index.html b/docs/index.html index 4ff7f4f5..e6614614 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051 diff --git a/docs/news/index.html b/docs/news/index.html index f85a2332..30ea0c4b 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051 @@ -236,9 +236,9 @@ Source: NEWS.md -
-

-AMR 1.4.0.9050 Unreleased +
+

+AMR 1.4.0.9051 Unreleased

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index d48e1c1d..0cf34fb6 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -12,7 +12,7 @@ articles: datasets: datasets.html resistance_predict: resistance_predict.html welcome_to_AMR: welcome_to_AMR.html -last_built: 2020-12-27T19:32Z +last_built: 2020-12-27T22:17Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/antibiotic_class_selectors.html b/docs/reference/antibiotic_class_selectors.html index cf10b3a5..c97bd1a6 100644 --- a/docs/reference/antibiotic_class_selectors.html +++ b/docs/reference/antibiotic_class_selectors.html @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051

@@ -331,7 +331,12 @@ data.frame(some_column = "some_value", J01CA01 = "S") %>% # ATC code of ampicillin select(penicillins()) # only the 'J01CA01' column will be selected - + + + # with dplyr 1.0.0 and higher (that adds 'across()'), this is equal: + # (though the row names on the first are more correct) + example_isolates %>% filter_carbapenems("R", "all") + example_isolates %>% filter(across(carbapenems(), ~. == "R")) }
diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index 18e02a80..d0bc8f15 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9046 + 1.4.0.9051

@@ -344,6 +344,7 @@ The lifecycle of this function is stablefilter_fluoroquinolones("R", "all") # with dplyr 1.0.0 and higher (that adds 'across()'), this is equal: + # (though the row names on the first are more correct) example_isolates %>% filter_carbapenems("R", "all") example_isolates %>% filter(across(carbapenems(), ~. == "R")) } diff --git a/docs/reference/index.html b/docs/reference/index.html index 85b27cb8..63f2beaa 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051 diff --git a/docs/survey.html b/docs/survey.html index 37f991a2..618bd197 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9050 + 1.4.0.9051 diff --git a/man/antibiotic_class_selectors.Rd b/man/antibiotic_class_selectors.Rd index 97f6d0a7..f87f9146 100644 --- a/man/antibiotic_class_selectors.Rd +++ b/man/antibiotic_class_selectors.Rd @@ -100,7 +100,12 @@ if (require("dplyr")) { data.frame(some_column = "some_value", J01CA01 = "S") \%>\% # ATC code of ampicillin select(penicillins()) # only the 'J01CA01' column will be selected - + + + # with dplyr 1.0.0 and higher (that adds 'across()'), this is equal: + # (though the row names on the first are more correct) + example_isolates \%>\% filter_carbapenems("R", "all") + example_isolates \%>\% filter(across(carbapenems(), ~. == "R")) } } \seealso{ diff --git a/man/filter_ab_class.Rd b/man/filter_ab_class.Rd index 550261af..814c1081 100644 --- a/man/filter_ab_class.Rd +++ b/man/filter_ab_class.Rd @@ -105,6 +105,7 @@ if (require("dplyr")) { filter_fluoroquinolones("R", "all") # with dplyr 1.0.0 and higher (that adds 'across()'), this is equal: + # (though the row names on the first are more correct) example_isolates \%>\% filter_carbapenems("R", "all") example_isolates \%>\% filter(across(carbapenems(), ~. == "R")) }