You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Leaky abstraction leading to bugs in cbind and combine #70
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...
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.
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.
Activity
kuwisdelu commentedon Nov 7, 2025
Okay, so I see the issue now...
combine()method for MSImagingExperiment some time ago with the idea that you should usecbind()since MSImagingExperiment is matrix-like, and I could later re-implement a bettercombine()method that "does the right thing" even when the features don't match up, but I haven't done that yet...cbind(), the defaultcombine()method for ANY is being used instead, which is justc()which doesn't work for MSImagingExperiment, but R tries to do it anyway and fails with a confusing error message.cbind()the underlying spectra matrices must becbind()-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 incbind()dispatches to R's internalcbind()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.