Writes a zlib-compressed, C-order Zarr v2 array of doubles into dir
and returns the path, ready for altarr_zarr_v2(). The store is made on
demand rather than shipped, because Zarr v2 metadata files (.zarray)
are hidden files, which R packages should not carry.
Arguments
- dir
directory to write the store into (created if needed).
- dim
R dimensions of the array (the Zarr shape is the reverse).
- chunk
R chunk shape (the Zarr chunk shape is the reverse). Edge chunks are padded in the store, as Zarr requires.
- sparse
if
TRUE, write a sparse store:fill_valueis0and only the chunks whose first two chunk coordinates are equal (a diagonal band, 20 of the default grid's 80 chunks) are written. The rest are absent and read as0, as Zarr reads an unwritten chunk.
Details
Every value is its own 0-based position in R's column-major order, so a
result can be checked by eye: in the array returned by
altarr_zarr_v2(), element x[i, j, k] is
(i - 1) + dim[1] * (j - 1) + dim[1] * dim[2] * (k - 1), and x[n] is
n - 1.
Examples
path <- altarr_example_zarr()
x <- altarr_zarr_v2(path)
dim(x)
#> [1] 70 50 30
x[c(1, 2, 71)] # 0, 1, 70
#> [1] 0 1 70
## a sparse store: most chunks were never written
xs <- altarr_zarr_v2(altarr_example_zarr(sparse = TRUE))
sum(altarr_present(xs))
#> [1] 20