Read CONTRIBUTING.md first; the conventions, checks and key design points live there and are not repeated here. This file adds what an agent needs on top: which package owns what, where the direction is recorded, and the things in this codebase that aren’t obvious from reading it.
What anndataR is
The native R implementation of AnnData: it reads and writes .h5ad files and Zarr stores without Python, and converts to and from SingleCellExperiment and Seurat. It is released on Bioconductor and part of scverse. Python anndata is the reference implementation: when R and Python disagree about a file, Python’s behaviour is the spec unless an issue says otherwise.
Before reporting a finding
Most of what looks wrong when reading the code is already tracked, and some of it is being replaced by an open PR. Before raising something, check:
- open issues:
gh issue list --search "<keyword>"; useful labels areh5ad,zarr,backed,Seurat,SingleCellExperiment,performance,design,triage - open PRs:
gh pr list; several change architecture, and a finding in code a PR rewrites should be made against that PR, not againstdevel - the project board: this is the live roadmap, and this file deliberately doesn’t carry one
-
inst/known_issues.yaml: expected test failures, skipped withmessage_if_known()
If it is tracked, link the issue or PR instead of re-reporting it. Upstream trackers matter too: a bug in a dependency is often already filed on Huber-group-EMBL/Rarr or Huber-group-EMBL/rhdf5.
Who owns what
anndataR sits on a stack of Bioconductor packages, and more and more of what it used to do itself is their job. The split:
| Concern | Owner | Where it touches anndataR |
|---|---|---|
The AnnData spec: element encodings, encoding-type/encoding-version, slot validation |
anndataR |
R/read_*_helpers.R, R/write_*_helpers.R, the validators in AbstractAnnData
|
| The AnnData classes and lazy views | anndataR |
R/*AnnData.R, R/AnnDataView.R
|
| Conversion to and from SingleCellExperiment and Seurat | anndataR |
R/as_*.R, R/from_*.R
|
| Raw HDF5 reading and writing | rhdf5 |
R/HDF5File.R wraps the handle, R/write_hdf5_helpers.R
|
| Raw Zarr reading and writing: chunks, codecs, string encoding, consolidated metadata | Rarr |
R/Rarr_utils.R, zarr_write_compressed()
|
| Backed (lazy, on-disk) matrices | DelayedArray, with HDF5Array seeds for H5AD and ZarrArray seeds for Zarr |
backed = TRUE in the readers; as_SingleCellExperiment() and as_Seurat() pass the seeds through |
| In-memory sparse matrices |
Matrix (dgCMatrix, dgRMatrix); SparseArray is being evaluated in #382 |
everywhere |
| Python interop | reticulate and Python anndata |
ReticulateAnnData, R/reticulate_helpers.R
|
What follows from this:
-
Format-level bugs go upstream. If the problem is how bytes land on disk (a chunk layout, a codec name, string encoding, metadata), file it on rhdf5 or Rarr, link it from the anndataR issue, work around it here with a
TODOnaming the upstream issue, and bump the version pin inDESCRIPTIONonce the fix is released. Recent examples: Rarr#262 (the C string encoder, merged), Rarr#111 (patch_zarr_vlen_utf8()waits on it), rhdf5#241 (a spuriousNAwarning, tracked ininst/known_issues.yamluntil the fix was released). - Prefer the owner’s implementation. anndataR decides what to write (the spec) and passes how through. When the owner doesn’t provide something yet, as with auto-chunking in Rarr, implement it here pinned to Python’s behaviour and propose it upstream.
-
The storage stack is optional. rhdf5, Rarr, DelayedArray, HDF5Array and ZarrArray are in
Suggests, as are Seurat and SingleCellExperiment, and are loaded throughcheck_requires(what, requires, where, version). A new call into one of them needs acheck_requires()guard and a matchingskip_if_*()in the tests. Matrix and reticulate areImportsand always available; Python anndata itself is optional and checked withcheck_requires(..., where = "Python").
Direction
These are decided; assume them when a change touches the area.
-
Backed mode goes through DelayedArray seeds for both formats. Backed mode (using HDF5Array or ZarrArray) covers every slot, not only
Xas in Python: aDelayedArrayinobsmorunsis intentional. -
H5AD and Zarr share one encoding layer.
R/read_h5ad_helpers.RandR/read_zarr_helpers.R(and theirwrite_counterparts) mirror each other, and #445 is about merging them. A new encoding is added to both; don’t let them drift further apart. -
Parity with Python anndata 0.13 (#514): sharded Zarr v3 stores, new encodings, and the missing API (
concat#325,copy#352,read_elem/write_elem#466). -
Performance is measured, not guessed. Bencher runs on every PR (
.github/workflows/bench-*.yaml); #329 and #382 are the long-running threads on memory use.
Open questions, not direction; don’t build on them yet:
-
S4Vectors::DataFrameinstead ofdata.frameforobs/var(#554). - Moving the conversions to zellkonverter (#383): if zellkonverter takes ownership of the AnnData <> SingleCellExperiment/Seurat conversions and builds on
AbstractAnnData, rather than on its own Python stack.
Things that aren’t obvious from the code
-
obs_namesandvar_namesare stored apart fromobs/varand from every matrix; dimnames are added on access by.add_matrix_dimnames()and friends. Internal code usesadata$obs_names, neverrownames(adata$obs)orcolnames(adata$X), and setters strip row names before storing. Python keeps the names separate too, which is what makes round trips exact. -
adata[i, j]returns anAnnDataView: lazy, read-only, converted with$as_InMemoryAnnData()and the other$as_*AnnData()methods. - The S3 methods (
dim(),dimnames(),[) for every class live inR/AbstractAnnData-s3methods.R;n_obs()/n_vars()are the R6 equivalents. -
HDF5AnnDataopens the file per operation (open_and_defer_close()) and closes it when the object is garbage collected;test-h5ad-fileclosure.Rguards against leaked handles. - R data frames can’t hold duplicate row names, Python can. Reading a file with duplicate
obs_namesorvar_namesis not handled yet (#256); don’t add fixtures that assume it is. -
NULLinunsis written as an empty dataset, as anndata >= 0.12 does;options(anndataR.write_null = FALSE)turns that off. - Every getter and setter carries a
# trackstatus: class=..., feature=..., status=...comment; the development-status article is generated from them, so a new feature gets one. -
man/is generated. Never hand-edit it; rundevtools::document()with the roxygen2 version pinned inDESCRIPTION.
Testing against Python
- The
skip_if_no_*()helpers intests/testthat/helper-skip_if_*.Rdeclare the Python requirement withreticulate::py_require()and skip when it can’t be imported.ANNDATAR_TEST_REQUIRE_PYTHON=trueturns the skips into errors, so a broken Python environment can’t silently skip every Python test; scverse/integration-testing sets it, this repository’s own workflows don’t. -
test-roundtrip-*.Rwrite with R and read with Python and vice versa, over every element type ofdummy_anndata, for H5AD, Zarr v2 and Zarr v3. A change to any encoding gets a roundtrip test. -
expect_equal_py()compares R and Python objects;generate_dataset()builds the R fixtures. -
h5diff(skipped when absent) checks that H5AD files written by R and Python are the same on disk.