diff --git a/R/RandomWalkTest.R b/R/RandomWalkTest.R index 7b9ad8b879f6df2c599daf2d9044565e1dc51e87..506775a5be5b47492d0f8c96a98f15565ef46447 100644 --- a/R/RandomWalkTest.R +++ b/R/RandomWalkTest.R @@ -102,8 +102,15 @@ 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))) { - 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 { + 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 7ef24b5a014e63beca310092346b7faf3748f90c..0e64435931bf0df9cdddae5df260ee8f34824c5a 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),