diff --git a/DESCRIPTION b/DESCRIPTION index 5d3a85e8..2791bafc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.2.0.9002 -Date: 2020-06-03 +Version: 1.2.0.9003 +Date: 2020-06-05 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 048dc9b3..9e8fac12 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 1.2.0.9002 -## Last updated: 03-Jun-2020 +# AMR 1.2.0.9003 +## Last updated: 05-Jun-2020 ### Changed * Fixed a bug where `eucast_rules()` would not work on a tibble when the `tibble` or `dplyr` package was loaded diff --git a/R/aa_helper_functions.R b/R/aa_helper_functions.R index 28f5860f..8c926c2f 100755 --- a/R/aa_helper_functions.R +++ b/R/aa_helper_functions.R @@ -250,26 +250,63 @@ dataset_UTF8_to_ASCII <- function(df) { df } - -# replace crayon::has_color, but now also FALSE on non-interactive mode -has_colour <- function() { - if (Sys.getenv("TERM") == "dumb" | !interactive()) { +has_colour <- function () { + # this is a base R version of crayon::has_color + enabled <- getOption("crayon.enabled") + if (!is.null(enabled)) { + return(isTRUE(enabled)) + } + rstudio_with_ansi_support <- function(x) { + if (Sys.getenv("RSTUDIO", "") == "") { + return(FALSE) + } + if ((cols <- Sys.getenv("RSTUDIO_CONSOLE_COLOR", "")) != "" && !is.na(as.numeric(cols))) { + return(TRUE) + } + tryCatch(get("isAvailable", envir = asNamespace("rstudioapi"))(), error = function(e) return(FALSE)) && + tryCatch(get("hasFun", envir = asNamespace("rstudioapi"))("getConsoleHasColor"), error = function(e) return(FALSE)) + } + if (rstudio_with_ansi_support() && sink.number() == 0) { + return(TRUE) + } + if (!isatty(stdout())) { return(FALSE) } if (tolower(Sys.info()["sysname"]) == "windows") { - if (Sys.getenv("ConEmuANSI") == "ON" | Sys.getenv("CMDER_ROOT") != "") { + if (Sys.getenv("ConEmuANSI") == "ON") { return(TRUE) - } else { - return(FALSE) } + if (Sys.getenv("CMDER_ROOT") != "") { + return(TRUE) + } + return(FALSE) } - "COLORTERM" %in% names(Sys.getenv()) | grepl("^screen|^xterm|^vt100|color|ansi|cygwin|linux", - Sys.getenv("TERM"), - ignore.case = TRUE, - perl = TRUE) + emacs_version <- function () { + ver <- Sys.getenv("INSIDE_EMACS") + if (ver == "") { + return(NA_integer_) + } + ver <- gsub("'", "", ver) + ver <- strsplit(ver, ",", fixed = TRUE)[[1]] + ver <- strsplit(ver, ".", fixed = TRUE)[[1]] + as.numeric(ver) + } + if ((Sys.getenv("EMACS") != "" || Sys.getenv("INSIDE_EMACS") != "") && + !is.na(emacs_version()[1]) && emacs_version()[1] >= 23) { + return(TRUE) + } + if ("COLORTERM" %in% names(Sys.getenv())) { + return(TRUE) + } + if (Sys.getenv("TERM") == "dumb") { + return(FALSE) + } + grepl(pattern = "^screen|^xterm|^vt100|color|ansi|cygwin|linux", + x = Sys.getenv("TERM"), + ignore.case = TRUE, + perl = TRUE) } - # the crayon colours try_colour <- function(..., before, after, collapse = " ") { txt <- paste0(unlist(list(...)), collapse = collapse) diff --git a/R/eucast_rules.R b/R/eucast_rules.R index efc39c49..713e87a3 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -614,7 +614,7 @@ eucast_rules <- function(x, if (info == TRUE) { cat(font_bold(paste0("\nRules by this AMR package (", font_red(paste0("v", utils::packageVersion("AMR"), ", ", - format(utils::packageDate("AMR"), "%Y"))), ")\n"))) + format(utils::packageDate("AMR"), "%Y"))), "), see ?eucast_rules\n"))) } ab_enzyme <- subset(antibiotics, name %like% "/")[, c("ab", "name")] diff --git a/R/filter_ab_class.R b/R/filter_ab_class.R index 5af90618..9d51b6e9 100644 --- a/R/filter_ab_class.R +++ b/R/filter_ab_class.R @@ -101,6 +101,7 @@ filter_ab_class <- function(x, return(x.bak) } # get reference data + ab_class.bak <- ab_class ab_class <- gsub("[^a-zA-Z0-9]+", ".*", ab_class) ab_class <- gsub("(ph|f)", "(ph|f)", ab_class) ab_class <- gsub("(t|th)", "(t|th)", ab_class) @@ -109,6 +110,10 @@ filter_ab_class <- function(x, atc_group1 %like% ab_class | atc_group2 %like% ab_class) ab_group <- find_ab_group(ab_class) + if (ab_group == "") { + message(font_blue(paste0("NOTE: unknown antimicrobial class '", ab_class.bak, "', data left unchanged."))) + return(x.bak) + } # 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) { diff --git a/data-raw/country_analysis.R b/data-raw/country_analysis.R index 44a22bf1..11e90808 100644 --- a/data-raw/country_analysis.R +++ b/data-raw/country_analysis.R @@ -127,12 +127,12 @@ countries_plot <- ggplot(countries_geometry) + countries_plot_mini <- countries_plot countries_plot_mini$data <- countries_plot_mini$data %>% filter(ID != "Antarctica") -countries_plot_mini <- countries_plot_mini + scale_colour_gradient(low = "#81899B", high = "#81899B") +# countries_plot_mini <- countries_plot_mini + scale_colour_gradient(low = "#81899B", high = "#81899B") countries_plot_big <- countries_plot + - labs(title = tools::toTitleCase("Countries where the AMR package for R was downloaded from"), - subtitle = paste0("Between March 2018 (first release) and ", format(Sys.Date(), "%B %Y"), "." #, - #"The dots denote visitors on our website https://gitlab.io/msberends/AMR." - )) + + labs(title = tools::toTitleCase("Countries the AMR package for R was downloaded from"), + subtitle = paste0("Between March 2018 (first release) and ", + format(Sys.Date(), "%B %Y")), + caption = "Source: https://cran-logs.rstudio.com") + theme(plot.title = element_text(size = 16, hjust = 0.5), plot.subtitle = element_text(size = 12, hjust = 0.5)) + geom_text(aes(x = -170, @@ -142,12 +142,7 @@ countries_plot_big <- countries_plot + paste(sort(countries_name[!is.na(countries_name)]), collapse = ", ")), 200)), hjust = 0, - size = 4) # + - # # points of visitors - # geom_point(data = ip_tbl, - # aes(x = x, y = y), - # size = 1, - # colour = "#81899B") + size = 4) # main website page ggsave("pkgdown/logos/countries.png", diff --git a/docs/404.html b/docs/404.html index 8e486d95..717e30f7 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9002 + 1.2.0.9003 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 032a9f3b..14fcc2d0 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9002 + 1.2.0.9003 diff --git a/docs/articles/index.html b/docs/articles/index.html index 8118b224..5245afa0 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9002 + 1.2.0.9003 diff --git a/docs/authors.html b/docs/authors.html index 5475d87f..11180804 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9002 + 1.2.0.9003 diff --git a/docs/countries.png b/docs/countries.png index 445ee879..31fc19e1 100644 Binary files a/docs/countries.png and b/docs/countries.png differ diff --git a/docs/countries_large.png b/docs/countries_large.png index edf17cf7..262b394b 100644 Binary files a/docs/countries_large.png and b/docs/countries_large.png differ diff --git a/docs/index.html b/docs/index.html index c58d3638..01fdb382 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.2.0.9002 + 1.2.0.9003 diff --git a/docs/news/index.html b/docs/news/index.html index 081ceac3..93893f38 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9002 + 1.2.0.9003 @@ -229,13 +229,13 @@ Source: NEWS.md -
-

-AMR 1.2.0.9002 Unreleased +
+

+AMR 1.2.0.9003 Unreleased

-
+

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

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 8849ba08..4f051c92 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-03T12:33Z +last_built: 2020-06-05T11:55Z urls: reference: https://msberends.gitlab.io/AMR/reference article: https://msberends.gitlab.io/AMR/articles diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index 4ab7b380..2554f2b0 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -82,7 +82,7 @@ AMR (for R) - 1.2.0.9001 + 1.2.0.9003

diff --git a/docs/reference/index.html b/docs/reference/index.html index c25e7a19..ca87e365 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.2.0.9002 + 1.2.0.9003
diff --git a/pkgdown/logos/countries.png b/pkgdown/logos/countries.png index 445ee879..31fc19e1 100644 Binary files a/pkgdown/logos/countries.png and b/pkgdown/logos/countries.png differ diff --git a/pkgdown/logos/countries_large.png b/pkgdown/logos/countries_large.png index edf17cf7..262b394b 100644 Binary files a/pkgdown/logos/countries_large.png and b/pkgdown/logos/countries_large.png differ