From ea53ca571a8e5ad82863aa64c0c550ad73fc4eff Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 21 Aug 2020 20:14:01 +0200 Subject: [PATCH 1/2] Bugfix for pval and detrended output --- R/Trend.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/Trend.R b/R/Trend.R index 7096d48..1f6664a 100644 --- a/R/Trend.R +++ b/R/Trend.R @@ -180,7 +180,7 @@ Trend <- function(data, time_dim = 'ftime', interval = 1, polydeg = 1, } else { trend <- rep(NA, polydeg + 1) - detrend <- NA + detrended <- rep(NA, length(x)) if (conf) { conf.lower <- rep(NA, polydeg + 1) @@ -188,7 +188,7 @@ Trend <- function(data, time_dim = 'ftime', interval = 1, polydeg = 1, } if (pval) { - p.val <- NA + p.val <- rep(NA, polydeg + 1) } } -- GitLab From b93c89f000ae50da3aa34f6f7ac8075d0a49f739 Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 21 Aug 2020 20:22:15 +0200 Subject: [PATCH 2/2] Add unit test for Trend bugfix --- tests/testthat/test-Trend.R | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-Trend.R b/tests/testthat/test-Trend.R index 79049b5..49a9982 100644 --- a/tests/testthat/test-Trend.R +++ b/tests/testthat/test-Trend.R @@ -16,7 +16,10 @@ context("s2dv::Trend tests") set.seed(1) na <- floor(runif(5, min = 1, max = 60)) dat3[na] <- NA - + + # dat4 + dat4 <- dat3 + dat4[, 1, 1, 1] <- NA ############################################## test_that("1. Input checks", { @@ -165,3 +168,16 @@ test_that("4. Output checks: dat3", { }) + +############################################## +test_that("5. Output checks: dat4", { + expect_equal( + Trend(dat4)$detrended[, 1, 1, 1], + as.numeric(rep(NA, 5)) + ) + expect_equal( + Trend(dat4)$p.val[, 1, 1, 1], + c(NA, 0.01800594), + tolerance = 0.0001 + ) +}) -- GitLab