Browse code

Testfix for new Matrix dimnames behavior, DelayedArray::sweep import.

LTLA authored on 08/09/2022 20:18:11
Showing 3 changed files

... ...
@@ -1,6 +1,6 @@
1 1
 Package: ScaledMatrix
2
-Version: 1.4.0
3
-Date: 2021-01-13
2
+Version: 1.4.1
3
+Date: 2022-09-08
4 4
 Title: Creating a DelayedMatrix of Scaled and Centered Values 
5 5
 Authors@R: person("Aaron", "Lun", role=c("aut", "cre", "cph"),
6 6
         email="[email protected]")
... ...
@@ -74,3 +74,10 @@ expect_equal_product <- function(x, y) {
74 74
     if (all(lengths(dimnames(y))==0L)) dimnames(y) <- NULL 
75 75
     expect_equal(X, y)
76 76
 }
77
+
78
+purgenames <- function(mat) {
79
+    if (identical(dimnames(mat), list(NULL, NULL))) {
80
+        dimnames(mat) <- NULL
81
+    }
82
+    mat
83
+}
... ...
@@ -12,7 +12,7 @@ test_that("ScaledMatrix utility functions work as expected", {
12 12
         expect_identical(extract_array(test$def, list(1:10, 1:10)), test$ref[1:10, 1:10])
13 13
         expect_identical(extract_array(test$def, list(1:10, NULL)), test$ref[1:10,])
14 14
         expect_identical(extract_array(test$def, list(NULL, 1:10)), test$ref[,1:10])
15
-        expect_identical(as.matrix(test$def), test$ref)
15
+        expect_identical(purgenames(as.matrix(test$def)), purgenames(test$ref))
16 16
 
17 17
         expect_equal(rowSums(test$def), rowSums(test$ref))
18 18
         expect_equal(colSums(test$def), colSums(test$ref))
... ...
@@ -22,7 +22,7 @@ test_that("ScaledMatrix utility functions work as expected", {
22 22
         tdef <- t(test$def)
23 23
         expect_s4_class(tdef, "ScaledMatrix") # still a DefMat!
24 24
         expect_identical(t(tdef), test$def)
25
-        expect_identical(as.matrix(tdef), t(test$ref))
25
+        expect_identical(purgenames(as.matrix(tdef)), purgenames(t(test$ref)))
26 26
 
27 27
         # Checking column names getting and setting.
28 28
         spawn_names <- sprintf("THING_%i", seq_len(ncol(test$def)))
... ...
@@ -50,7 +50,7 @@ set.seed(1000011)
50 50
 test_that("ScaledMatrix subsetting works as expected", {
51 51
     expect_identical_and_defmat <- function(x, y) {
52 52
         expect_s4_class(x, "ScaledMatrix") # class is correctly preserved by direct seed modification.
53
-        expect_identical(as.matrix(x), y)
53
+        expect_identical(purgenames(as.matrix(x)), purgenames(y))
54 54
     }
55 55
 
56 56
     possibles <- spawn_scenarios()
... ...
@@ -96,6 +96,6 @@ test_that("DelayedMatrix wrapping works", {
96 96
         expect_equal_product(test$def*v, test$ref*v)
97 97
 
98 98
         w <- rnorm(ncol(test$def))
99
-        expect_equal_product(sweep(test$def, 2, w, "*"), sweep(test$ref, 2, w, "*"))
99
+        expect_equal_product(DelayedArray::sweep(test$def, 2, w, "*"), sweep(test$ref, 2, w, "*"))
100 100
     }
101 101
 })