From fa2c53faeaa273f216af887df5444f39b486c4ad Mon Sep 17 00:00:00 2001 From: ARIADNA BATALLA FERRES Date: Wed, 3 Sep 2025 17:04:51 +0200 Subject: [PATCH 1/3] Relax dimensions check in R/RandomWalkTest.R to accept dimensions in different order --- R/RandomWalkTest.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/RandomWalkTest.R b/R/RandomWalkTest.R index 7b9ad8b8..952e9efc 100644 --- a/R/RandomWalkTest.R +++ b/R/RandomWalkTest.R @@ -102,7 +102,8 @@ RandomWalkTest <- function(skill_A, skill_B, time_dim = 'sdate', if (!is.numeric(skill_A) | !is.numeric(skill_B)) { stop("Parameters 'skill_A' and 'skill_B' must be a numerical array.") } - if (!identical(dim(skill_A), dim(skill_B))) { + if (!setequal(names(dim(skill_A)), names(dim(skill_B))) || + any(dim(skill_A)[names(dim(skill_B))] != dim(skill_B))) { stop("Parameters 'skill_A' and 'skill_B' must have the same dimensions.") } ## time_dim -- GitLab From cd2dc2cc2dbc179eded38981a373492acd479818 Mon Sep 17 00:00:00 2001 From: ARIADNA BATALLA FERRES Date: Wed, 3 Sep 2025 17:32:30 +0200 Subject: [PATCH 2/3] Update check to include input arrays with no dimension names --- R/RandomWalkTest.R | 13 ++++++++++--- tests/testthat/test-RandomWalkTest.R | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/R/RandomWalkTest.R b/R/RandomWalkTest.R index 952e9efc..efa7909b 100644 --- a/R/RandomWalkTest.R +++ b/R/RandomWalkTest.R @@ -102,9 +102,16 @@ RandomWalkTest <- function(skill_A, skill_B, time_dim = 'sdate', if (!is.numeric(skill_A) | !is.numeric(skill_B)) { stop("Parameters 'skill_A' and 'skill_B' must be a numerical array.") } - if (!setequal(names(dim(skill_A)), names(dim(skill_B))) || - any(dim(skill_A)[names(dim(skill_B))] != dim(skill_B))) { - stop("Parameters 'skill_A' and 'skill_B' must have the same dimensions.") + if (is.null(names(dim(skill_A))) || is.null(names(dim(skill_B)))) { + if (!identical(dim(skill_A), dim(skill_B))) { + stop("Parameters 'skill_A' and 'skill_B' must have the same dimension sizes in the same order if no dimension names are provided.") + } + } else { + # Names exist: allow different orders, but sizes must match + if (!setequal(names(dim(skill_A)), names(dim(skill_B))) || + any(dim(skill_A)[names(dim(skill_B))] != dim(skill_B))) { + stop("Parameters 'skill_A' and 'skill_B' must have the same dimensions.") + } } ## time_dim if (!is.character(time_dim) | length(time_dim) != 1) { diff --git a/tests/testthat/test-RandomWalkTest.R b/tests/testthat/test-RandomWalkTest.R index 7ef24b5a..0e644359 100644 --- a/tests/testthat/test-RandomWalkTest.R +++ b/tests/testthat/test-RandomWalkTest.R @@ -23,7 +23,7 @@ test_that("1. Input checks", { ) expect_error( RandomWalkTest(array(1:10, dim = c(2, 5)), array(1:12, dim = c(2, 6))), - "Parameters 'skill_A' and 'skill_B' must have the same dimensions." + "Parameters 'skill_A' and 'skill_B' must have the same dimension sizes in the same order if no dimension names are provided." ) expect_error( RandomWalkTest(1:10, 2:11, time_dim = 12), -- GitLab From 4d490c8df6a8909a0652dcb0ab37e4adc0d69d00 Mon Sep 17 00:00:00 2001 From: abatalla Date: Thu, 4 Sep 2025 15:19:15 +0200 Subject: [PATCH 3/3] Remove comment in RandomWalkTest.R --- R/RandomWalkTest.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/RandomWalkTest.R b/R/RandomWalkTest.R index efa7909b..506775a5 100644 --- a/R/RandomWalkTest.R +++ b/R/RandomWalkTest.R @@ -107,7 +107,6 @@ RandomWalkTest <- function(skill_A, skill_B, time_dim = 'sdate', stop("Parameters 'skill_A' and 'skill_B' must have the same dimension sizes in the same order if no dimension names are provided.") } } else { - # Names exist: allow different orders, but sizes must match if (!setequal(names(dim(skill_A)), names(dim(skill_B))) || any(dim(skill_A)[names(dim(skill_B))] != dim(skill_B))) { stop("Parameters 'skill_A' and 'skill_B' must have the same dimensions.") -- GitLab