Browse code

Accomodate for change to class(matrix()) in R 4.0

Hervé Pagès authored on 24/03/2020 07:29:35
Showing 1 changed files
... ...
@@ -17,7 +17,9 @@
17 17
         return(.getSeedClasses(seed))
18 18
     }
19 19
     else {
20
-        class(seed)
20
+        # Pick the first element returned by class() (starting with R 4.0,
21
+        # 'class(matrix())' is 'c("matrix", "array")').
22
+        class(seed)[[1L]]
21 23
     }
22 24
 }
23 25
 
Browse code

Re-sync with DelayedArray

Peter Hickey authored on 08/04/2018 18:47:50
Showing 1 changed files
... ...
@@ -4,8 +4,12 @@
4 4
 #
5 5
 
6 6
 .getSeedClasses <- function(seed) {
7
-    if (is(seed, "SeedBinder") || is(seed, "ConformableSeedCombiner")) {
8
-        seeds <- seed@seeds
7
+    if (is(seed, "DelayedOp")) {
8
+        seeds <- try(seed@seeds, silent = TRUE)
9
+        if (is(seeds, "try-error")) {
10
+            seed <- seed@seed
11
+            return(.getSeedClasses(seed))
12
+        }
9 13
         return(lapply(seeds, .getSeedClasses))
10 14
     } else if (is(seed, "DelayedArray")) {
11 15
         # A DelayedArray can have another DelayedArray as a seed
Browse code

bsseq now uses DelayedMatrix objects from the DelayedArray package for all matrix-like data

Peter Hickey authored on 07/04/2017 17:42:29
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,42 @@
1
+#-------------------------------------------------------------------------------
2
+# Is a DelayedMatrix object (or the assays of a SummarizedExperiment object)
3
+# backed by a HDF5 file?
4
+#
5
+
6
+.getSeedClasses <- function(seed) {
7
+    if (is(seed, "SeedBinder") || is(seed, "ConformableSeedCombiner")) {
8
+        seeds <- seed@seeds
9
+        return(lapply(seeds, .getSeedClasses))
10
+    } else if (is(seed, "DelayedArray")) {
11
+        # A DelayedArray can have another DelayedArray as a seed
12
+        seed <- seed@seed
13
+        return(.getSeedClasses(seed))
14
+    }
15
+    else {
16
+        class(seed)
17
+    }
18
+}
19
+
20
+# NOTE: Returns TRUE if *any* assay is HDF5Array-backed and FALSE if *all*
21
+#       assays are not HDF5Array-backed
22
+.isHDF5ArrayBacked <- function(object) {
23
+    if (is(object, "SummarizedExperiment")) {
24
+        return(all(vapply(X = assays(object, withDimnames = FALSE),
25
+                          FUN = .isHDF5ArrayBacked,
26
+                          FUN.VALUE = logical(1L))))
27
+    }
28
+    if (is(object, "DelayedArray")) {
29
+        seed <- object@seed
30
+        seed_classes <- .getSeedClasses(seed)
31
+        is_hdf5_backed <- vapply(unlist(seed_classes, use.names = FALSE),
32
+                                 extends, class2 = "HDF5ArraySeed",
33
+                                 logical(1L))
34
+        return(any(is_hdf5_backed))
35
+    } else if (is.matrix(object)) {
36
+        FALSE
37
+    } else if (is.null(object)) {
38
+        FALSE
39
+    } else {
40
+        stop("Don't know how to handle object of class ", class(object))
41
+    }
42
+}