read_elem_lazy() reads the metadata of an Element and leaves its data on
disk, so values are read only when they are realised or processed by block.
It matches Python's read_elem_lazy().
Arguments
- store
An h5ad file or a zarr directory (v3 or v2), given as a path or as an open store handle.
- path
Path of the Element within the store.
- chunks
Chunk shape of the
DelayedArraygrid, one entry per dimension, whereNAor-1is the whole axis. The default is the on-disk chunking (1000 where an HDF5 array is contiguous) and for sparse arrays the major axis is cut every 1000 positions. Sparse arrays can only be chunked along the major axis. Ignored for string, categorical, nullable anddataframeElements.
Details
What is returned depends on the encoding of the Element:
dense and sparse (CSR and CSC) arrays are
DelayedArrays, sparse ones stay sparse (SparseArray) when processed by blockstring arrays are 1-d
DelayedArrays ofcharactercategorical and nullable arrays are lazy columns, and a
dataframeis a lazy data frame whose columns are lazyother encodings (such as
dictand scalars) raiseanndata_io_registry_error, as in Python
Realising a lazy value gives what read_h5ad() and read_zarr() give for
the same Element, including NA and the On-disk dtype records.
The store stays open while any lazy object that uses it exists.
Deviations from Python
store is a path or an open store handle, because R has no element object
like h5py's.
See vignette("deviations") for the full list.
Examples
adata <- AnnData(matrix(as.numeric(1:6), nrow = 3))
path <- tempfile(fileext = ".zarr")
write_zarr(adata, path)
read_elem_lazy(path, "X")
#> <3 x 2> DelayedMatrix object of type "double":
#> [,1] [,2]
#> [1,] 1 4
#> [2,] 2 5
#> [3,] 3 6