← Back to all sparks
R

RNifti

INFRA · APIS
Velocity0.0

Fast R and C++ Access to NIfTI Images

The C++ layer under R's neuroimaging stack, closing the gaps where images stopped acting like arrays

neuroimagingmedical-imagingcpp-interfacefile-formatsmemory-efficiencyr-package
Current state
RNifti reads and writes NIfTI and ANALYZE medical image files, exposing them to R through an internalImage class that keeps pixel data on the C++ side until it is needed. It is infrastructure: other neuroimaging packages depend on it, and much of its release history is driven by their bug reports. Recent work has been about making that lazy image type behave like a normal R array without giving up the memory advantage.
Where it's heading
Two threads run through these releases. One extends what the package can represent — RGB arrays, complex datatypes, JSON sidecar metadata — steadily widening the file and type surface it covers. The other closes semantic holes in the deferred-loading design, where R would silently fall back on character methods because the image class had no method of its own. The 1.9.0 work is the clearest example, and it is careful to keep the memory benefit by pushing summaries into C++ rather than materialising an array.
Prediction
The JSON sidecar support is flagged as R-only for now, which makes exposing it through the C++ API the most likely next step.

Recent moves

  1. 7mo ago

    Arithmetic and summary generics for lazily loaded images

    Adds Math, Ops, Complex and Summary group generics plus is.na() and mean() to internalImage, so R no longer falls back on character methods that produce nothing useful. Summary is implemented in C++ specifically to avoid materialising a full R array for a single value, which keeps the class's deferred-loading benefit intact.

    View source ↗
  2. 1y ago

    Reads and writes BIDS-style JSON sidecar metadata

    readNifti and writeNifti gain a json argument and a new imageAttributes function, bringing the metadata sidecars used by the Brain Imaging Data Structure into the package's remit. It extends coverage past the image header into the surrounding convention, though only from R for the moment.

    View source ↗
  3. 2y ago

    RGB arrays keep their type through indexing

    Indexing an rgbArray or RGB-valued image now returns an rgbArray rather than dropping to a plain type, preserving the colour interpretation, and an as.raster method is added. Same class of type-fidelity work the group generics later continued.

    View source ↗
  4. 2y ago

    Misaligned memory read fixed under UBSan

    A single sanitiser-caught memory alignment fix with no change in behaviour users would observe. Routine correctness upkeep for a package with a large C++ surface.

    View source ↗
  5. 2y ago

    Legacy ANALYZE header fields readable for inspection

    niftiHeader() gains an unused argument that surfaces legacy ANALYZE-7.5 fields, read-only, for inspecting files written by other software. The C++ side also gains NiftiImage constructors that take a header structure.

    View source ↗
  6. 2y ago

    Compiler format-string warnings resolved

    Clears printf-style format string warnings from newer compilers. Toolchain upkeep, published within a minute of the 1.5.0 release it follows.

    View source ↗