Skip to content

Leaky abstraction leading to bugs in cbind and combine #70

Open

Description

@kuwisdelu

In many cases, cbind() and combine() with MSImagingExperiment objects fails with opaque error messages. See #67 as an example.

Activity

  1. kuwisdelu commented on Nov 7, 2025

    @kuwisdelu
    MemberAuthor

    Okay, so I see the issue now...

    1. I removed the combine() method for MSImagingExperiment some time ago with the idea that you should use cbind() since MSImagingExperiment is matrix-like, and I could later re-implement a better combine() method that "does the right thing" even when the features don't match up, but I haven't done that yet...
    2. But instead of erroring and directing you to use cbind(), the default combine() method for ANY is being used instead, which is just c() which doesn't work for MSImagingExperiment, but R tries to do it anyway and fails with a confusing error message.
    3. When using cbind() the underlying spectra matrices must be cbind()-able, which typically means they need to be the same class. After binning, the underlying matrix becomes a sparse_mat matrix. Mixing a sparse_mat with a built-in R matrix in cbind() dispatches to R's internal cbind() implementation which will fail.

    The long-term solution (which was already planned) is that binned MSImagingExperiments should be their own class (e.g., maybe BinnedMSImagingExperiment or SparseMSImagingExperiment) with appropriate method dispatch for these cases.

    The short-term solution is to make sure each underlying spectra matrix is the same class (as reported by spectraData()) by either binning or coercion.

    Alternatively, use MSImagingArrays which are more flexible and more easily combine()-able, with the expense of not having an experiment-wide m/z axis, but then just bin or align after combining datasets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions