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
We have already the joinSpectraData() function, but I would still like to have a different (maybe easier?) way of adding new spectra variable columns to a Spectra object. With [[<- and $<- it's already possible to add a single new spectra variable (or also to replace an existing variable), but we have frequently a data.frame or DataFrame (or matrix) with multiple columns I would like to add.
I would thus propose to have an additional function, e.g. cbind,Spectra,ANY <- function(x, y) that allows to add data for multiple values in one go. The properties would be:
nrow(y) has to be same as length(x)
throw an error if x has already a spectra variables with a name, to avoid replacing values, but just adding new values.
ideally, this should be added as a new method for MsBackend with a default implementation that (re)uses the [[<- method and a loop - some backends, such as MsBackendMemory could implement their own version that directly calls cbind on its @spectraDatadata.frame.
nrow(y) has to be same as length(x) is equivalent to nrow(y) is identical to nrow(spectraData(x)). Any consideration regarding regarding rownames(x), or some mechanism to insure that the rows or y and spectraData(x) are matching when cinding?
yes, nrow(y) is equivalent to nrow(spectraData(x)) - but a backend can have a more efficient lenght() method implemented that does not require to first get the spectra data with the spectraData(x) call.
I would actually keep the function simple and don't do any checks on rownames - or change row names. we don't explicitly support or force row names on spectraData(), as e.g. if you have a SQL backend, there are no row names available.
So, cbind() should blindly append columns (i.e. spectraVariables) to a Spectra assuming the user provides the rows in the correct order (similar to a $<- call). I would throw an error if a) nrow() does not match the number of spectra in Spectra or if any of the colnames in y are already spectraVariables().
And actually, I would maybe implement cbind2() instead of cbind() - then we have a bit better control over the dispatching.
So, cbind() should blindly append columns (i.e. spectraVariables) to a Spectra assuming the user provides the rows in the correct order (similar to a $<- call).
My suggestion would be to be explicit in the manual page and mention these risks, and then point to joinSpectraData() for a more complete/safe option (and inversely, mention cbind[2]() in the joinSpectraData() section). More seasoned users will be aware of the dangers or cbind(), but new users who are used to tidyverse's joins might not be.
And actually, I would maybe implement cbind2() instead of cbind() - then we have a bit better control over the dispatching.
We have already the
joinSpectraData()
function, but I would still like to have a different (maybe easier?) way of adding new spectra variable columns to aSpectra
object. With[[<-
and$<-
it's already possible to add a single new spectra variable (or also to replace an existing variable), but we have frequently adata.frame
orDataFrame
(ormatrix
) with multiple columns I would like to add.I would thus propose to have an additional function, e.g.
cbind,Spectra,ANY <- function(x, y)
that allows to add data for multiple values in one go. The properties would be:nrow(y)
has to be same aslength(x)
x
has already a spectra variables with a name, to avoid replacing values, but just adding new values.ideally, this should be added as a new method for
MsBackend
with a default implementation that (re)uses the[[<-
method and a loop - some backends, such asMsBackendMemory
could implement their own version that directly callscbind
on its@spectraData
data.frame
.@lgatto @sgibb , any thoughts?
ping @philouail
The text was updated successfully, but these errors were encountered: