From 49a1e3495e361431c1ed25c22c3ba833cc0d5009 Mon Sep 17 00:00:00 2001 From: aho Date: Tue, 29 Nov 2022 18:39:36 +0100 Subject: [PATCH 1/2] Bugfix for p.val when output is NA; it should return one NA only --- R/Trend.R | 6 +++-- man/Trend.Rd | 4 +++- tests/testthat/test-Trend.R | 46 ++++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/R/Trend.R b/R/Trend.R index 1f714a6..d709101 100644 --- a/R/Trend.R +++ b/R/Trend.R @@ -50,7 +50,9 @@ #' \code{conf = TRUE}. #'} #'\item{$p.val}{ -#' The p-value calculated by anova(). Only present if \code{pval = TRUE}. +#' A numeric array of p-value calculated by anova(). The first dimension +#' 'stats' is 1, followed by the same dimensions as parameter 'data' except +#' the 'time_dim' dimension. Only present if \code{pval = TRUE}. #'} #'\item{$detrended}{ #' A numeric array with the same dimensions as paramter 'data', containing the @@ -188,7 +190,7 @@ Trend <- function(data, time_dim = 'ftime', interval = 1, polydeg = 1, } if (pval) { - p.val <- rep(NA, polydeg + 1) + p.val <- as.array(NA) } } diff --git a/man/Trend.Rd b/man/Trend.Rd index d283ee6..7623c36 100644 --- a/man/Trend.Rd +++ b/man/Trend.Rd @@ -66,7 +66,9 @@ A list containing: \code{conf = TRUE}. } \item{$p.val}{ - The p-value calculated by anova(). Only present if \code{pval = TRUE}. + A numeric array of p-value calculated by anova(). The first dimension + 'stats' is 1, followed by the same dimensions as parameter 'data' except + the 'time_dim' dimension. Only present if \code{pval = TRUE}. } \item{$detrended}{ A numeric array with the same dimensions as paramter 'data', containing the diff --git a/tests/testthat/test-Trend.R b/tests/testthat/test-Trend.R index 49a9982..07da6ce 100644 --- a/tests/testthat/test-Trend.R +++ b/tests/testthat/test-Trend.R @@ -112,6 +112,22 @@ test_that("2. Output checks: dat1", { 0.1153846, tolerance = 0.001 ) + expect_equal( + dim(Trend(dat1)$trend), + c(stats = 2, dat = 1, sdate = 2) + ) + expect_equal( + dim(Trend(dat1)$p), + c(stats = 1, dat = 1, sdate = 2) + ) + expect_equal( + dim(Trend(dat1)$detrend), + c(ftime = 13, dat = 1, sdate = 2) + ) + expect_equal( + dim(Trend(dat1, polydeg = 3)$trend), + c(stats = 4, dat = 1, sdate = 2) + ) }) @@ -176,8 +192,32 @@ test_that("5. Output checks: dat4", { as.numeric(rep(NA, 5)) ) expect_equal( - Trend(dat4)$p.val[, 1, 1, 1], - c(NA, 0.01800594), - tolerance = 0.0001 + dim(Trend(dat4)$p.val), + c(stats = 1, lat = 2, lon = 3, lev = 2) + ) + expect_equal( + is.na(Trend(dat4)$p.val[, 1, 1, 1]), + TRUE ) + expect_equal( + as.vector(Trend(dat4)$trend[1, 2, , ]), + as.vector(Trend(dat3)$trend[1, 2, , ]) + ) + expect_equal( + as.vector(Trend(dat4)$p.val[1, 2, , ]), + as.vector(Trend(dat3)$p.val[1, 2, , ]) + ) + expect_equal( + as.vector(Trend(dat4)$conf.l[1, 2, , ]), + as.vector(Trend(dat3)$conf.l[1, 2, , ]) + ) + expect_equal( + as.vector(Trend(dat4)$conf.u[1, 2, , ]), + as.vector(Trend(dat3)$conf.u[1, 2, , ]) + ) + expect_equal( + as.vector(Trend(dat4)$de[1, 2, , ]), + as.vector(Trend(dat3)$de[1, 2, , ]) + ) + }) -- GitLab From bd9171a11e2ecb267571b1101e74d39f46b3f1d6 Mon Sep 17 00:00:00 2001 From: aho Date: Tue, 29 Nov 2022 18:40:19 +0100 Subject: [PATCH 2/2] Don't ignore unit test --- .Rbuildignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index 6008b57..4212858 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,7 +10,7 @@ README\.md$ vignettes .gitlab-ci.yml # unit tests should be ignored when building the package for CRAN -^tests$ +#^tests$ # CDO is not in windbuilder, so we can test the unit tests by winbuilder # but test-CDORemap.R and test-Load.R needs to be hidden #tests/testthat/test-CDORemap.R -- GitLab