Contents

1 Introduction

ZarrArray is an infrastructure package that leverages the Rarr package to bring Zarr datasets in R as DelayedArray objects.

The package implements two main classes:

Both classes extend the DelayedArray class from the DelayedArray package. This means that ZarrArray and ZarrSparseMatrix objects allow easy and intuitive R-style array- and matrix-like manipulation of on-disk Zarr datasets.

2 Install and load the package

Like any other Bioconductor package, ZarrArray should always be installed with BiocManager::install():

if (!require("BiocManager", quietly=TRUE))
    install.packages("BiocManager")
BiocManager::install("ZarrArray")

Load the package:

library(ZarrArray)

3 ZarrArray objects

The ZarrArray class is a DelayedArray extension for representing and operating on a conventional (i.e. dense) Zarr dataset. Please check its man page (with ?ZarrArray) for more information.

3.1 Construction

To construct a ZarrArray object, simply call the ZarrArray() constructor function on the path to a Zarr dataset:

zarr_path <- system.file(package="Rarr", "extdata",
                         "zarr_examples", "column-first", "int32.zarr")
A <- ZarrArray(zarr_path)
A
## <30 x 20 x 10> ZarrArray object of type "integer":
## ,,1
##        [,1]  [,2]  [,3]  [,4] ... [,17] [,18] [,19] [,20]
##  [1,]     1     2     3     4   .    17    18    19    20
##  [2,]     1     0     0     0   .     0     0     0     0
##   ...     .     .     .     .   .     .     .     .     .
## [29,]     1     0     0     0   .     0     0     0     0
## [30,]     1     0     0     0   .     0     0     0     0
## 
## ...
## 
## ,,10
##        [,1]  [,2]  [,3]  [,4] ... [,17] [,18] [,19] [,20]
##  [1,]     0     0     0     0   .     0     0     0     0
##  [2,]     0     0     0     0   .     0     0     0     0
##   ...     .     .     .     .   .     .     .     .     .
## [29,]     0     0     0     0   .     0     0     0     0
## [30,]     0     0     0     0   .     0     0     0     0

3.2 Array and matrix operations

Note that ZarrArray objects are DelayedArray derivatives, and, therefore, support all operations (delayed or block-processed) supported by DelayedArray objects:

class(A)
## [1] "ZarrArray"
## attr(,"package")
## [1] "ZarrArray"
is(A, "DelayedArray")
## [1] TRUE

This allows ZarrArray objects to “look and feel” like ordinary arrays or matrices in R, by mimicking their behavior. In particular, ZarrArray objects suppport most of the “standard array API” defined in base R like dim(), length(), dimnames(), [, aperm(), max(), sum(), arithmetic and comparison operations, math functions, etc…

dim(A)
## [1] 30 20 10
length(A)
## [1] 6000
A[1:5, , 1]
## <5 x 20> DelayedMatrix object of type "integer":
##       [,1]  [,2]  [,3]  [,4] ... [,17] [,18] [,19] [,20]
## [1,]     1     2     3     4   .    17    18    19    20
## [2,]     1     0     0     0   .     0     0     0     0
## [3,]     1     0     0     0   .     0     0     0     0
## [4,]     1     0     0     0   .     0     0     0     0
## [5,]     1     0     0     0   .     0     0     0     0
aperm(A)
## <10 x 20 x 30> DelayedArray object of type "integer":
## ,,1
##        [,1]  [,2]  [,3]  [,4] ... [,17] [,18] [,19] [,20]
##  [1,]     1     2     3     4   .    17    18    19    20
##  [2,]     0     0     0     0   .     0     0     0     0
##   ...     .     .     .     .   .     .     .     .     .
##  [9,]     0     0     0     0   .     0     0     0     0
## [10,]     0     0     0     0   .     0     0     0     0
## 
## ...
## 
## ,,30
##        [,1]  [,2]  [,3]  [,4] ... [,17] [,18] [,19] [,20]
##  [1,]     1     0     0     0   .     0     0     0     0
##  [2,]     0     0     0     0   .     0     0     0     0
##   ...     .     .     .     .   .     .     .     .     .
##  [9,]     0     0     0     0   .     0     0     0     0
## [10,]     0     0     0     0   .     0     0     0     0
max(A)
## [1] 20
sum(A)
## [1] 239
A - 0.5
## <30 x 20 x 10> DelayedArray object of type "double":
## ,,1
##        [,1]  [,2]  [,3] ... [,19] [,20]
##  [1,]   0.5   1.5   2.5   .  18.5  19.5
##  [2,]   0.5  -0.5  -0.5   .  -0.5  -0.5
##   ...     .     .     .   .     .     .
## [29,]   0.5  -0.5  -0.5   .  -0.5  -0.5
## [30,]   0.5  -0.5  -0.5   .  -0.5  -0.5
## 
## ...
## 
## ,,10
##        [,1]  [,2]  [,3] ... [,19] [,20]
##  [1,]  -0.5  -0.5  -0.5   .  -0.5  -0.5
##  [2,]  -0.5  -0.5  -0.5   .  -0.5  -0.5
##   ...     .     .     .   .     .     .
## [29,]  -0.5  -0.5  -0.5   .  -0.5  -0.5
## [30,]  -0.5  -0.5  -0.5   .  -0.5  -0.5
A^3
## <30 x 20 x 10> DelayedArray object of type "double":
## ,,1
##        [,1]  [,2]  [,3] ... [,19] [,20]
##  [1,]     1     8    27   .  6859  8000
##  [2,]     1     0     0   .     0     0
##   ...     .     .     .   .     .     .
## [29,]     1     0     0   .     0     0
## [30,]     1     0     0   .     0     0
## 
## ...
## 
## ,,10
##        [,1]  [,2]  [,3] ... [,19] [,20]
##  [1,]     0     0     0   .     0     0
##  [2,]     0     0     0   .     0     0
##   ...     .     .     .   .     .     .
## [29,]     0     0     0   .     0     0
## [30,]     0     0     0   .     0     0
A == 0L
## <30 x 20 x 10> DelayedArray object of type "logical":
## ,,1
##        [,1]  [,2]  [,3] ... [,19] [,20]
##  [1,] FALSE FALSE FALSE   . FALSE FALSE
##  [2,] FALSE  TRUE  TRUE   .  TRUE  TRUE
##   ...     .     .     .   .     .     .
## [29,] FALSE  TRUE  TRUE   .  TRUE  TRUE
## [30,] FALSE  TRUE  TRUE   .  TRUE  TRUE
## 
## ...
## 
## ,,10
##        [,1]  [,2]  [,3] ... [,19] [,20]
##  [1,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
##  [2,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
##   ...     .     .     .   .     .     .
## [29,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
## [30,]  TRUE  TRUE  TRUE   .  TRUE  TRUE
sqrt(A)
## <30 x 20 x 10> DelayedArray object of type "double":
## ,,1
##           [,1]     [,2]     [,3] ...    [,19]    [,20]
##  [1,] 1.000000 1.414214 1.732051   . 4.358899 4.472136
##  [2,] 1.000000 0.000000 0.000000   . 0.000000 0.000000
##   ...        .        .        .   .        .        .
## [29,]        1        0        0   .        0        0
## [30,]        1        0        0   .        0        0
## 
## ...
## 
## ,,10
##        [,1]  [,2]  [,3] ... [,19] [,20]
##  [1,]     0     0     0   .     0     0
##  [2,]     0     0     0   .     0     0
##   ...     .     .     .   .     .     .
## [29,]     0     0     0   .     0     0
## [30,]     0     0     0   .     0     0

In the 2D case, they also support the “standard matrix API” defined in base R like nrow(), ncol(), rownames(), colnames(), t(), rbind(), cbind(), rowSums(), colSums(), %*%, etc…, as well as some row/column summarization operations from the matrixStats package like rowMaxs(), colVars(), etc…

3.3 Other operations

Other operations are supported that are specific to DelayedArray objects and their derivatives:

path(A)
## [1] "/home/biocbuild/bbs-3.24-bioc/R/site-library/Rarr/extdata/zarr_examples/column-first/int32.zarr/"
type(A)
## [1] "integer"
chunkdim(A)
## [1] 10 10  5
a <- as.array(A)

See ?ZarrArray for more information and examples.

3.4 Write an array-like object to disk in Zarr format

The writeZarrArray() function can be used to write an array-like object to disk in Zarr format.

For example we can write back A to disk but with a different physical chunk geometry:

path1 <- tempfile(fileext=".zarr")
writeZarrArray(A, path1, chunkdim=c(3, 5, 2))
## <30 x 20 x 10> ZarrArray object of type "integer":
## ,,1
##        [,1]  [,2]  [,3]  [,4] ... [,17] [,18] [,19] [,20]
##  [1,]     1     2     3     4   .    17    18    19    20
##  [2,]     1     0     0     0   .     0     0     0     0
##   ...     .     .     .     .   .     .     .     .     .
## [29,]     1     0     0     0   .     0     0     0     0
## [30,]     1     0     0     0   .     0     0     0     0
## 
## ...
## 
## ,,10
##        [,1]  [,2]  [,3]  [,4] ... [,17] [,18] [,19] [,20]
##  [1,]     0     0     0     0   .     0     0     0     0
##  [2,]     0     0     0     0   .     0     0     0     0
##   ...     .     .     .     .   .     .     .     .     .
## [29,]     0     0     0     0   .     0     0     0     0
## [30,]     0     0     0     0   .     0     0     0     0

Or, we can transform A and then write it back to disk:

path2 <- tempfile(fileext=".zarr")
A2 <- sqrt(t(A[ , , 1]) + 1)  # all these operations are delayed

## This will realize the delayed operations carried by 'A2' block by block:
writeZarrArray(A2, path2)
## <20 x 30> ZarrMatrix object of type "double":
##           [,1]     [,2]     [,3] ...    [,29]    [,30]
##  [1,] 1.414214 1.414214 1.414214   . 1.414214 1.414214
##  [2,] 1.732051 1.000000 1.000000   . 1.000000 1.000000
##  [3,] 2.000000 1.000000 1.000000   . 1.000000 1.000000
##  [4,] 2.236068 1.000000 1.000000   . 1.000000 1.000000
##  [5,] 2.449490 1.000000 1.000000   . 1.000000 1.000000
##   ...        .        .        .   .        .        .
## [16,] 4.123106 1.000000 1.000000   .        1        1
## [17,] 4.242641 1.000000 1.000000   .        1        1
## [18,] 4.358899 1.000000 1.000000   .        1        1
## [19,] 4.472136 1.000000 1.000000   .        1        1
## [20,] 4.582576 1.000000 1.000000   .        1        1

Note that writeZarrArray() leverages lower-level functionality implemented in the Rarr package like Rarr::create_empty_zarr_array() and Rarr::update_zarr_array(). See ?writeZarrArray for more information.

4 ZarrSparseMatrix objects

The ZarrSparseMatrix class is a DelayedMatrix extension for representing and operating on a sparse matrix stored on disk in “Zarr sparse” format.

For the examples in this section, we’re going to use a zipped AnnData-style file from the anndataR package that contains a collection of Zarr-based sparse matrices.

if (!require("anndataR", quietly=TRUE))
    BiocManager::install("anndataR")

library(anndataR)
anndataR_extdata <- system.file(package="anndataR", "extdata")
list.files(anndataR_extdata)  # 3 files
## [1] "example.h5ad"        "example_v2.zarr.zip" "example_v3.zarr.zip"

Please refer to the Examples section of the ZarrSparseMatrix man page (with ?ZarrSparseMatrix) for a quick overview of what’s in these files.

The file that we’re interested in is example_v3.zarr.zip, but we need to unzip it first:

zad_basename <- "example_v3.zarr"  # zad: Zarr-based AnnData
zad_zip <- paste0(zad_basename, ".zip")
zad_zip_path <- file.path(anndataR_extdata, zad_zip)
exdir <- tempdir()
unzip(zad_zip_path, exdir=exdir)
zad_store <- file.path(exdir, zad_basename)

4.1 Construction

To construct a ZarrSparseMatrix object, simply call the ZarrSparseMatrix() constructor function specifying the path to the Zarr store and group where the sparse matrix is located:

ZSM <- ZarrSparseMatrix(zad_store, "/X")
ZSM
## <100 x 50> sparse ZarrSparseMatrix object of type "double":
##             [,1]      [,2]      [,3] ...     [,49]     [,50]
##   [1,] 1.3469266 0.6892936 1.1073005   .  0.747668  0.000000
##   [2,] 1.0636960 0.0000000 0.6996704   .  1.695299  1.948128
##   [3,] 1.7479203 0.0000000 1.1073005   .  0.747668  1.100338
##   [4,] 0.6670749 0.6892936 0.6996704   .  1.695299  1.611508
##   [5,] 0.0000000 0.6892936 1.1073005   .  0.747668  1.388235
##    ...         .         .         .   .         .         .
##  [96,] 1.5673896 1.0934708 0.6996704   . 0.7476680 0.6944417
##  [97,] 0.6670749 0.0000000 1.1073005   . 1.4670000 0.6944417
##  [98,] 0.6670749 0.0000000 1.6198547   . 1.1706656 1.6115083
##  [99,] 0.6670749 1.7853285 1.6198547   . 1.4670000 0.6944417
## [100,] 1.9007897 1.3805084 0.6996704   . 1.1706656 1.7939160

4.2 Matrix operations

Like ZarrArray objects, ZarrSparseMatrix objects are also DelayedArray derivatives, and, therefore, also support all operations (delayed or block-processed) supported by DelayedArray objects:

class(ZSM)
## [1] "ZarrSparseMatrix"
## attr(,"package")
## [1] "ZarrArray"
is(ZSM, "DelayedMatrix")
## [1] TRUE
## The DelayedMatrix class extends the DelayedArray class:
is(ZSM, "DelayedArray")
## [1] TRUE

ZarrSparseMatrix objects to “look and feel” like ordinary matrices in R:

dim(ZSM)
## [1] 100  50
length(ZSM)
## [1] 5000
ZSM[1:5, 1:6]
## <5 x 6> sparse DelayedMatrix object of type "double":
##           [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
## [1,] 1.3469266 0.6892936 1.1073005 1.0734221 1.0510234 0.6553608
## [2,] 1.0636960 0.0000000 0.6996704 1.5791326 1.3325943 1.0479064
## [3,] 1.7479203 0.0000000 1.1073005 1.3579103 0.0000000 1.8802317
## [4,] 0.6670749 0.6892936 0.6996704 0.6743142 0.6576694 0.6553608
## [5,] 0.0000000 0.6892936 1.1073005 1.0734221 1.7319107 1.5482749
ZSM[1:5 , 50]
## [1] 0.000000 1.948128 1.100338 1.611508 1.388235
t(ZSM)
## <50 x 100> sparse DelayedMatrix object of type "double":
##            [,1]      [,2]      [,3] ...     [,99]    [,100]
##  [1,] 1.3469266 1.0636960 1.7479203   . 0.6670749 1.9007897
##  [2,] 0.6892936 0.0000000 0.0000000   . 1.7853285 1.3805084
##  [3,] 1.1073005 0.6996704 1.1073005   . 1.6198547 0.6996704
##  [4,] 1.0734221 1.5791326 1.3579103   . 1.5791326 1.7601712
##  [5,] 1.0510234 1.3325943 0.0000000   . 0.6576694 0.0000000
##   ...         .         .         .   .         .         .
## [46,] 0.7131079 1.1251390 1.1251390   . 1.6411866 0.7131079
## [47,] 0.6996704 0.6996704 1.8026079   . 1.1073005 1.1073005
## [48,] 1.7479203 0.0000000 0.6670749   . 1.0636960 0.0000000
## [49,] 0.7476680 1.6952993 0.7476680   . 1.4670000 1.1706656
## [50,] 0.0000000 1.9481282 1.1003379   . 0.6944417 1.7939160
max(ZSM)
## [1] 2.295638
sum(ZSM)
## [1] 4791.225
ZSM - 0.5
## <100 x 50> DelayedMatrix object of type "double":
##              [,1]       [,2]       [,3] ...      [,49]      [,50]
##   [1,]  0.8469266  0.1892936  0.6073005   .  0.2476680 -0.5000000
##   [2,]  0.5636960 -0.5000000  0.1996704   .  1.1952993  1.4481282
##   [3,]  1.2479203 -0.5000000  0.6073005   .  0.2476680  0.6003379
##   [4,]  0.1670749  0.1892936  0.1996704   .  1.1952993  1.1115083
##   [5,] -0.5000000  0.1892936  0.6073005   .  0.2476680  0.8882354
##    ...          .          .          .   .          .          .
##  [96,]  1.0673896  0.5934708  0.1996704   .  0.2476680  0.1944417
##  [97,]  0.1670749 -0.5000000  0.6073005   .  0.9670000  0.1944417
##  [98,]  0.1670749 -0.5000000  1.1198547   .  0.6706656  1.1115083
##  [99,]  0.1670749  1.2853285  1.1198547   .  0.9670000  0.1944417
## [100,]  1.4007897  0.8805084  0.1996704   .  0.6706656  1.2939160
ZSM^3
## <100 x 50> sparse DelayedMatrix object of type "double":
##             [,1]      [,2]      [,3] ...    [,49]    [,50]
##   [1,] 2.4436092 0.3275011 1.3576772   . 0.417952 0.000000
##   [2,] 1.2035181 0.0000000 0.3425157   . 4.872357 7.393543
##   [3,] 5.3402902 0.0000000 1.3576772   . 0.417952 1.332227
##   [4,] 0.2968410 0.3275011 0.3425157   . 4.872357 4.185021
##   [5,] 0.0000000 0.3275011 1.3576772   . 0.417952 2.675404
##    ...         .         .         .   .        .        .
##  [96,] 3.8506220 1.3074394 0.3425157   . 0.417952 0.334894
##  [97,] 0.2968410 0.0000000 1.3576772   . 3.157115 0.334894
##  [98,] 0.2968410 0.0000000 4.2503840   . 1.604348 4.185021
##  [99,] 0.2968410 5.6905523 4.2503840   . 3.157115 0.334894
## [100,] 6.8675564 2.6309778 0.3425157   . 1.604348 5.773063
ZSM == 0L
## <100 x 50> DelayedMatrix object of type "logical":
##         [,1]  [,2]  [,3] ... [,49] [,50]
##   [1,] FALSE FALSE FALSE   . FALSE  TRUE
##   [2,] FALSE  TRUE FALSE   . FALSE FALSE
##   [3,] FALSE  TRUE FALSE   . FALSE FALSE
##   [4,] FALSE FALSE FALSE   . FALSE FALSE
##   [5,]  TRUE FALSE FALSE   . FALSE FALSE
##    ...     .     .     .   .     .     .
##  [96,] FALSE FALSE FALSE   . FALSE FALSE
##  [97,] FALSE  TRUE FALSE   . FALSE FALSE
##  [98,] FALSE  TRUE FALSE   . FALSE FALSE
##  [99,] FALSE FALSE FALSE   . FALSE FALSE
## [100,] FALSE FALSE FALSE   . FALSE FALSE
sqrt(ZSM)
## <100 x 50> sparse DelayedMatrix object of type "double":
##             [,1]      [,2]      [,3] ...     [,49]     [,50]
##   [1,] 1.1605717 0.8302371 1.0522835   .  0.864678  0.000000
##   [2,] 1.0313564 0.0000000 0.8364630   .  1.302037  1.395754
##   [3,] 1.3220894 0.0000000 1.0522835   .  0.864678  1.048970
##   [4,] 0.8167465 0.8302371 0.8364630   .  1.302037  1.269452
##   [5,] 0.0000000 0.8302371 1.0522835   .  0.864678  1.178234
##    ...         .         .         .   .         .         .
##  [96,] 1.2519543 1.0456915 0.8364630   . 0.8646780 0.8333317
##  [97,] 0.8167465 0.0000000 1.0522835   . 1.2111978 0.8333317
##  [98,] 0.8167465 0.0000000 1.2727351   . 1.0819730 1.2694519
##  [99,] 0.8167465 1.3361619 1.2727351   . 1.2111978 0.8333317
## [100,] 1.3786913 1.1749504 0.8364630   . 1.0819730 1.3393715
head(rowSums(ZSM))
## [1] 47.44578 48.33904 48.83190 42.81068 48.22690 45.73604
head(rowMaxs(ZSM))
## [1] 2.090829 1.948128 2.047693 1.802608 1.983871 1.747920
head(colVars(ZSM))
## [1] 0.2736919 0.2797302 0.2751871 0.2361084 0.2971117 0.2684965

4.3 Other operations

Other operations are supported that are specific to DelayedArray objects and their derivatives:

path(ZSM)
## [1] "/tmp/RtmpwNGL4s/example_v3.zarr"
group(ZSM)
## [1] "/X"
type(ZSM)
## [1] "double"
chunkdim(ZSM)
## [1] 100   1
is_sparse(ZSM)
## [1] TRUE
zsm <- as.matrix(ZSM)

See ?ZarrSparseMatrix for more information and examples.

4.4 Write a matrix-like object as a Zarr-based sparse matrix

The writeZarrSparseMatrix() function can be used to write a matrix-like object (typically sparse) to disk in “Zarr sparse” format:

m0 <- matrix(0L, nrow=25, ncol=12,
             dimnames=list(letters[1:25], LETTERS[1:12]))
m0[cbind(2:24, c(12:1, 2:12))] <- 100L + sample(55L, 23, replace=TRUE)

zarr_store <- tempfile(fileext=".zarr")
ZSM0 <- writeZarrSparseMatrix(m0, zarr_store, group="/X0")
ZSM0
## <25 x 12> sparse ZarrSparseMatrix object of type "integer":
##        [,1]  [,2]  [,3]  [,4] ...  [,9] [,10] [,11] [,12]
##  [1,]     0     0     0     0   .     0     0     0     0
##  [2,]     0     0     0     0   .     0     0     0   101
##  [3,]     0     0     0     0   .     0     0   103     0
##  [4,]     0     0     0     0   .     0   135     0     0
##  [5,]     0     0     0     0   .   134     0     0     0
##   ...     .     .     .     .   .     .     .     .     .
## [21,]     0     0     0     0   .   116     0     0     0
## [22,]     0     0     0     0   .     0   127     0     0
## [23,]     0     0     0     0   .     0     0   108     0
## [24,]     0     0     0     0   .     0     0     0   154
## [25,]     0     0     0     0   .     0     0     0     0

path() and group():

path(ZSM0)
## [1] "/tmp/RtmpwNGL4s/file3ac2905c57b9f5.zarr"
group(ZSM0)
## [1] "/X0"

The object passed to writeZarrSparseMatrix() can be a matrix-like object of any sort. For example, it can be a dgCMatrix object from the Matrix package:

library(Matrix)
dgc <- as(m0, "dgCMatrix")
ZSM1 <- writeZarrSparseMatrix(dgc, zarr_store, group="/X1")
ZSM1
## <25 x 12> sparse ZarrSparseMatrix object of type "double":
##        [,1]  [,2]  [,3] ... [,11] [,12]
##  [1,]     0     0     0   .     0     0
##  [2,]     0     0     0   .     0   101
##  [3,]     0     0     0   .   103     0
##  [4,]     0     0     0   .     0     0
##  [5,]     0     0     0   .     0     0
##   ...     .     .     .   .     .     .
## [21,]     0     0     0   .     0     0
## [22,]     0     0     0   .     0     0
## [23,]     0     0     0   .   108     0
## [24,]     0     0     0   .     0   154
## [25,]     0     0     0   .     0     0
path(ZSM1)
## [1] "/tmp/RtmpwNGL4s/file3ac2905c57b9f5.zarr"
group(ZSM1)
## [1] "/X1"

or it can be a DelayedMatrix object:

SM2 <- log(ZSM1[ , 7:12] + 1)  # all these operations are delayed
is_sparse(SM2)
## [1] TRUE
## This will realize the delayed operations carried by 'SM2' block by block:
ZSM2 <- writeZarrSparseMatrix(SM2, zarr_store, group="/X2")
ZSM2
## <25 x 6> sparse ZarrSparseMatrix object of type "double":
##           [,1]     [,2]     [,3]     [,4]     [,5]     [,6]
##  [1,] 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
##  [2,] 0.000000 0.000000 0.000000 0.000000 0.000000 4.624973
##  [3,] 0.000000 0.000000 0.000000 0.000000 4.644391 0.000000
##  [4,] 0.000000 0.000000 0.000000 4.912655 0.000000 0.000000
##  [5,] 0.000000 0.000000 4.905275 0.000000 0.000000 0.000000
##   ...        .        .        .        .        .        .
## [21,] 0.000000 0.000000 4.762174 0.000000 0.000000 0.000000
## [22,] 0.000000 0.000000 0.000000 4.852030 0.000000 0.000000
## [23,] 0.000000 0.000000 0.000000 0.000000 4.691348 0.000000
## [24,] 0.000000 0.000000 0.000000 0.000000 0.000000 5.043425
## [25,] 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
path(ZSM2)
## [1] "/tmp/RtmpwNGL4s/file3ac2905c57b9f5.zarr"
group(ZSM2)
## [1] "/X2"

Etc…

Note that writeZarrSparseMatrix() leverages lower-level functionality implemented in the Rarr package like Rarr::write_zarr_group(), Rarr::create_empty_zarr_array(), and Rarr::update_zarr_array(). See ?writeZarrSparseMatrix for more information.

5 Session information

sessionInfo()
## R version 4.6.1 (2026-06-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.24-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] anndataR_1.4.0        ZarrArray_1.2.1       DelayedArray_0.40.0  
##  [4] SparseArray_1.14.0    S4Arrays_1.14.0       IRanges_2.48.0       
##  [7] abind_1.4-8           S4Vectors_0.52.0      MatrixGenerics_1.26.0
## [10] matrixStats_1.5.0     BiocGenerics_0.60.0   generics_0.1.4       
## [13] Matrix_1.7-6          BiocStyle_2.42.0     
## 
## loaded via a namespace (and not attached):
##  [1] sass_0.5.0          lattice_0.23-1      paws.common_0.9.0  
##  [4] digest_0.6.39       magrittr_2.0.5      evaluate_1.0.5     
##  [7] grid_4.6.1          bookdown_0.48       fastmap_1.2.0      
## [10] R.oo_1.27.1         jsonlite_2.0.0      R.utils_2.13.0     
## [13] Rarr_2.2.0          BiocManager_1.30.27 purrr_1.2.2        
## [16] httr2_1.3.0         jquerylib_0.1.4     cli_3.6.6          
## [19] rlang_1.3.0         crayon_1.5.3        XVector_0.54.0     
## [22] R.methodsS3_1.8.2   cachem_1.1.0        yaml_2.3.12        
## [25] otel_0.3.0          tools_4.6.1         grumpy_0.2.0       
## [28] curl_8.2.0          reticulate_1.47.0   vctrs_0.7.3        
## [31] R6_2.6.1            png_0.1-9           lifecycle_1.0.5    
## [34] progressr_1.1.0     bslib_0.12.0        glue_1.8.1         
## [37] Rcpp_1.1.2          xfun_0.62           paws.storage_0.11.0
## [40] knitr_1.52          htmltools_0.5.9     rmarkdown_2.32     
## [43] compiler_4.6.1