From d6ab3896a16997b9bffeff28d9e5048484f77af5 Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Sun, 4 Aug 2019 10:48:41 +0200 Subject: [PATCH] (v0.7.1.9021) CI fix for resistance_predict --- .gitlab-ci.yml | 2 +- DESCRIPTION | 4 ++-- NEWS.md | 2 +- R/get_locale.R | 5 ++++- R/resistance_predict.R | 25 +++++++++++----------- codecov.yml | 1 - docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 8 +++---- docs/reference/index.html | 2 +- docs/reference/resistance_predict.html | 6 +++--- man/resistance_predict.Rd | 4 ++-- tests/testthat/test-extended.R | 29 ++++++++++++++++++++++++++ tests/testthat/test-freq.R | 6 ++++-- 16 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 tests/testthat/test-extended.R diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 09b504cf..6ab64af1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -118,7 +118,7 @@ coverage: # install missing and outdated packages - Rscript -e 'source(".gitlab-ci.R"); gl_update_pkg_all(repos = "https://cran.rstudio.com", quiet = TRUE, install_pkgdown = FALSE)' # codecov token is set in https://gitlab.com/msberends/AMR/settings/ci_cd - - Rscript -e "cc <- covr::package_coverage(); covr::codecov(coverage = cc, token = '$codecov', exclusions = c('R/atc_online.R', 'R/mo_source.R', 'R/resistance_predict.R')); cat('Code coverage:', covr::percent_coverage(cc))" + - Rscript -e "cc <- covr::package_coverage()); covr::codecov(coverage = cc, token = '$codecov'); cat('Code coverage:', covr::percent_coverage(cc))" coverage: '/Code coverage: \d+\.\d+/' pages: diff --git a/DESCRIPTION b/DESCRIPTION index 9c3addf1..2c5bc58f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9020 -Date: 2019-08-03 +Version: 0.7.1.9021 +Date: 2019-08-04 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index a66cba0f..0cad9316 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.1.9020 +# AMR 0.7.1.9021 ### Breaking * Function `freq()` has moved to a new package, [`clean`](https://github.com/msberends/clean) ([CRAN link](https://cran.r-project.org/package=clean)). Creating frequency tables is actually not the scope of this package (never was) and this function has matured a lot over the last two years. We decided to create a new package for data cleaning and checking and it perfectly fits the `freq()` function. The [`clean`](https://github.com/msberends/clean) package is available on CRAN and will be installed automatically when updating the `AMR` package, that now imports it. In a later stage, the `skewness()` and `kurtosis()` functions will be moved to the `clean` package too. diff --git a/R/get_locale.R b/R/get_locale.R index a81a4c1a..b5316b24 100755 --- a/R/get_locale.R +++ b/R/get_locale.R @@ -67,7 +67,10 @@ get_locale <- function() { } lang <- Sys.getlocale("LC_COLLATE") - # grepl with case = FALSE is faster than like + + # Check the locale settings for a start with one of these languages: + + # grepl() with ignore.case = FALSE is faster than %like% if (grepl("^(English|en_|EN_)", lang, ignore.case = FALSE)) { # as first option to optimise speed "en" diff --git a/R/resistance_predict.R b/R/resistance_predict.R index 80110d54..bf100ce9 100755 --- a/R/resistance_predict.R +++ b/R/resistance_predict.R @@ -28,8 +28,8 @@ #' @param year_max highest year to use in the prediction model, defaults to 10 years after today #' @param year_every unit of sequence between lowest year found in the data and \code{year_max} #' @param minimum minimal amount of available isolates per year to include. Years containing less observations will be estimated by the model. -#' @param model the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options. -#' @param I_as_S a logical to indicate whether values \code{I} should be treated as \code{S} +#' @param model the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution (i.e. using \code{\link{glm}(..., family = \link{binomial})}), assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options. +#' @param I_as_S a logical to indicate whether values \code{I} should be treated as \code{S} (will otherwise be treated as \code{R}) #' @param preserve_measurements a logical to indicate whether predictions of years that are actually available in the data should be overwritten by the original data. The standard errors of those years will be \code{NA}. #' @param info a logical to indicate whether textual analysis should be printed with the name and \code{\link{summary}} of the statistical model. #' @param main title of the plot @@ -162,18 +162,19 @@ resistance_predict <- function(x, as.integer(format(as.Date(x), '%Y')) } } - + df <- x %>% mutate_at(col_ab, as.rsi) %>% - mutate_at(col_ab, droplevels) %>% - mutate_at(col_ab, ~( - if (I_as_S == TRUE) { - gsub("I", "S", .) - } else { - # then I as R - gsub("I", "R", .) - } - )) %>% + mutate_at(col_ab, droplevels) + if (I_as_S == TRUE) { + df <- df %>% + mutate_at(col_ab, ~gsub("I", "S", .)) + } else { + # then I as R + df <- df %>% + mutate_at(col_ab, ~gsub("I", "R", .)) + } + df <- df %>% filter_at(col_ab, all_vars(!is.na(.))) %>% mutate(year = pull(., col_date) %>% year()) %>% group_by_at(c('year', col_ab)) %>% diff --git a/codecov.yml b/codecov.yml index 40a77d53..50a3f625 100644 --- a/codecov.yml +++ b/codecov.yml @@ -18,4 +18,3 @@ coverage: ignore: - "R/atc_online.R" - "R/mo_source.R" - - "R/resistance_predict.R" diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index afc950b3..11801aa4 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9020 + 0.7.1.9021 diff --git a/docs/articles/index.html b/docs/articles/index.html index 3d0cdfde..28f44446 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9020 + 0.7.1.9021 diff --git a/docs/authors.html b/docs/authors.html index afd686da..34d8dba3 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9020 + 0.7.1.9021 diff --git a/docs/index.html b/docs/index.html index 4424837a..d1747e19 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.1.9020 + 0.7.1.9021 diff --git a/docs/news/index.html b/docs/news/index.html index 3f979420..fad857df 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.1.9020 + 0.7.1.9021 @@ -225,9 +225,9 @@ -
+

-AMR 0.7.1.9020 Unreleased +AMR 0.7.1.9021 Unreleased

@@ -1198,7 +1198,7 @@ Using as.mo(..., allow_uncertain = 3)

Contents

diff --git a/docs/reference/resistance_predict.html b/docs/reference/resistance_predict.html index ee1abfe4..c323f78c 100644 --- a/docs/reference/resistance_predict.html +++ b/docs/reference/resistance_predict.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.1.9015 + 0.7.1.9021
@@ -284,11 +284,11 @@ model -

the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options.

+

the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution (i.e. using glm(..., family = binomial)), assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options.

I_as_S -

a logical to indicate whether values I should be treated as S

+

a logical to indicate whether values I should be treated as S (will otherwise be treated as R)

preserve_measurements diff --git a/man/resistance_predict.Rd b/man/resistance_predict.Rd index b82ada42..3862a718 100644 --- a/man/resistance_predict.Rd +++ b/man/resistance_predict.Rd @@ -38,9 +38,9 @@ ggplot_rsi_predict(x, main = paste("Resistance Prediction of", x_name), \item{minimum}{minimal amount of available isolates per year to include. Years containing less observations will be estimated by the model.} -\item{model}{the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options.} +\item{model}{the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution (i.e. using \code{\link{glm}(..., family = \link{binomial})}), assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options.} -\item{I_as_S}{a logical to indicate whether values \code{I} should be treated as \code{S}} +\item{I_as_S}{a logical to indicate whether values \code{I} should be treated as \code{S} (will otherwise be treated as \code{R})} \item{preserve_measurements}{a logical to indicate whether predictions of years that are actually available in the data should be overwritten by the original data. The standard errors of those years will be \code{NA}.} diff --git a/tests/testthat/test-extended.R b/tests/testthat/test-extended.R new file mode 100644 index 00000000..9d79dc25 --- /dev/null +++ b/tests/testthat/test-extended.R @@ -0,0 +1,29 @@ +# ==================================================================== # +# TITLE # +# Antimicrobial Resistance (AMR) Analysis # +# # +# SOURCE # +# https://gitlab.com/msberends/AMR # +# # +# LICENCE # +# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) # +# # +# This R package is free software; you can freely use and distribute # +# it for both personal and commercial purposes under the terms of the # +# GNU General Public License version 2.0 (GNU GPL-2), as published by # +# the Free Software Foundation. # +# # +# This R package was created for academic research and was publicly # +# released in the hope that it will be useful, but it comes WITHOUT # +# ANY WARRANTY OR LIABILITY. # +# Visit our website for more info: https://msberends.gitlab.io/AMR. # +# ==================================================================== # + +context("extended.R") + +test_that("extensions work", { + + expect_identical(scale_type.mo(), "discrete") + expect_identical(scale_type.ab(), "discrete") + +}) diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R index 02ebd32e..5d329901 100755 --- a/tests/testthat/test-freq.R +++ b/tests/testthat/test-freq.R @@ -24,8 +24,10 @@ context("freq.R") test_that("frequency table works", { library(clean) # mo - expect_output(print(freq(septic_patients$mo))) + expect_true(is.freq(freq(septic_patients$mo))) # rsi - expect_output(print(freq(septic_patients$AMX))) + expect_true(is.freq(freq(septic_patients$AMX))) + library(dplyr) + expect_true(is.freq(septic_patients %>% freq(mo))) })