diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 06e62421..7b23dd58 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -64,8 +64,7 @@ jobs: - {os: ubuntu-16.04, r: '3.5', allowfail: false, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.4', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.3', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - - {os: ubuntu-16.04, r: '3.2', allowfail: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - + # older R versions cannot be tested, since tidyverse only supports last 4 R x.x versions env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} diff --git a/DESCRIPTION b/DESCRIPTION index 10786081..382f6d8b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 1.4.0.9020 +Version: 1.4.0.9021 Date: 2020-11-16 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 5061854f..5093c630 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 1.4.0.9020 +# AMR 1.4.0.9021 ## Last updated: 16 November 2020 ### New diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 91ca9ed3..4002720d 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -670,7 +670,7 @@ progress_ticker <- function(n = 1, n_min = 0, ...) { pb$kill <- function() { invisible() } - structure(pb, class = "txtProgressBar") + set_clean_class(pb, new_class = "txtProgressBar") } else if (n >= n_min) { pb <- utils::txtProgressBar(max = n, style = 3) pb$tick <- function() { @@ -680,6 +680,21 @@ progress_ticker <- function(n = 1, n_min = 0, ...) { } } +set_clean_class <- function(x, new_class) { + if (is.null(x)) { + x <- NA_character_ + } + if (is.factor(x)) { + lvls <- levels(x) + attributes(x) <- NULL + levels(x) <- lvls + } else { + attributes(x) <- NULL + } + class(x) <- new_class + x +} + create_pillar_column <- function(x, ...) { new_pillar_shaft_simple <- import_fn("new_pillar_shaft_simple", "pillar", error_on_fail = FALSE) if (!is.null(new_pillar_shaft_simple)) { diff --git a/R/ab.R b/R/ab.R index 9913632f..cd9192cc 100755 --- a/R/ab.R +++ b/R/ab.R @@ -97,8 +97,8 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = TRUE, ...) { if (all(toupper(x) %in% antibiotics$ab)) { # valid AB code, but not yet right class - return(structure(.Data = toupper(x), - class = c("ab", "character"))) + return(set_clean_class(toupper(x), + new_class = c("ab", "character"))) } x_bak <- x @@ -455,8 +455,8 @@ as.ab <- function(x, flag_multiple_results = TRUE, info = TRUE, ...) { x_result <- NA_character_ } - structure(.Data = x_result, - class = c("ab", "character")) + set_clean_class(x_result, + new_class = c("ab", "character")) } #' @rdname as.ab diff --git a/R/ab_property.R b/R/ab_property.R index 79e711ff..c6af266f 100644 --- a/R/ab_property.R +++ b/R/ab_property.R @@ -263,7 +263,7 @@ ab_validate <- function(x, property, ...) { pm_pull(property) } if (property == "ab") { - return(structure(x, class = property)) + return(set_clean_class(x, new_class = c("ab", "character"))) } else if (property == "cid") { return(as.integer(x)) } else if (property %like% "ddd") { diff --git a/R/age.R b/R/age.R index 392721b9..995eed80 100755 --- a/R/age.R +++ b/R/age.R @@ -139,13 +139,14 @@ age <- function(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE, ...) { #' #' \donttest{ #' # resistance of ciprofloxacin per age group -#' library(dplyr) -#' example_isolates %>% -#' 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", minimum = 0) +#' if (require("dplyr")) { +#' example_isolates %>% +#' 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", minimum = 0) +#' } #' } age_groups <- function(x, split_at = c(12, 25, 55, 75), na.rm = FALSE) { meet_criteria(x, allow_class = c("numeric", "integer")) diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R index 792aeb85..e9ec0a5a 100644 --- a/R/bug_drug_combinations.R +++ b/R/bug_drug_combinations.R @@ -106,7 +106,8 @@ bug_drug_combinations <- function(x, out <- rbind(out, out_group, stringsAsFactors = FALSE) } - structure(.Data = out, class = c("bug_drug_combinations", x_class)) + set_clean_class(out, + new_class = c("bug_drug_combinations", x_class)) } #' @method format bug_drug_combinations @@ -245,7 +246,8 @@ format.bug_drug_combinations <- function(x, #' @export print.bug_drug_combinations <- function(x, ...) { x_class <- class(x) - print(structure(x, class = x_class[x_class != "bug_drug_combinations"]), + print(set_clean_class(x, + new_class = x_class[x_class != "bug_drug_combinations"]), ...) message_("Use 'format()' on this result to get a publishable/printable format.", as_note = FALSE) } diff --git a/R/catalogue_of_life.R b/R/catalogue_of_life.R index 49f61e6d..525b4001 100755 --- a/R/catalogue_of_life.R +++ b/R/catalogue_of_life.R @@ -107,8 +107,8 @@ catalogue_of_life_version <- function() { n_total_species = nrow(microorganisms), n_total_synonyms = nrow(microorganisms.old))) - structure(.Data = lst, - class = c("catalogue_of_life_version", "list")) + set_clean_class(lst, + new_class = c("catalogue_of_life_version", "list")) } #' @method print catalogue_of_life_version diff --git a/R/disk.R b/R/disk.R index ed402605..eb2fc05f 100644 --- a/R/disk.R +++ b/R/disk.R @@ -39,7 +39,6 @@ #' @examples #' \donttest{ #' # transform existing disk zones to the `disk` class -#' library(dplyr) #' df <- data.frame(microorganism = "E. coli", #' AMP = 20, #' CIP = 14, @@ -107,8 +106,8 @@ as.disk <- function(x, na.rm = FALSE) { list_missing, call = FALSE) } } - structure(as.integer(x), - class = c("disk", "integer")) + set_clean_class(as.integer(x), + new_class = c("disk", "integer")) } all_valid_disks <- function(x) { diff --git a/R/mic.R b/R/mic.R index a2d2e963..7db9e0e7 100755 --- a/R/mic.R +++ b/R/mic.R @@ -131,8 +131,8 @@ as.mic <- function(x, na.rm = FALSE) { list_missing, call = FALSE) } - structure(.Data = factor(x, levels = lvls, ordered = TRUE), - class = c("mic", "ordered", "factor")) + set_clean_class(factor(x, levels = lvls, ordered = TRUE), + new_class = c("mic", "ordered", "factor")) } } diff --git a/R/mo.R b/R/mo.R index 6904e307..62096c23 100755 --- a/R/mo.R +++ b/R/mo.R @@ -175,7 +175,7 @@ as.mo <- function(x, & isFALSE(Lancefield), error = function(e) FALSE)) { # don't look into valid MO codes, just return them # is.mo() won't work - MO codes might change between package versions - return(to_class_mo(x)) + return(set_clean_class(x, new_class = c("mo", "character"))) } if (tryCatch(all(x == "" | gsub(".*(unknown ).*", "unknown name", tolower(x), perl = TRUE) %in% MO_lookup$fullname_lower, na.rm = TRUE) @@ -228,12 +228,8 @@ as.mo <- function(x, ...) } - to_class_mo(y) -} - -to_class_mo <- function(x) { - structure(.Data = x, - class = c("mo", "character")) + set_clean_class(y, + new_class = c("mo", "character")) } #' @rdname as.mo @@ -399,7 +395,8 @@ exec_as.mo <- function(x, # all empty if (all(identical(trimws(x_input), "") | is.na(x_input) | length(x) == 0)) { if (property == "mo") { - return(to_class_mo(rep(NA_character_, length(x_input)))) + return(set_clean_class(rep(NA_character_, length(x_input)), + new_class = c("mo", "character"))) } else { return(rep(NA_character_, length(x_input))) } @@ -1499,7 +1496,7 @@ exec_as.mo <- function(x, x <- df_found$found[match(df_input$input, df_found$input)] if (property == "mo") { - x <- to_class_mo(x) + x <- set_clean_class(x, new_class = c("mo", "character")) } if (length(mo_renamed()) > 0) { @@ -1740,8 +1737,9 @@ mo_uncertainties <- function() { if (is.null(getOption("mo_uncertainties"))) { return(NULL) } - structure(.Data = as.data.frame(getOption("mo_uncertainties"), stringsAsFactors = FALSE), - class = c("mo_uncertainties", "data.frame")) + set_clean_class(as.data.frame(getOption("mo_uncertainties"), + stringsAsFactors = FALSE), + new_class = c("mo_uncertainties", "data.frame")) } #' @method print mo_uncertainties @@ -1814,8 +1812,9 @@ mo_renamed <- function() { } else { items <- pm_distinct(items, old_name, .keep_all = TRUE) } - structure(.Data = items, - class = c("mo_renamed", "data.frame")) + set_clean_class(as.data.frame(items, + stringsAsFactors = FALSE), + new_class = c("mo_renamed", "data.frame")) } #' @method print mo_renamed diff --git a/R/rsi.R b/R/rsi.R index 4e9ac65e..1fa79775 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -223,17 +223,15 @@ is.rsi.eligible <- function(x, threshold = 0.05) { #' @export as.rsi.default <- function(x, ...) { if (is.rsi(x)) { - x - } else if (all(is.na(x)) || identical(levels(x), c("S", "I", "R"))) { - structure(.Data = factor(x, levels = c("S", "I", "R"), ordered = TRUE), - class = c("rsi", "ordered", "factor")) - } else if (inherits(x, "integer") & all(x %in% c(1:3, NA))) { + return(x) + } + + if (inherits(x, "integer") & all(x %in% c(1:3, NA))) { x[x == 1] <- "S" x[x == 2] <- "I" x[x == 3] <- "R" - structure(.Data = factor(x, levels = c("S", "I", "R"), ordered = TRUE), - class = c("rsi", "ordered", "factor")) - } else { + + } else if (!all(is.na(x)) && !identical(levels(x), c("S", "I", "R"))) { if (!any(x %like% "(R|S|I)", na.rm = TRUE)) { # check if they are actually MICs or disks now that the antibiotic name is valid @@ -280,10 +278,10 @@ as.rsi.default <- function(x, ...) { list_missing, call = FALSE) } } - - structure(.Data = factor(x, levels = c("S", "I", "R"), ordered = TRUE), - class = c("rsi", "ordered", "factor")) } + + set_clean_class(factor(x, levels = c("S", "I", "R"), ordered = TRUE), + new_class = c("rsi", "ordered", "factor")) } #' @rdname as.rsi @@ -804,8 +802,8 @@ exec_as.rsi <- function(method, load_mo_failures_uncertainties_renamed(metadata_mo) - structure(.Data = factor(new_rsi, levels = c("S", "I", "R"), ordered = TRUE), - class = c("rsi", "ordered", "factor")) + set_clean_class(factor(new_rsi, levels = c("S", "I", "R"), ordered = TRUE), + new_class = c("rsi", "ordered", "factor")) } # will be exported using s3_register() in R/zzz.R diff --git a/docs/404.html b/docs/404.html index 333cb5db..3a2193e7 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9020 + 1.4.0.9021 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 55d12c2c..7c605413 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9020 + 1.4.0.9021 diff --git a/docs/articles/index.html b/docs/articles/index.html index 7b138a6b..537821e6 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9020 + 1.4.0.9021 diff --git a/docs/authors.html b/docs/authors.html index c396b164..0b6aac47 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9020 + 1.4.0.9021 diff --git a/docs/index.html b/docs/index.html index d9700088..43ae6c4c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.4.0.9020 + 1.4.0.9021 diff --git a/docs/news/index.html b/docs/news/index.html index f0ee724a..f0936704 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.4.0.9020 + 1.4.0.9021 @@ -236,9 +236,9 @@ Source: NEWS.md -
-

-AMR 1.4.0.9020 Unreleased +
+

+AMR 1.4.0.9021 Unreleased

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 2ae4a883..55b5488a 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-11-16T09:57Z +last_built: 2020-11-16T15:57Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/age_groups.html b/docs/reference/age_groups.html index df8b7115..e0e6de7f 100644 --- a/docs/reference/age_groups.html +++ b/docs/reference/age_groups.html @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9008 + 1.4.0.9021

@@ -316,13 +316,14 @@ The lifecycle of this function is stable# \donttest{ # resistance of ciprofloxacin per age group -library(dplyr) -example_isolates %>% - 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", minimum = 0) +if (require("dplyr")) { + example_isolates %>% + 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", minimum = 0) +} # }
diff --git a/docs/reference/antibiotic_class_selectors.html b/docs/reference/antibiotic_class_selectors.html index 12e7a928..5a79aac5 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.9020 + 1.4.0.9021

diff --git a/docs/reference/as.disk.html b/docs/reference/as.disk.html index 5c8eb708..650a7dcd 100644 --- a/docs/reference/as.disk.html +++ b/docs/reference/as.disk.html @@ -82,7 +82,7 @@ AMR (for R) - 1.4.0.9000 + 1.4.0.9021 @@ -284,7 +284,6 @@ The lifecycle of this function is stableExamples
# \donttest{
 # transform existing disk zones to the `disk` class
-library(dplyr)
 df <- data.frame(microorganism = "E. coli",
                  AMP = 20,
                  CIP = 14,
diff --git a/docs/reference/as.mo.html b/docs/reference/as.mo.html
index 392ceee9..33d1841a 100644
--- a/docs/reference/as.mo.html
+++ b/docs/reference/as.mo.html
@@ -82,7 +82,7 @@
       
       
         AMR (for R)
-        1.4.0.9020
+        1.4.0.9021
       
     
 
diff --git a/docs/reference/index.html b/docs/reference/index.html
index 391fb915..91c18bcd 100644
--- a/docs/reference/index.html
+++ b/docs/reference/index.html
@@ -81,7 +81,7 @@
       
       
         AMR (for R)
-        1.4.0.9020
+        1.4.0.9021
       
     
 
diff --git a/docs/reference/mo_property.html b/docs/reference/mo_property.html
index ed41ba40..94acf13a 100644
--- a/docs/reference/mo_property.html
+++ b/docs/reference/mo_property.html
@@ -82,7 +82,7 @@
       
       
         AMR (for R)
-        1.4.0.9020
+        1.4.0.9021
       
     
 
diff --git a/docs/survey.html b/docs/survey.html
index 6563ec90..472e3707 100644
--- a/docs/survey.html
+++ b/docs/survey.html
@@ -81,7 +81,7 @@
       
       
         AMR (for R)
-        1.4.0.9020
+        1.4.0.9021
       
     
 
diff --git a/man/age_groups.Rd b/man/age_groups.Rd
index d0ad6c16..a213c444 100644
--- a/man/age_groups.Rd
+++ b/man/age_groups.Rd
@@ -69,13 +69,14 @@ age_groups(ages, "children")
 
 \donttest{
 # resistance of ciprofloxacin per age group
-library(dplyr)
-example_isolates \%>\%
-  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", minimum = 0)
+if (require("dplyr")) {
+  example_isolates \%>\%
+    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", minimum = 0)
+}
 }
 }
 \seealso{
diff --git a/man/as.disk.Rd b/man/as.disk.Rd
index a4cb38f3..99e0b67b 100644
--- a/man/as.disk.Rd
+++ b/man/as.disk.Rd
@@ -40,7 +40,6 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/
 \examples{
 \donttest{
 # transform existing disk zones to the `disk` class
-library(dplyr)
 df <- data.frame(microorganism = "E. coli",
                  AMP = 20,
                  CIP = 14,