From 5f650657f02e651220515240f6ce4c2321d6edfa Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Mon, 1 Jun 2026 14:24:53 +0200 Subject: [PATCH 1/3] Add array and matrix to lengthDS permitted classes --- R/lengthDS.R | 2 +- tests/testthat/test-smk-lengthDS.R | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/R/lengthDS.R b/R/lengthDS.R index 1c793aa0..0441e67c 100644 --- a/R/lengthDS.R +++ b/R/lengthDS.R @@ -12,7 +12,7 @@ #' lengthDS <- function(x){ x.val <- .loadServersideObject(x) - .checkClass(obj = x.val, obj_name = x, permitted_classes = c("character", "factor", "integer", "logical", "numeric", "list", "data.frame")) + .checkClass(obj = x.val, obj_name = x, permitted_classes = c("character", "factor", "integer", "logical", "numeric", "list", "data.frame", "array", "matrix")) list(length = length(x.val), class = class(x.val)) } #AGGREGATE FUNCTION diff --git a/tests/testthat/test-smk-lengthDS.R b/tests/testthat/test-smk-lengthDS.R index b410915d..d91fafd9 100644 --- a/tests/testthat/test-smk-lengthDS.R +++ b/tests/testthat/test-smk-lengthDS.R @@ -76,6 +76,26 @@ test_that("simple lengthDS, character data.frame", { expect_equal(res$class, "data.frame") }) +test_that("simple lengthDS, matrix", { + input <- matrix(1:6, nrow = 2, ncol = 3) + + res <- lengthDS("input") + + expect_equal(class(res), "list") + expect_equal(res$length, 6) + expect_equal(res$class, c("matrix", "array")) +}) + +test_that("simple lengthDS, array", { + input <- array(1:24, dim = c(2, 3, 4)) + + res <- lengthDS("input") + + expect_equal(class(res), "list") + expect_equal(res$length, 24) + expect_equal(res$class, "array") +}) + # # Done # From 2e6b5f40d9f48fd6bdc6b9a8bade0d0cb39cb744 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 2 Jun 2026 08:39:14 +0200 Subject: [PATCH 2/3] bumped roxygen to version 8 --- DESCRIPTION | 2 +- man/levelsDS.Rd | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a6737e2e..52c47835 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -76,7 +76,7 @@ Imports: Suggests: spelling, testthat (>= 3.0.0) -RoxygenNote: 7.3.3 +RoxygenNote: 8.0.0 Encoding: UTF-8 Language: en-GB Config/testthat/edition: 3 diff --git a/man/levelsDS.Rd b/man/levelsDS.Rd index c54b7d13..4002c73c 100644 --- a/man/levelsDS.Rd +++ b/man/levelsDS.Rd @@ -10,9 +10,8 @@ levelsDS(x) \item{x}{a factor vector} } \value{ -a list with two elements: \code{Levels} (the factor levels present - in the vector) and \code{class} (the class of the input object, for - client-side consistency checking) +a list with one element: \code{Levels} (the factor levels present + in the vector) } \description{ This function is similar to R function \code{levels}. From c56e03c9c892d74c60e18e9d429349b7e67e7753 Mon Sep 17 00:00:00 2001 From: Tim Cadman <41470917+timcadman@users.noreply.github.com> Date: Tue, 2 Jun 2026 08:39:27 +0200 Subject: [PATCH 3/3] test: add density test for levels --- tests/testthat/test-smk-levelsDS.R | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/testthat/test-smk-levelsDS.R b/tests/testthat/test-smk-levelsDS.R index 2c313e1a..43fd7658 100644 --- a/tests/testthat/test-smk-levelsDS.R +++ b/tests/testthat/test-smk-levelsDS.R @@ -52,6 +52,15 @@ test_that("levelsDS throws error when object is not a factor", { ) }) +test_that("levelsDS blocks when levels density exceeds threshold", { + input <- factor(1:10, levels = 1:10) + + expect_error( + levelsDS("input"), + regexp = "nfilter.levels.density" + ) +}) + # # Done #